]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
wdctl: allow to specify more than one device
authorKarel Zak <kzak@redhat.com>
Tue, 22 May 2012 09:39:26 +0000 (11:39 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 22 May 2012 09:48:36 +0000 (11:48 +0200)
 * remove -d <device> option

 * support wdctl [options] [<device> ...] usage

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/wdctl.8
sys-utils/wdctl.c

index 8bb1d5c6c212373685ed4daaaf39a4c83e36d984..081134fec15a3e2cdd6a2f62398ac27ed07ad636 100644 (file)
@@ -9,20 +9,20 @@ show hardware watchdog status
 .SH SYNOPSIS
 .B wdctl
 .RB [options]
-
+.RB [device...]
 .SH DESCRIPTION
-Show hardware watchdog status. Note that number of supported watchdog
-features is hardware specific.
+Show hardware watchdog status. The default device is /dev/watchdog. If more
+than one device is specified then the output is separated by one blank line.
+
+Note that number of supported watchdog features is hardware specific.
 
 .SH OPTIONS
-.IP "\fB\-d, \-\-device \fIpath\fP"
-Device to use, default is /dev/watchdog.
 .IP "\fB\-f, \-\-flags \fI<list>\fP"
 Print selected flags only.
 .IP "\fB\-F, \-\-noflags\fP"
 Don't print information about flags
 .IP "\fB\-n, \-\-noheadings\fP"
-Do not print a header line.
+Do not print a header line for flags table.
 .IP "\fB\-I, \-\-noident\fP"
 Don't print watchdog identity information
 .IP "\fB\-T, \-\-notimeouts\fP"
index 093240e79f2747baa3baef0c5780de7a0cb6c779..ee60e020f9930f87c6a39f36aff64dc3a6624bbb 100644 (file)
@@ -141,28 +141,29 @@ static void usage(FILE *out)
 
        fputs(USAGE_HEADER, out);
        fprintf(out,
-             _(" %s [options]\n"), program_invocation_short_name);
+             _(" %s [options] [<device> ...]\n"), program_invocation_short_name);
 
        fputs(USAGE_OPTIONS, out);
-       fprintf(out,
-             _(" -d, --device <path>   device to use (default is %s)\n"), _PATH_WATCHDOG_DEV);
 
        fputs(_(" -f, --flags <list>    print selected flags only\n"
                " -x, --flags-only      print only flags table (same as -I -T)\n"
                " -F, --noflags         don't print information about flags\n"
-               " -n, --noheadings      don't print headings\n"
+               " -n, --noheadings      don't print headings for flags table\n"
                " -I, --noident         don't print watchdog identity information\n"
                " -T, --notimeouts      don't print watchdog timeouts\n"
                " -o, --output <list>   output columns of the flags\n"
-               " -P, --pairs           use key=\"value\" output format\n"
-               " -r, --raw             use raw output format\n"), out);
+               " -P, --pairs           use key=\"value\" output format for flags table\n"
+               " -r, --raw             use raw output format for flags table\n"), out);
 
        fputs(USAGE_SEPARATOR, out);
        fputs(USAGE_HELP, out);
        fputs(USAGE_VERSION, out);
        fputs(USAGE_SEPARATOR, out);
 
-       fprintf(out, _("\nAvailable columns:\n"));
+       fprintf(out, _("The default device is %s.\n"), _PATH_WATCHDOG_DEV);
+       fputs(USAGE_SEPARATOR, out);
+
+       fputs(_("Available columns:\n"), out);
        for (i = 0; i < ARRAY_SIZE(infos); i++)
                fprintf(out, " %13s  %s\n", infos[i].name, _(infos[i].help));
 
@@ -278,10 +279,10 @@ static int read_watchdog(struct wdinfo *wd)
 
        if (fd < 0) {
                if (errno == EBUSY)
-                       errx(EXIT_FAILURE, _("%s: watchdog already in use, terminating."),
+                       warnx(_("%s: watchdog already in use, terminating."),
                                        wd->device);
-               err(EXIT_FAILURE, _("%s: failed to open watchdog device"),
-                               wd->device);
+               warn(_("%s: open failed"), wd->device);
+               return -1;
        }
 
        if (ioctl(fd, WDIOC_GETSUPPORT, &wd->ident) < 0)
@@ -331,14 +332,12 @@ static void show_timeouts(struct wdinfo *wd)
 
 int main(int argc, char *argv[])
 {
-       struct wdinfo wd = { .device = _PATH_WATCHDOG_DEV };
-
-       int c, tt_flags = 0, rc = 0;
+       struct wdinfo wd;
+       int c, tt_flags = 0, res = EXIT_SUCCESS, count = 0;
        char noflags = 0, noident = 0, notimeouts = 0;
        uint32_t wanted = 0;
 
        static const struct option long_opts[] = {
-               { "device",     required_argument, NULL, 'd' },
                { "flags",      required_argument, NULL, 'f' },
                { "flags-only", no_argument,       NULL, 'x' },
                { "help",       no_argument,       NULL, 'h' },
@@ -361,9 +360,6 @@ int main(int argc, char *argv[])
        while ((c = getopt_long(argc, argv,
                                "d:f:hFnITo:PrVx", long_opts, NULL)) != -1) {
                switch(c) {
-               case 'd':
-                       wd.device = optarg;
-                       break;
                case 'o':
                        ncolumns = string_to_idarray(optarg,
                                                     columns, ARRAY_SIZE(columns),
@@ -420,26 +416,38 @@ int main(int argc, char *argv[])
                columns[ncolumns++] = COL_BSTATUS;
        }
 
-       if (optind < argc)
-               usage(stderr);
+       do {
+               int rc;
 
-       rc = read_watchdog(&wd);
-       if (rc)
-               goto done;
+               memset(&wd, 0, sizeof(wd));
 
-       if (!noident) {
-               printf("%-15s%s\n", _("Device:"), wd.device);
-               printf(_("%-15s%s [version %x]\n"),
-                               ("Identity:"),
-                               wd.ident.identity,
-                               wd.ident.firmware_version);
-       }
-       if (!notimeouts)
-               show_timeouts(&wd);
-       if (!noflags && !(noident && notimeouts))
-               fputc('\n', stdout);
-       if (!noflags)
-               show_flags(&wd, tt_flags, wanted);
-done:
-       return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+               if (optind == argc)
+                       wd.device = _PATH_WATCHDOG_DEV;
+               else
+                       wd.device = argv[optind++];
+
+               if (count)
+                       fputc('\n', stdout);
+               count++;
+
+               rc = read_watchdog(&wd);
+               if (rc) {
+                       res = EXIT_FAILURE;
+                       continue;
+               }
+
+               if (!noident) {
+                       printf("%-15s%s\n", _("Device:"), wd.device);
+                       printf(_("%-15s%s [version %x]\n"),
+                                       ("Identity:"),
+                                       wd.ident.identity,
+                                       wd.ident.firmware_version);
+               }
+               if (!notimeouts)
+                       show_timeouts(&wd);
+               if (!noflags)
+                       show_flags(&wd, tt_flags, wanted);
+       } while (optind < argc);
+
+       return res;
 }