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 v2 1/2] log: Fix missing `gettid()` syscall on older glibc version
Date: Fri, 1 Aug 2025 05:25:42 +0700 [thread overview]
Message-ID: <20250731222543.303821-2-alviro.iskandar@gnuweeb.org> (raw)
In-Reply-To: <20250731222543.303821-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 | 3 ++-
src/gwproxy/syscall.h | 9 +++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/gwproxy/log.c b/src/gwproxy/log.c
index 95d1930..519b775 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>
@@ -48,7 +49,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:
diff --git a/src/gwproxy/syscall.h b/src/gwproxy/syscall.h
index 1a6f60e..e111be0 100644
--- a/src/gwproxy/syscall.h
+++ b/src/gwproxy/syscall.h
@@ -283,6 +283,10 @@ static inline int __sys_eventfd(unsigned int c, int flags)
return (int) __do_syscall2(__NR_eventfd2, c, flags);
}
+static inline pid_t __sys_gettid(void)
+{
+ return (pid_t)__do_syscall0(__NR_gettid);
+}
#else /* #ifdef __x86_64__ */
#include <errno.h>
@@ -430,6 +434,11 @@ static inline int __sys_shutdown(int sockfd, int how)
int r = shutdown(sockfd, how);
return (r < 0) ? -errno : r;
}
+
+static inline pid_t __sys_gettid(void)
+{
+ return syscall(__NR_gettid);
+}
#endif /* #endif __x86_64__ */
#endif /* #ifndef GWPROXY_SYSCALL_H */
--
Alviro Iskandar Setiawan
next prev parent reply other threads:[~2025-07-31 22:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-31 22:25 [PATCH gwproxy v2 0/2] Fixes for older glibc version Alviro Iskandar Setiawan
2025-07-31 22:25 ` Alviro Iskandar Setiawan [this message]
2025-07-31 22:25 ` [PATCH gwproxy v2 2/2] configure: Append `-lanl` lib to fix missing `getaddrinfo_a()` Alviro Iskandar Setiawan
2025-07-31 22:32 ` [PATCH gwproxy v2 0/2] Fixes for older glibc version Ammar Faizi
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=20250731222543.303821-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