]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
newgrp: add version and help options
authorSami Kerola <kerolasa@iki.fi>
Sun, 13 Nov 2011 14:56:20 +0000 (15:56 +0100)
committerSami Kerola <kerolasa@iki.fi>
Wed, 23 Nov 2011 20:37:19 +0000 (21:37 +0100)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/newgrp.c

index 7016cfa635b66e8d88fa06ec42f7ecb2fe1d2abe..d826c541da7e481e6888dca517d16d970833798b 100644 (file)
@@ -14,6 +14,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <getopt.h>
 
 #ifdef HAVE_CRYPT_H
 #include <crypt.h>
@@ -87,17 +88,45 @@ allow_setgid(struct passwd *pe, struct group *ge)
     return FALSE;                      /* default to denial */
 }
 
+static void __attribute__ ((__noreturn__)) usage(FILE * out)
+{
+    fprintf(out, USAGE_HEADER);
+    fprintf(out, _(" %s <group>\n"), program_invocation_short_name);
+    fprintf(out, USAGE_OPTIONS);
+    fprintf(out, USAGE_HELP);
+    fprintf(out, USAGE_VERSION);
+    fprintf(out, USAGE_MAN_TAIL("newgrp(1)"));
+    exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
 int
 main(int argc, char *argv[])
 {
     struct passwd *pw_entry;
     struct group *gr_entry;
     char *shell;
+    char ch;
+    static const struct option longopts[] = {
+       {"version", no_argument, NULL, 'V'},
+       {"help", no_argument, NULL, 'h'},
+       {NULL, 0, NULL, 0}
+    };
 
     setlocale(LC_ALL, "");
     bindtextdomain(PACKAGE, LOCALEDIR);
     textdomain(PACKAGE);
 
+    while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
+       switch (ch) {
+       case 'V':
+           printf(UTIL_LINUX_VERSION);
+           return EXIT_SUCCESS;
+       case 'h':
+           usage(stdout);
+       default:
+           usage(stderr);
+       }
+
     if (!(pw_entry = getpwuid(getuid())))
        err(EXIT_FAILURE, _("who are you?"));