This is the mail archive of the libc-alpha@sourceware.org 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] grp: testgrp should exit unsupported properly.


grp/testgrp should properly exit unsupported if getpweuid() returns
NULL and it does not set errno since it indicates that tests are
executed by a passwordless user.

Also refactor to use the support test driver.

Checked on x86_64-linux-gnu.

2017-04-13  Wainer dos Santos Moschetta  <wainersm@gmail.com>

	* grp/testgrp.c: Import support/test-driver.
	(do_test): New, replace main().
	(do_test): exit unsupported if getpwuid() returns NULL
	and it does not set errno.
---
 grp/testgrp.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/grp/testgrp.c b/grp/testgrp.c
index 892cfaa..38f6088 100644
--- a/grp/testgrp.c
+++ b/grp/testgrp.c
@@ -1,12 +1,14 @@
+#include <errno.h>
 #include <grp.h>
 #include <pwd.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <support/test-driver.h>
 
 int
-main (int argc, char *argv[])
+do_test (void)
 {
   uid_t me;
   struct passwd *my_passwd;
@@ -14,9 +16,21 @@ main (int argc, char *argv[])
   char **members;
 
   me = getuid ();
+  errno = 0;
   my_passwd = getpwuid (me);
   if (my_passwd == NULL)
-    printf ("Cannot find user entry for UID %d\n", me);
+    {
+      if (errno == 0)
+        {
+          printf ("Cannot find user entry for UID %d\n", me);
+          return EXIT_UNSUPPORTED;
+        }
+      else
+        {
+          printf ("FAIL: getpwuid() exited with error: %m\n");
+          return EXIT_FAILURE;
+        }
+    }
   else
     {
       printf ("My login name is %s.\n", my_passwd->pw_name);
@@ -39,3 +53,5 @@ main (int argc, char *argv[])
 
   return my_passwd && my_group ? EXIT_SUCCESS : EXIT_FAILURE;
 }
+
+#include <support/test-driver.c>
-- 
2.7.4


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