From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server-vie001.gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_DBL_BLOCKED_OPENDNS, URIBL_ZEN_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=new2025; t=1754000749; bh=RQJ3hGN10sD8b4ruLHJf7X8h9Vwfz2c07NZMjAtE4SE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID: Date:From:Reply-To:Subject:To:Cc:In-Reply-To:References: Resent-Date:Resent-From:Resent-To:Resent-Cc:User-Agent: Content-Type:Content-Transfer-Encoding; b=UQpeb/iCmBZAzUYosevvKouPB5/oU2PkMRlTde9xDfAXX+ep0L20Nzwbe7KHMu9Ks 7TNeAztBGokhc/Mp7ZYdGrBb1nqgErJiSEDc9aJEIN9jfmZ1tIh+SYkcxRXalfn9iE e3FixObHNLE26CpMPqXAmPF00X3bl7yS6GEAzZFRaJnsqv9qL5/S2KgrCPJ53N/VsR IKAwxi94gBkN2JZLFR6X8Z0p6rnixuO2bbcb2vy7mjHPSZE37OV7tG72r8tTLXZgkt bXpnsxIRgsguYOyHN1SCEA2FN6sFx2spDOq2hmlRflxSpCjjVNfBzP1IeBW6AT+LvL ZFrkRRSZFIEoA== Received: from localhost.localdomain (unknown [68.183.184.174]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 419A03126ED8; Thu, 31 Jul 2025 22:25:48 +0000 (UTC) From: Alviro Iskandar Setiawan To: Ammar Faizi Cc: Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH gwproxy v2 1/2] log: Fix missing `gettid()` syscall on older glibc version Date: Fri, 1 Aug 2025 05:25:42 +0700 Message-Id: <20250731222543.303821-2-alviro.iskandar@gnuweeb.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250731222543.303821-1-alviro.iskandar@gnuweeb.org> References: <20250731222543.303821-1-alviro.iskandar@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: 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 --- 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 #include +#include #include #include #include @@ -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 @@ -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