From: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
To: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Cc: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>,
GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>
Subject: [PATCH gwproxy v1 1/2] log: Fix missing `gettid()` syscall on older glibc version
Date: Fri, 1 Aug 2025 05:05:45 +0700 [thread overview]
Message-ID: <20250731220546.303497-2-alviro.iskandar@gnuweeb.org> (raw)
In-Reply-To: <20250731220546.303497-1-alviro.iskandar@gnuweeb.org>
Compiling on GNU CC version 8.5.0 20210514 (Red Hat 8.5.0-26) with
glibc version 2.28 throws this error:
src/gwproxy/log.c: In function ‘__pr_log’:
src/gwproxy/log.c:51:56: warning: implicit declaration of function ‘gettid’; \
did you mean ‘getgid’? [-Wimplicit-function-declaration]
fprintf(handle, "[%s][%s][%08d]: %s\n", time_buf, ls, gettid(), pb);
^~~~~~
getgid
src/gwproxy/log.c:51: undefined reference to `gettid'
collect2: error: ld returned 1 exit status
Fix it by defining our own `__sys_gettid()`.
Signed-off-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
---
src/gwproxy/log.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/gwproxy/log.c b/src/gwproxy/log.c
index 95d1930..574c5e0 100644
--- a/src/gwproxy/log.c
+++ b/src/gwproxy/log.c
@@ -1,5 +1,6 @@
#include <gwproxy/common.h>
#include <gwproxy/log.h>
+#include <gwproxy/syscall.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
@@ -7,6 +8,11 @@
#include <unistd.h>
#include <stdarg.h>
+static inline pid_t __sys_gettid(void)
+{
+ return (pid_t)__do_syscall0(__NR_gettid);
+}
+
__attribute__((__format__(printf, 3, 4)))
void __pr_log(FILE *handle, int level, const char *fmt, ...)
{
@@ -48,7 +54,7 @@ void __pr_log(FILE *handle, int level, const char *fmt, ...)
else
time_buf[0] = '\0';
- fprintf(handle, "[%s][%s][%08d]: %s\n", time_buf, ls, gettid(), pb);
+ fprintf(handle, "[%s][%s][%08d]: %s\n", time_buf, ls, __sys_gettid(), pb);
if (unlikely(pb != loc_buf))
free(pb);
out:
--
Alviro Iskandar Setiawan
next prev parent reply other threads:[~2025-07-31 22:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-31 22:05 [PATCH gwproxy v1 0/2] Fixes for older glibc version Alviro Iskandar Setiawan
2025-07-31 22:05 ` Alviro Iskandar Setiawan [this message]
2025-07-31 22:17 ` [PATCH gwproxy v1 1/2] log: Fix missing `gettid()` syscall on " Ammar Faizi
2025-07-31 22:20 ` Alviro Iskandar Setiawan
2025-07-31 22:05 ` [PATCH gwproxy v1 2/2] configure: Append `-lanl` lib to fix missing `getaddrinfo_a()` Alviro Iskandar Setiawan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250731220546.303497-2-alviro.iskandar@gnuweeb.org \
--to=alviro.iskandar@gnuweeb.org \
--cc=ammarfaizi2@gnuweeb.org \
--cc=gwml@vger.gnuweeb.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox