summaryrefslogtreecommitdiffstats
path: root/login-utils/newgrp.c
diff options
context:
space:
mode:
authorSami Kerola2011-11-13 15:56:20 +0100
committerSami Kerola2011-11-23 21:37:19 +0100
commite947e273603d0fb9e9fdfa4ed7538a68d46c240e (patch)
treea3482dd085ff4fc52860acc65f069a63e4792086 /login-utils/newgrp.c
parentvipw: stop printing non-sense version string (diff)
downloadkernel-qcow2-util-linux-e947e273603d0fb9e9fdfa4ed7538a68d46c240e.tar.gz
kernel-qcow2-util-linux-e947e273603d0fb9e9fdfa4ed7538a68d46c240e.tar.xz
kernel-qcow2-util-linux-e947e273603d0fb9e9fdfa4ed7538a68d46c240e.zip
newgrp: add version and help options
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'login-utils/newgrp.c')
-rw-r--r--login-utils/newgrp.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/login-utils/newgrp.c b/login-utils/newgrp.c
index 7016cfa63..d826c541d 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 <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?"));