1*4882a593SmuzhiyunFrom f4f9d24860e1b5cd4f6a014f3fda7cd33ebe5be7 Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Petr Lautrbach <plautrba@redhat.com>
3*4882a593SmuzhiyunDate: Sat, 27 Jul 2019 08:20:20 -0700
4*4882a593SmuzhiyunSubject: [PATCH] libselinux: Do not define gettid() if glibc >= 2.30 is used
5*4882a593SmuzhiyunMIME-Version: 1.0
6*4882a593SmuzhiyunContent-Type: text/plain; charset=UTF-8
7*4882a593SmuzhiyunContent-Transfer-Encoding: 8bit
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunSince version 2.30 glibc implements gettid() system call wrapper, see
10*4882a593Smuzhiyunhttps://sourceware.org/bugzilla/show_bug.cgi?id=6399
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunFixes:
13*4882a593Smuzhiyuncc -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
14*4882a593Smuzhiyunprocattr.c:28:14: error: static declaration of ‘gettid’ follows non-static declaration
15*4882a593Smuzhiyun   28 | static pid_t gettid(void)
16*4882a593Smuzhiyun      |              ^~~~~~
17*4882a593SmuzhiyunIn file included from /usr/include/unistd.h:1170,
18*4882a593Smuzhiyun                 from procattr.c:2:
19*4882a593Smuzhiyun/usr/include/bits/unistd_ext.h:34:16: note: previous declaration of ‘gettid’ was here
20*4882a593Smuzhiyun   34 | extern __pid_t gettid (void) __THROW;
21*4882a593Smuzhiyun      |                ^~~~~~
22*4882a593Smuzhiyun
23*4882a593SmuzhiyunSigned-off-by: Petr Lautrbach <plautrba@redhat.com>
24*4882a593SmuzhiyunAcked-by: Stephen Smalley <sds@tycho.nsa.gov>
25*4882a593SmuzhiyunSigned-off-by: Khem Raj <raj.khem@gmail.com>
26*4882a593Smuzhiyun---
27*4882a593Smuzhiyun src/procattr.c | 14 +++++++++++++-
28*4882a593Smuzhiyun 1 file changed, 13 insertions(+), 1 deletion(-)
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun--- a/src/procattr.c
31*4882a593Smuzhiyun+++ b/src/procattr.c
32*4882a593Smuzhiyun@@ -8,12 +8,16 @@
33*4882a593Smuzhiyun #include "selinux_internal.h"
34*4882a593Smuzhiyun #include "policy.h"
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun-#ifndef __BIONIC__
37*4882a593Smuzhiyun+/* Bionic and glibc >= 2.30 declare gettid() system call wrapper in unistd.h and
38*4882a593Smuzhiyun+ * has a definition for it */
39*4882a593Smuzhiyun+#if defined(__GLIBC_)
40*4882a593Smuzhiyun+#if !__GLIBC_PREREQ(2,30)
41*4882a593Smuzhiyun static pid_t gettid(void)
42*4882a593Smuzhiyun {
43*4882a593Smuzhiyun 	return syscall(__NR_gettid);
44*4882a593Smuzhiyun }
45*4882a593Smuzhiyun #endif
46*4882a593Smuzhiyun+#endif
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun static int getprocattrcon(char ** context,
49*4882a593Smuzhiyun 			  pid_t pid, const char *attr)
50