]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sulogin: add long options
authorKarel Zak <kzak@redhat.com>
Mon, 12 Mar 2012 11:23:29 +0000 (12:23 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 12 Mar 2012 11:23:29 +0000 (12:23 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/sulogin.8
login-utils/sulogin.c

index e5d2f2865a835aec166182345199717e31f820b8..916bbef7cdc88cf064a46e7852100cb2a4894327 100644 (file)
@@ -39,18 +39,24 @@ optional tty device that can be specified on the command line
 After the user exits the single-user shell or presses control\-D at the
 prompt, the system will continue to boot.
 .SH OPTIONS
-.IP "\fB\-t \fIseconds\fP"
-Specify the maximum amount of time to wait for user input. By default,
-sulogin will wait forever.
-.IP "\fB\-p\fP"
-Specifying this option causes sulogin to start the shell process as a
-login shell.
-.IP "\fB\-e\fP"
+.IP "\fB\-e, \-\-force\fP"
 If the default method of obtaining the root password via \fBgetpwnam\fP(3) from
 the system fails, manually examine /etc/passwd and /etc/shadow to get the
 password. If they are damaged or nonexistent, sulogin will start a root shell
-without asking for a password. Only use the \fB\-e\fP option if you are sure
-the console is physically protected against unauthorized access.
+without asking for a password.
+
+Only use the \fB\-e\fP option if you are sure the console is physically
+protected against unauthorized access.
+.IP "\fB\-h, \-\-help\fP"
+Print a help message.
+.IP "\fB\-p, \-\-login\-shell\fP"
+Specifying this option causes sulogin to start the shell process as a
+login shell.
+.IP "\fB\-t, \-\-timeout \fIseconds\fP"
+Specify the maximum amount of time to wait for user input. By default,
+sulogin will wait forever.
+.IP "\fB\-V, \-\-version\fP"
+Output version.
 .SH ENVIRONMENT VARIABLES
 \fIsulogin\fP looks for the environment variable \fBSUSHELL\fP or
 \fBsushell\fP to determine what shell to start. If the environment variable
index 62707f1c6059ca94414195f8ddf531d5ba8809f4..14843d0b438132f411272a0fa800f6a3e2d635e8 100644 (file)
@@ -34,6 +34,7 @@
 #include <shadow.h>
 #include <termios.h>
 #include <errno.h>
+#include <getopt.h>
 #include <sys/ioctl.h>
 #ifdef HAVE_CRYPT_H
 # include <crypt.h>
@@ -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 <seconds>  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;