]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: add --help and --version
authorRuediger Meier <ruediger.meier@ga-group.nl>
Wed, 21 Jun 2017 02:14:58 +0000 (04:14 +0200)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Thu, 22 Jun 2017 19:34:54 +0000 (21:34 +0200)
Also we don't print the usage text on stderr anymore.

Note, the usage text could be improved, currently it
does not describe any options. I have only added a
pointer to the man page.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
login-utils/login.1
login-utils/login.c

index 2fc7a501f378074a5ff927a577b04160e5a5cafc..5d43fdcddec884cc8f04d1c2af96770d7396d834 100644 (file)
@@ -131,7 +131,10 @@ to tell
 .B login
 that printing the hostname should be suppressed in the login: prompt.
 .TP
-.B \-V
+\fB\-\-help\fR
+Display help text and exit.
+.TP
+\fB\-V\fR, \fB\-\-version\fR
 Display version information and exit.
 .SH CONFIG FILE ITEMS
 .B login
index 37553ef0a7de1df490127db457260ab6f291953f..ee06d03e877a55a94cb91a0c3a52023ebfce8b55 100644 (file)
@@ -1095,6 +1095,16 @@ static void init_remote_info(struct login_context *cxt, char *remotehost)
        }
 }
 
+static void __attribute__((__noreturn__)) usage(void)
+{
+       fputs(USAGE_HEADER, stdout);
+       printf(_(" %s [-p] [-h <host>] [-H] [[-f] <username>]\n"), program_invocation_short_name);
+       fputs(USAGE_SEPARATOR, stdout);
+       fputs(_("Begin a session on the system.\n"), stdout);
+       printf(USAGE_MAN_TAIL("login(1)"));
+       exit(EXIT_SUCCESS);
+}
+
 int main(int argc, char **argv)
 {
        int c;
@@ -1119,6 +1129,14 @@ int main(int argc, char **argv)
 
        };
 
+       /* the only two longopts to satisfy UL standards */
+       enum { HELP_OPTION = CHAR_MAX + 1 };
+       static const struct option longopts[] = {
+               {"help", no_argument, NULL, HELP_OPTION},
+               {"version", no_argument, NULL, 'V'},
+               {NULL, 0, NULL, 0}
+       };
+
        timeout = (unsigned int)getlogindefs_num("LOGIN_TIMEOUT", LOGIN_TIMEOUT);
 
        signal(SIGALRM, timedout);
@@ -1142,7 +1160,7 @@ int main(int argc, char **argv)
         * -h is used by other servers to pass the name of the remote
         *    host to login so that it may be placed in utmp and wtmp
         */
-       while ((c = getopt(argc, argv, "fHh:pV")) != -1)
+       while ((c = getopt_long(argc, argv, "fHh:pV", longopts, NULL)) != -1)
                switch (c) {
                case 'f':
                        cxt.noauth = 1;
@@ -1168,12 +1186,10 @@ int main(int argc, char **argv)
                case 'V':
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
-               case '?':
+               case HELP_OPTION:
+                       usage();
                default:
-                       fprintf(stderr, _("Usage: login [-p] [-h <host>] [-H] [[-f] <username>]\n"));
-                       fputs(USAGE_SEPARATOR, stderr);
-                       fputs(_("Begin a session on the system.\n"), stderr);
-                       exit(EXIT_FAILURE);
+                       errtryhelp(EXIT_FAILURE);
                }
        argc -= optind;
        argv += optind;