25845f
commit 8915eacef88eb25ac94e6bb37b473adb326e9d1b
25845f
Author: Joseph Myers <joseph@codesourcery.com>
25845f
Date:   Wed Nov 26 20:54:16 2014 +0000
25845f
25845f
    Avoid warnings for unused results in nscd/connections.c.
25845f
    
25845f
    This patch avoids warnings for unused results of setuid and setgid in
25845f
    nscd/connections.c using an ignore_value macro along the lines
25845f
    suggested by Paul in
25845f
    <https://sourceware.org/ml/libc-alpha/2014-11/msg00733.html>.
25845f
    
25845f
    Tested for x86_64.
25845f
    
25845f
            * include/libc-internal.h (ignore_value): New macro.
25845f
            * nscd/connections.c (restart): Wrap calls to setuid and setgid
25845f
            with ignore_value.
25845f
25845f
diff --git a/include/libc-internal.h b/include/libc-internal.h
25845f
index 78f82da58a2c334b..2ced1c17d3dff93d 100644
25845f
--- a/include/libc-internal.h
25845f
+++ b/include/libc-internal.h
25845f
@@ -70,4 +70,10 @@ extern void __init_misc (int, char **, char **);
25845f
 #define PTR_ALIGN_UP(base, size) \
25845f
   ((__typeof__ (base)) ALIGN_UP ((uintptr_t) (base), (size)))
25845f
 
25845f
+/* Ignore the value of an expression when a cast to void does not
25845f
+   suffice (in particular, for a call to a function declared with
25845f
+   attribute warn_unused_result).  */
25845f
+#define ignore_value(x) \
25845f
+  ({ __typeof__ (x) __ignored_value = (x); (void) __ignored_value; })
25845f
+
25845f
 #endif /* _LIBC_INTERNAL  */
25845f
diff --git a/nscd/connections.c b/nscd/connections.c
25845f
index 53813cf58876eae7..54b70e88d894523a 100644
25845f
--- a/nscd/connections.c
25845f
+++ b/nscd/connections.c
25845f
@@ -1486,7 +1486,7 @@ cannot change to old UID: %s; disabling paranoia mode"),
25845f
 cannot change to old GID: %s; disabling paranoia mode"),
25845f
 		   strerror (errno));
25845f
 
25845f
-	  setuid (server_uid);
25845f
+	  ignore_value (setuid (server_uid));
25845f
 	  paranoia = 0;
25845f
 	  return;
25845f
 	}
25845f
@@ -1501,8 +1501,8 @@ cannot change to old working directory: %s; disabling paranoia mode"),
25845f
 
25845f
       if (server_user != NULL)
25845f
 	{
25845f
-	  setuid (server_uid);
25845f
-	  setgid (server_gid);
25845f
+	  ignore_value (setuid (server_uid));
25845f
+	  ignore_value (setgid (server_gid));
25845f
 	}
25845f
       paranoia = 0;
25845f
       return;
25845f
@@ -1546,8 +1546,8 @@ cannot change to old working directory: %s; disabling paranoia mode"),
25845f
 
25845f
   if (server_user != NULL)
25845f
     {
25845f
-      setuid (server_uid);
25845f
-      setgid (server_gid);
25845f
+      ignore_value (setuid (server_uid));
25845f
+      ignore_value (setgid (server_gid));
25845f
     }
25845f
   if (chdir ("/") != 0)
25845f
     dbg_log (_("cannot change current working directory to \"/\": %s"),