]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
wdctl: remove printing from main()
authorKarel Zak <kzak@redhat.com>
Fri, 31 May 2019 12:25:41 +0000 (14:25 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 17 Jun 2019 13:47:39 +0000 (15:47 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/wdctl.c

index 6b04acd8b33065c2a6fe1f4125eb96e973221fdc..b4f2c6b56e75db9ddaca6517a3a0f9b293e8d8b1 100644 (file)
@@ -420,6 +420,19 @@ static int read_watchdog(struct wd_device *wd)
        return 0;
 }
 
+static void show_timeouts(struct wd_device *wd)
+{
+       if (wd->has_timeout)
+               printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->timeout),
+                         _("Timeout:"), wd->timeout);
+       if (wd->has_pretimeout)
+               printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->pretimeout),
+                         _("Pre-timeout:"), wd->pretimeout);
+       if (wd->has_timeleft)
+               printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->timeleft),
+                         _("Timeleft:"), wd->timeleft);
+}
+
 static void print_oneline(struct wd_control *ctl, struct wd_device *wd, uint32_t wanted)
 {
        printf("%s:", wd->devpath);
@@ -463,17 +476,28 @@ static void print_oneline(struct wd_control *ctl, struct wd_device *wd, uint32_t
        fputc('\n', stdout);
 }
 
-static void show_timeouts(struct wd_device *wd)
+static void print_device(struct wd_control *ctl, struct wd_device *wd, uint32_t wanted)
 {
-       if (wd->has_timeout)
-               printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->timeout),
-                         _("Timeout:"), wd->timeout);
-       if (wd->has_pretimeout)
-               printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->pretimeout),
-                         _("Pre-timeout:"), wd->pretimeout);
-       if (wd->has_timeleft)
-               printf(P_("%-14s %2i second\n", "%-14s %2i seconds\n", wd->timeleft),
-                         _("Timeleft:"), wd->timeleft);
+       /* NAME=value one line output */
+       if (ctl->show_oneline) {
+               print_oneline(ctl, wd, wanted);
+               return;
+       }
+
+       /* pretty output */
+       if (!ctl->hide_ident) {
+               printf("%-15s%s\n", _("Device:"), wd->devpath);
+               printf("%-15s%s [%s %x]\n",
+                               _("Identity:"),
+                               wd->ident.identity,
+                               _("version"),
+                               wd->ident.firmware_version);
+       }
+       if (!ctl->hide_timeouts)
+               show_timeouts(wd);
+
+       if (!ctl->hide_flags)
+               show_flags(ctl, wd, wanted);
 }
 
 int main(int argc, char *argv[])
@@ -598,24 +622,8 @@ int main(int argc, char *argv[])
                        continue;
                }
 
-               if (ctl.show_oneline) {
-                       print_oneline(&ctl, &wd, wanted);
-                       continue;
-               }
+               print_device(&ctl, &wd, wanted);
 
-               /* pretty output */
-               if (!ctl.hide_ident) {
-                       printf("%-15s%s\n", _("Device:"), wd.devpath);
-                       printf("%-15s%s [%s %x]\n",
-                                       _("Identity:"),
-                                       wd.ident.identity,
-                                       _("version"),
-                                       wd.ident.firmware_version);
-               }
-               if (!ctl.hide_timeouts)
-                       show_timeouts(&wd);
-               if (!ctl.hide_flags)
-                       show_flags(&ctl, &wd, wanted);
        } while (optind < argc);
 
        return res;