From 8614335f6ba1b23af5c40d4f31fa485cf7546b0d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 12 Mar 2012 12:23:29 +0100 Subject: sulogin: add long options Signed-off-by: Karel Zak --- login-utils/sulogin.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'login-utils/sulogin.c') diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c index 62707f1c6..14843d0b4 100644 --- a/login-utils/sulogin.c +++ b/login-utils/sulogin.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #ifdef HAVE_CRYPT_H # include @@ -395,18 +396,20 @@ static void sushell(struct passwd *pwd) static void usage(FILE *out) { - fprintf(out, USAGE_HEADER); + fputs(USAGE_HEADER, out); fprintf(out, _( - " %s [options] [tty device]\n"), program_invocation_short_name); - - fprintf(out, USAGE_OPTIONS); - fprintf(out, _( - " -p start a login shell\n" - " -t SEC max time to wait for a password (default: no limit)\n" - " -e examine shadow files directly if getpwnam(3) fails\n" - " -h display this help message\n")); - - fprintf(out, _("\nFor more information see sulogin(8).\n")); + " %s [options] [tty device]\n"), program_invocation_short_name); + + fputs(USAGE_OPTIONS, out); + fputs(_(" -p, --login-shell start a login shell\n" + " -t, --timeout max time to wait for a password (default: no limit)\n" + " -e, --force examine password files directly if getpwnam(3) fails\n"), + out); + + fputs(USAGE_SEPARATOR, out); + fputs(USAGE_HELP, out); + fputs(USAGE_VERSION, out); + fprintf(out, USAGE_MAN_TAIL("sulogin(8)")); } int main(int argc, char **argv) @@ -419,11 +422,19 @@ int main(int argc, char **argv) pid_t pid, pgrp, ppgrp, ttypgrp; struct sigaction saved_sighup; + static const struct option longopts[] = { + { "login-shell", 0, 0, 'p' }, + { "timeout", 1, 0, 't' }, + { "force", 0, 0, 'e' }, + { "help", 0, 0, 'h' }, + { "version", 0, 0, 'V' }, + { NULL, 0, 0, 0 } + }; + /* * See if we have a timeout flag. */ - opterr = 0; - while ((c = getopt(argc, argv, "ehpt:")) != EOF) { + while ((c = getopt_long(argc, argv, "ehpt:V", longopts, NULL)) != -1) { switch(c) { case 't': timeout = atoi(optarg); @@ -434,6 +445,9 @@ int main(int argc, char **argv) case 'e': opt_e = 1; break; + case 'V': + printf(UTIL_LINUX_VERSION); + return EXIT_SUCCESS; case 'h': usage(stdout); return EXIT_SUCCESS; -- cgit v1.2.3-55-g7522