From e947e273603d0fb9e9fdfa4ed7538a68d46c240e Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 13 Nov 2011 15:56:20 +0100 Subject: newgrp: add version and help options Signed-off-by: Sami Kerola --- login-utils/newgrp.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'login-utils/newgrp.c') 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 #include #include +#include #ifdef HAVE_CRYPT_H #include @@ -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 \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?")); -- cgit v1.2.3-55-g7522