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---
27Upstream-Status: Pending
28
29 src/procattr.c | 14 +++++++++++++-
30 1 file changed, 13 insertions(+), 1 deletion(-)
31
32--- a/src/procattr.c
33+++ b/src/procattr.c
34@@ -8,12 +8,16 @@
35 #include "selinux_internal.h"
36 #include "policy.h"
37
38-#ifndef __BIONIC__
39+/* Bionic and glibc >= 2.30 declare gettid() system call wrapper in unistd.h and
40+ * has a definition for it */
41+#if defined(__GLIBC_)
42+#if !__GLIBC_PREREQ(2,30)
43 static pid_t gettid(void)
44 {
45 	return syscall(__NR_gettid);
46 }
47 #endif
48+#endif
49
50 static int getprocattrcon(char ** context,
51 			  pid_t pid, const char *attr)
52