1From f4f9d24860e1b5cd4f6a014f3fda7cd33ebe5be7 Mon Sep 17 00:00:00 2001 2From: Petr Lautrbach <plautrba@redhat.com> 3Date: Sat, 27 Jul 2019 08:20:20 -0700 4Subject: [PATCH] libselinux: Do not define gettid() if glibc >= 2.30 is used 5MIME-Version: 1.0 6Content-Type: text/plain; charset=UTF-8 7Content-Transfer-Encoding: 8bit 8 9Since version 2.30 glibc implements gettid() system call wrapper, see 10https://sourceware.org/bugzilla/show_bug.cgi?id=6399 11 12Fixes: 13cc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I../include -D_GNU_SOURCE -DNO_ANDROID_BACKEND -c -o procattr.o procattr.c 14procattr.c:28:14: error: static declaration of ‘gettid’ follows non-static declaration 15 28 | static pid_t gettid(void) 16 | ^~~~~~ 17In file included from /usr/include/unistd.h:1170, 18 from procattr.c:2: 19/usr/include/bits/unistd_ext.h:34:16: note: previous declaration of ‘gettid’ was here 20 34 | extern __pid_t gettid (void) __THROW; 21 | ^~~~~~ 22 23Signed-off-by: Petr Lautrbach <plautrba@redhat.com> 24Acked-by: Stephen Smalley <sds@tycho.nsa.gov> 25Signed-off-by: Khem Raj <raj.khem@gmail.com> 26--- 27 src/procattr.c | 14 +++++++++++++- 28 1 file changed, 13 insertions(+), 1 deletion(-) 29 30--- a/src/procattr.c 31+++ b/src/procattr.c 32@@ -8,12 +8,16 @@ 33 #include "selinux_internal.h" 34 #include "policy.h" 35 36-#ifndef __BIONIC__ 37+/* Bionic and glibc >= 2.30 declare gettid() system call wrapper in unistd.h and 38+ * has a definition for it */ 39+#if defined(__GLIBC_) 40+#if !__GLIBC_PREREQ(2,30) 41 static pid_t gettid(void) 42 { 43 return syscall(__NR_gettid); 44 } 45 #endif 46+#endif 47 48 static int getprocattrcon(char ** context, 49 pid_t pid, const char *attr) 50