[PATCH] newgrp: Use err() and EXIT_*

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use err() or errx() where appropriate.  Also use EXIT_* macros instead
of 0/1.  All error messages shall start with lowercase.

Signed-off-by: Marek Polacek <mmpolacek@xxxxxxxxx>
---
 login-utils/newgrp.c |   40 +++++++++++++++-------------------------
 1 files changed, 15 insertions(+), 25 deletions(-)

diff --git a/login-utils/newgrp.c b/login-utils/newgrp.c
index 976a049..052c01e 100644
--- a/login-utils/newgrp.c
+++ b/login-utils/newgrp.c
@@ -14,6 +14,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <err.h>

 #include "c.h"
 #include "pathnames.h"
@@ -95,47 +96,36 @@ main(int argc, char *argv[])
     bindtextdomain(PACKAGE, LOCALEDIR);
     textdomain(PACKAGE);

-    if (!(pw_entry = getpwuid(getuid()))) {
-	perror(_("newgrp: Who are you?"));
-	exit(1);
-    }
+    if (!(pw_entry = getpwuid(getuid())))
+	err(EXIT_FAILURE, _("who are you?"));

     shell = (pw_entry->pw_shell[0] ? pw_entry->pw_shell : _PATH_BSHELL);

     if (argc < 2) {
-	if(setgid(pw_entry->pw_gid) < 0) {
-	    perror(_("newgrp: setgid"));
-	    exit(1);
-	}
+	if(setgid(pw_entry->pw_gid) < 0)
+	    err(EXIT_FAILURE, "setgid");
     } else {
 	errno = 0;
 	if (!(gr_entry = getgrnam(argv[1]))) {
 	    if (errno)
-		    perror(_("newgrp: No such group."));			/* error */
+		    err(EXIT_FAILURE, _("no such group"));
 	    else
-		    fprintf(stderr, "%s\n", _("newgrp: No such group."));	/* no group */
-	    exit(1);
+		    errx(EXIT_FAILURE, _("no such group"));	/* No group */
 	} else {
-	    if(allow_setgid(pw_entry, gr_entry)) {
-		if(setgid(gr_entry->gr_gid) < 0) {
-		    perror(_("newgrp: setgid"));
-		    exit(1);
-		}
-	    } else {
-		puts(_("newgrp: Permission denied"));
-		exit(1);
-	    }
+	    if (allow_setgid(pw_entry, gr_entry)) {
+		if (setgid(gr_entry->gr_gid) < 0)
+		    err(EXIT_FAILURE, "setgid");
+	    } else
+	        errx(EXIT_FAILURE, _("permission denied"));
 	}
     }

-    if(setuid(getuid()) < 0) {
-	perror(_("newgrp: setuid"));
-	exit(1);
-    }
+    if (setuid(getuid()) < 0)
+	err(EXIT_FAILURE, "setuid");

     fflush(stdout); fflush(stderr);
     execl(shell,shell,(char*)0);
     perror(_("No shell"));
     fflush(stderr);
-    exit(1);
+    exit(EXIT_FAILURE);
 }
-- 
1.7.3.2



--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux