This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix and cleanup setxid stuff


Hi!

With current CVS, it is impossible to statically link programs
that use set{,e,re,res}[ug]id.
The following patch ought to cure it and cleanup the setxid stuff
at the same time (so that there is not that much code duplication,
and NPTL specific stuff is not used in non-nptl/ tree).
The .os files on x86-64 (with the exception of setres[ug]id.os
that were incorrectly for current thread only before this patch)
were identical with and without this patch (after stripping).

2004-11-10  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/unix/sysv/linux/setreuid.c: Remove sys/syscall.h,
	sys/types.h, linux/posix_types.h and pthread-functions.h includes.
	Include setxid.h.  Use SETXID macro.
	* sysdeps/unix/sysv/linux/setegid.c: Likewise.
	* sysdeps/unix/sysv/linux/setuid.c: Likewise.
	* sysdeps/unix/sysv/linux/seteuid.c: Likewise.
	* sysdeps/unix/sysv/linux/setgid.c: Likewise.
	* sysdeps/unix/sysv/linux/setresuid.c: Likewise.
	* sysdeps/unix/sysv/linux/setresgid.c: Likewise.
	* sysdeps/unix/sysv/linux/setregid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setegid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setreuid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setuid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/seteuid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setgid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setresuid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setresgid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setregid.c: Likewise.
	* sysdeps/unix/sysv/linux/alpha/setreuid.c: Likewise.
	Formatting.  Change signed int into int.
	* sysdeps/unix/sysv/linux/alpha/setresuid.c: Likewise.
	* sysdeps/unix/sysv/linux/alpha/setresgid.c: Likewise.
	* sysdeps/unix/sysv/linux/alpha/setregid.c: Likewise.
	* sysdeps/unix/sysv/linux/syscalls.list (setresuid, setresgid):
	Remove.
	* sysdeps/generic/setxid.h: New file.
nptl/
	* sysdeps/pthread/setxid.h: New file.
	* sysdeps/pthread/pthread-functions.h (HAVE_PTR__NPTL_SETXID): Remove.
	(struct xid_command): Add forward decl.

--- libc/sysdeps/unix/sysv/linux/setegid.c.jj	2004-11-10 15:14:00.800982231 +0100
+++ libc/sysdeps/unix/sysv/linux/setegid.c	2004-11-10 15:32:55.752982281 +0100
@@ -17,13 +17,10 @@
    02111-1307 USA.  */
 
 #include <errno.h>
-#include <sys/syscall.h>
-#include <sys/types.h>
 #include <unistd.h>
-
 #include <sysdep.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 #if defined __NR_setresgid || __ASSUME_SETRESGID_SYSCALL > 0
@@ -55,21 +52,12 @@ setegid (gid_t gid)
 #  endif
 # endif
 
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
+  if (result == 0)
 # ifdef __NR_setresgid32
-      cmd.syscall_no = __NR_setresgid32;
+      SETXID (setresgid32, 3, -1, gid, -1);
 # else
-      cmd.syscall_no = __NR_setresgid;
+      SETXID (setresgid, 3, -1, gid, -1);
 # endif
-      cmd.id[0] = -1;
-      cmd.id[1] = gid;
-      cmd.id[2] = -1;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/setreuid.c.jj	2004-11-10 15:14:00.805981345 +0100
+++ libc/sysdeps/unix/sysv/linux/setreuid.c	2004-11-10 15:32:55.753982104 +0100
@@ -18,14 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 int
@@ -34,17 +29,8 @@ __setreuid (uid_t ruid, uid_t euid)
   int result;
 
   result = INLINE_SYSCALL (setreuid, 2, ruid, euid);
-
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setreuid;
-      cmd.id[0] = ruid;
-      cmd.id[1] = euid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setreuid, 2, ruid, euid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/setuid.c.jj	2004-11-10 15:14:00.810980458 +0100
+++ libc/sysdeps/unix/sysv/linux/setuid.c	2004-11-10 15:32:55.755981749 +0100
@@ -18,15 +18,8 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
-#include "kernel-features.h"
-#include <pthread-functions.h>
-
+#include <setxid.h>
 
 int
 __setuid (uid_t uid)
@@ -34,16 +27,8 @@ __setuid (uid_t uid)
   int result;
 
   result = INLINE_SYSCALL (setuid, 1, uid);
-
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setuid;
-      cmd.id[0] = uid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setuid, 1, uid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/seteuid.c.jj	2004-11-10 15:14:00.814979749 +0100
+++ libc/sysdeps/unix/sysv/linux/seteuid.c	2004-11-10 15:32:55.756981572 +0100
@@ -17,13 +17,10 @@
    02111-1307 USA.  */
 
 #include <errno.h>
-#include <sys/syscall.h>
-#include <sys/types.h>
 #include <unistd.h>
-
 #include <sysdep.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 #if defined __NR_setresuid || __ASSUME_SETRESUID_SYSCALL > 0
@@ -55,21 +52,12 @@ seteuid (uid_t uid)
 #  endif
 # endif
 
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
+  if (result == 0)
 # ifdef __NR_setresuid32
-      cmd.syscall_no = __NR_setresuid32;
+    SETXID (setresuid32, 3, -1, uid, -1);
 # else
-      cmd.syscall_no = __NR_setresuid;
+    SETXID (setresuid, 3, -1, uid, -1);
 # endif
-      cmd.id[0] = -1;
-      cmd.id[1] = uid;
-      cmd.id[2] = -1;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/setgid.c.jj	2004-11-10 15:14:00.819978862 +0100
+++ libc/sysdeps/unix/sysv/linux/setgid.c	2004-11-10 15:32:55.757981394 +0100
@@ -18,15 +18,8 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
-#include "kernel-features.h"
-#include <pthread-functions.h>
-
+#include <setxid.h>
 
 
 int
@@ -35,16 +28,8 @@ __setgid (gid_t gid)
   int result;
 
   result = INLINE_SYSCALL (setgid, 1, gid);
-
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setgid;
-      cmd.id[0] = gid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setgid, 1, gid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/alpha/setreuid.c.jj	2004-11-01 06:31:54.000000000 +0100
+++ libc/sysdeps/unix/sysv/linux/alpha/setreuid.c	2004-11-10 15:48:21.491740775 +0100
@@ -18,14 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 int
@@ -33,18 +28,9 @@ __setreuid (uid_t ruid, uid_t euid)
 {
   int result;
 
-  result = INLINE_SYSCALL (setreuid, 2, (signed int)ruid, (signed int)euid);
-
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setreuid;
-      cmd.id[0] = ruid;
-      cmd.id[1] = euid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  result = INLINE_SYSCALL (setreuid, 2, (int) ruid, (int) euid);
+  if (result == 0)
+    SETXID (setreuid, 2, ruid, euid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/alpha/setresuid.c.jj	2004-11-01 06:31:54.000000000 +0100
+++ libc/sysdeps/unix/sysv/linux/alpha/setresuid.c	2004-11-10 15:47:59.226691593 +0100
@@ -18,14 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 int
@@ -33,19 +28,9 @@ __setresuid (uid_t ruid, uid_t euid, uid
 {
   int result;
 
-  result = INLINE_SYSCALL (setresuid, 3, (signed int)ruid, (signed int)euid, (signed int)suid);
-
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setresuid;
-      cmd.id[0] = ruid;
-      cmd.id[1] = euid;
-      cmd.id[2] = suid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  result = INLINE_SYSCALL (setresuid, 3, (int) ruid, (int) euid, (int) suid);
+  if (result == 0)
+    SETXID (setresuid, ruid, euid, suid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/alpha/setresgid.c.jj	2004-11-01 06:31:54.000000000 +0100
+++ libc/sysdeps/unix/sysv/linux/alpha/setresgid.c	2004-11-10 15:49:25.147445393 +0100
@@ -18,14 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 int
@@ -33,19 +28,9 @@ __setresgid (gid_t rgid, gid_t egid, gid
 {
   int result;
 
-  result = INLINE_SYSCALL (setresgid, 3, (signed int)rgid, (signed int)egid, (signed int)sgid);
-
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setresgid;
-      cmd.id[0] = rgid;
-      cmd.id[1] = egid;
-      cmd.id[2] = sgid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  result = INLINE_SYSCALL (setresgid, 3, (int) rgid, (int) egid, (int) sgid);
+  if (result == 0)
+    SETXID (setresgid, rgid, egid, sgid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/alpha/setregid.c.jj	2004-11-01 06:31:54.000000000 +0100
+++ libc/sysdeps/unix/sysv/linux/alpha/setregid.c	2004-11-10 15:48:08.621024617 +0100
@@ -18,14 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 int
@@ -33,18 +28,9 @@ __setregid (gid_t rgid, gid_t egid)
 {
   int result;
 
-  result = INLINE_SYSCALL (setregid, 2, (signed int)rgid, (signed int)egid);
-
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setregid;
-      cmd.id[0] = rgid;
-      cmd.id[1] = egid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  result = INLINE_SYSCALL (setregid, 2, (int) rgid, (int) egid);
+  if (result == 0)
+    SETXID (setregid, 2, rgid, egid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/setresuid.c.jj	2004-11-10 15:14:00.824977976 +0100
+++ libc/sysdeps/unix/sysv/linux/setresuid.c	2004-11-10 15:32:55.758981217 +0100
@@ -18,14 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 int
@@ -34,18 +29,8 @@ __setresuid (uid_t ruid, uid_t euid, uid
   int result;
 
   result = INLINE_SYSCALL (setresuid, 3, ruid, euid, suid);
-
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setresuid;
-      cmd.id[0] = ruid;
-      cmd.id[1] = euid;
-      cmd.id[2] = suid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setresuid, 3, ruid, euid, suid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/i386/setegid.c.jj	2004-11-10 15:14:00.829977089 +0100
+++ libc/sysdeps/unix/sysv/linux/i386/setegid.c	2004-11-10 15:32:55.759981039 +0100
@@ -18,11 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 #ifdef __NR_setresgid
@@ -59,17 +57,8 @@ setegid (gid)
     result = __setregid (-1, gid);
 #endif
 
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setresgid32;
-      cmd.id[0] = -1;
-      cmd.id[1] = gid;
-      cmd.id[2] = -1;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setresgid32, 3, -1, gid, -1);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/i386/setreuid.c.jj	2004-11-10 15:14:00.834976203 +0100
+++ libc/sysdeps/unix/sysv/linux/i386/setreuid.c	2004-11-10 15:32:55.760980862 +0100
@@ -17,15 +17,10 @@
    02111-1307 USA.  */
 
 #include <errno.h>
-#include <sys/types.h>
 #include <unistd.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 #ifdef __NR_setreuid32
@@ -73,16 +68,8 @@ __setreuid (uid_t ruid, uid_t euid)
 # endif
 #endif
 
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setreuid32;
-      cmd.id[0] = ruid;
-      cmd.id[1] = euid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setreuid32, 2, ruid, euid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/i386/setuid.c.jj	2004-11-10 15:14:00.839975316 +0100
+++ libc/sysdeps/unix/sysv/linux/i386/setuid.c	2004-11-10 15:32:55.761980685 +0100
@@ -18,14 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 #ifdef __NR_setuid32
@@ -73,15 +68,8 @@ __setuid (uid_t uid)
 # endif
 #endif
 
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setuid32;
-      cmd.id[0] = uid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setuid32, 1, uid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/i386/seteuid.c.jj	2004-11-10 15:14:00.843974607 +0100
+++ libc/sysdeps/unix/sysv/linux/i386/seteuid.c	2004-11-10 15:32:55.762980507 +0100
@@ -17,12 +17,10 @@
    02111-1307 USA.  */
 
 #include <errno.h>
-#include <sys/types.h>
 #include <unistd.h>
-
 #include <sysdep.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 #ifdef __NR_setresuid
@@ -58,17 +56,8 @@ seteuid (uid_t uid)
     result = __setreuid (-1, uid);
 #endif
 
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setresuid32;
-      cmd.id[0] = -1;
-      cmd.id[1] = uid;
-      cmd.id[2] = -1;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setresuid32, 3, -1, uid, -1);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/i386/setgid.c.jj	2004-11-10 15:14:00.848973720 +0100
+++ libc/sysdeps/unix/sysv/linux/i386/setgid.c	2004-11-10 15:32:55.763980330 +0100
@@ -1,5 +1,4 @@
-/* Copyright (C) 1998, 2000, 2003, 2004
-   Free Software Foundation, Inc.
+/* Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -19,15 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
-
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 #ifdef __NR_setgid32
@@ -76,15 +69,8 @@ __setgid (gid_t gid)
 # endif
 #endif
 
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setgid32;
-      cmd.id[0] = gid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setgid32, 1, gid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/i386/setresuid.c.jj	2004-11-10 15:14:00.853972834 +0100
+++ libc/sysdeps/unix/sysv/linux/i386/setresuid.c	2004-11-10 15:32:55.764980152 +0100
@@ -18,14 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
-#include <linux/posix_types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 #if defined __NR_setresuid || defined __NR_setresuid32
@@ -76,17 +71,8 @@ __setresuid (uid_t ruid, uid_t euid, uid
 #  endif
 # endif
 
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setresuid32;
-      cmd.id[0] = ruid;
-      cmd.id[1] = euid;
-      cmd.id[2] = suid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setresuid32, 3, ruid, euid, suid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/i386/setresgid.c.jj	2004-11-10 15:14:00.858971947 +0100
+++ libc/sysdeps/unix/sysv/linux/i386/setresgid.c	2004-11-10 15:32:55.765979975 +0100
@@ -18,14 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
-#include <linux/posix_types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 #if defined __NR_setresgid || defined __NR_setresgid32
@@ -76,17 +71,8 @@ __setresgid (gid_t rgid, gid_t egid, gid
 #  endif
 # endif
 
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setresgid32;
-      cmd.id[0] = rgid;
-      cmd.id[1] = egid;
-      cmd.id[2] = sgid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setresgid32, 3, rgid, egid, sgid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/i386/setregid.c.jj	2004-11-10 15:14:00.863971061 +0100
+++ libc/sysdeps/unix/sysv/linux/i386/setregid.c	2004-11-10 15:32:55.766979798 +0100
@@ -17,15 +17,10 @@
    02111-1307 USA.  */
 
 #include <errno.h>
-#include <sys/types.h>
 #include <unistd.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 #ifdef __NR_setregid32
@@ -73,16 +68,8 @@ __setregid (gid_t rgid, gid_t egid)
 # endif
 #endif
 
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setregid32;
-      cmd.id[0] = rgid;
-      cmd.id[1] = egid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setregid32, 2, rgid, egid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/setresgid.c.jj	2004-11-10 15:14:00.867970351 +0100
+++ libc/sysdeps/unix/sysv/linux/setresgid.c	2004-11-10 15:32:55.767979620 +0100
@@ -18,14 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 int
@@ -34,18 +29,8 @@ __setresgid (gid_t rgid, gid_t egid, gid
   int result;
 
   result = INLINE_SYSCALL (setresgid, 3, rgid, egid, sgid);
-
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setresgid;
-      cmd.id[0] = rgid;
-      cmd.id[1] = egid;
-      cmd.id[2] = sgid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setresgid, 3, rgid, egid, sgid);
 
   return result;
 }
--- libc/sysdeps/unix/sysv/linux/syscalls.list.jj	2004-11-01 13:25:48.000000000 +0100
+++ libc/sysdeps/unix/sysv/linux/syscalls.list	2004-11-10 15:34:44.486697056 +0100
@@ -66,8 +66,6 @@ sendfile64	-	sendfile64	i:iipi	sendfile6
 setfsgid	EXTRA	setfsgid	i:i	setfsgid
 setfsuid	EXTRA	setfsuid	i:i	setfsuid
 setpgid		-	setpgid		i:ii	__setpgid	setpgid
-setresuid	-	setresuid	i:iii	__setresuid	setresuid
-setresgid	-	setresgid	i:iii	__setresgid	setresgid
 sigaltstack	-	sigaltstack	i:PP	__sigaltstack	sigaltstack
 sysinfo		EXTRA	sysinfo		i:p	sysinfo
 swapon		-	swapon		i:si	__swapon	swapon
--- libc/sysdeps/unix/sysv/linux/setregid.c.jj	2004-11-10 15:14:00.872969465 +0100
+++ libc/sysdeps/unix/sysv/linux/setregid.c	2004-11-10 15:32:55.768979443 +0100
@@ -18,14 +18,9 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <sys/types.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <linux/posix_types.h>
 #include "kernel-features.h"
-#include <pthread-functions.h>
+#include <setxid.h>
 
 
 int
@@ -34,17 +29,8 @@ __setregid (gid_t rgid, gid_t egid)
   int result;
 
   result = INLINE_SYSCALL (setregid, 2, rgid, egid);
-
-#if defined HAVE_PTR__NPTL_SETXID && !defined SINGLE_THREAD
-  if (result == 0 && __libc_pthread_functions.ptr__nptl_setxid != NULL)
-    {
-      struct xid_command cmd;
-      cmd.syscall_no = __NR_setregid;
-      cmd.id[0] = rgid;
-      cmd.id[1] = egid;
-      __libc_pthread_functions.ptr__nptl_setxid (&cmd);
-    }
-#endif
+  if (result == 0)
+    SETXID (setregid, 2, rgid, egid);
 
   return result;
 }
--- libc/sysdeps/generic/setxid.h.jj	2004-11-10 13:12:58.099998869 +0100
+++ libc/sysdeps/generic/setxid.h	2004-11-10 15:32:55.770979088 +0100
@@ -0,0 +1,2 @@
+/* Nothing needed to be done general.  */
+#define SETXID(name, nr, args...) do { } while (0)
--- libc/nptl/sysdeps/pthread/setxid.h.jj	2004-11-10 13:12:58.000000000 +0100
+++ libc/nptl/sysdeps/pthread/setxid.h	2004-11-10 15:32:55.771978911 +0100
@@ -0,0 +1,58 @@
+/* Copyright (C) 2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <pthreadP.h>
+
+#define __SETXID_1(cmd, arg1) \
+  cmd.id[0] = arg1
+#define __SETXID_2(cmd, arg1, arg2) \
+  __SETXID_1 (cmd, arg1); cmd.id[1] = arg2
+#define __SETXID_3(cmd, arg1, arg2, arg3) \
+  __SETXID_2 (cmd, arg1, arg2); cmd.id[2] = arg3
+
+#ifdef SINGLE_THREAD
+# define SETXID(name, nr, args...) do { } while (0)
+#elif defined SHARED
+# define SETXID(name, nr, args...) \
+  do								\
+    {								\
+      if (__libc_pthread_functions.ptr__nptl_setxid != NULL)	\
+	{							\
+	  struct xid_command __cmd;				\
+	  __cmd.syscall_no = __NR_##name;			\
+	  __SETXID_##nr (__cmd, args);				\
+	  __libc_pthread_functions.ptr__nptl_setxid (&__cmd);	\
+	}							\
+    }								\
+  while (0)
+#else
+# define SETXID(name, nr, args...) \
+  do								\
+    {								\
+      extern __typeof (__nptl_setxid) __nptl_setxid		\
+	__attribute__((weak));					\
+      if (__nptl_setxid != NULL)				\
+	{							\
+	  struct xid_command __cmd;				\
+	  __cmd.syscall_no = __NR_##name;			\
+	  __SETXID_##nr (__cmd, args);				\
+	  __nptl_setxid (&__cmd);				\
+	}							\
+    }								\
+  while (0)
+#endif
--- libc/nptl/sysdeps/pthread/pthread-functions.h.jj	2004-09-20 15:35:02.000000000 +0200
+++ libc/nptl/sysdeps/pthread/pthread-functions.h	2004-11-10 15:32:55.772978733 +0100
@@ -24,6 +24,7 @@
 #include <setjmp.h>
 #include <internaltypes.h>
 
+struct xid_command;
 
 /* Data type shared with libc.  The libc uses it to pass on calls to
    the thread functions.  */
@@ -93,7 +94,6 @@ struct pthread_functions
   void (*ptr___pthread_unwind) (__pthread_unwind_buf_t *)
        __attribute ((noreturn)) __cleanup_fct_attribute;
   void (*ptr__nptl_deallocate_tsd) (void);
-#define HAVE_PTR__NPTL_SETXID
   void (*ptr__nptl_setxid) (struct xid_command *);
 };
 

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]