]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fsck: add --help and --version
authorRuediger Meier <ruediger.meier@ga-group.nl>
Wed, 21 Jun 2017 13:33:57 +0000 (15:33 +0200)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Thu, 22 Jun 2017 19:34:51 +0000 (21:34 +0200)
Also cleanup usage() function, never write usage to stderr.

FIXME:
 - currently strtou32_or_err() exits with wrong exit code.
 - option -C does not use a safe strto*_err function

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
disk-utils/fsck.8
disk-utils/fsck.c

index 3148e428437676f2db1463ebf6cd3b1f453970a7..b3096bec60228bc91a64164dceba6343ced6a2b2 100644 (file)
@@ -309,6 +309,12 @@ Don't show the title on startup.
 .B \-V
 Produce verbose output, including all filesystem-specific commands
 that are executed.
+.TP
+\fB\-?\fR, \fB\-\-help\fR
+Display help text and exit.
+.TP
+\fB\-\-version\fR
+Display version information and exit.
 .SH FILESYSTEM SPECIFIC OPTIONS
 .B Options which are not understood by fsck are passed to the filesystem-specific checker! 
 .PP
index cb1b21278c3c3a9c0a2f5aad14d061639e7b82d6..cbe179ba6296b1c60d1f9c1021ffdbf49f54e0a6 100644 (file)
@@ -1369,8 +1369,9 @@ static int check_all(void)
        return status;
 }
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] -- [fs-options] [<filesystem> ...]\n"),
                         program_invocation_short_name);
@@ -1393,13 +1394,14 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fputs(_(" -t <type>  specify filesystem types to be checked;\n"
                "            <type> is allowed to be a comma-separated list\n"), out);
        fputs(_(" -V         explain what is being done\n"), out);
-       fputs(_(" -?         display this help and exit\n"), out);
 
+       fputs(USAGE_SEPARATOR, out);
+       fputs(_(" -?, --help     display this help and exit\n"), out);
+       fputs(_("     --version  output version information and exit\n"), out);
        fputs(USAGE_SEPARATOR, out);
        fputs(_("See the specific fsck.* commands for available fs-options."), out);
        fprintf(out, USAGE_MAN_TAIL("fsck(8)"));
-
-       exit(out == stderr ? FSCK_EX_USAGE : FSCK_EX_OK);
+       exit(FSCK_EX_OK);
 }
 
 static void signal_cancel(int sig __attribute__((__unused__)))
@@ -1433,6 +1435,15 @@ static void parse_argv(int argc, char *argv[])
                arg = argv[i];
                if (!arg)
                        continue;
+
+               /* the only two longopts to satisfy UL standards */
+               if (!opts_for_fsck && !strcmp(arg, "--help"))
+                       usage();
+               if (!opts_for_fsck && !strcmp(arg, "--version")) {
+                       printf(UTIL_LINUX_VERSION);
+                       exit(FSCK_EX_OK);
+               }
+
                if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) {
                        if (num_devices >= MAX_DEVICES)
                                errx(FSCK_EX_ERROR, _("too many devices"));
@@ -1536,13 +1547,15 @@ static void parse_argv(int argc, char *argv[])
                        case 't':
                                tmp = NULL;
                                if (fstype)
-                                       usage(stderr);
+                                       errx(FSCK_EX_USAGE,
+                                               _("option '%s' may be specified only once"), "-t");
                                if (arg[j+1])
                                        tmp = arg+j+1;
                                else if ((i+1) < argc)
                                        tmp = argv[++i];
                                else
-                                       usage(stderr);
+                                       errx(FSCK_EX_USAGE,
+                                               _("option '%s' requires an argument"), "-t");
                                fstype = xstrdup(tmp);
                                compile_fs_type(fstype, &fs_type_compiled);
                                goto next_arg;
@@ -1550,7 +1563,7 @@ static void parse_argv(int argc, char *argv[])
                                opts_for_fsck++;
                                break;
                        case '?':
-                               usage(stdout);
+                               usage();
                                break;
                        default:
                                options[++opt] = arg[j];