summaryrefslogtreecommitdiffstats
path: root/sys-utils
diff options
context:
space:
mode:
authorKarel Zak2019-05-31 14:25:41 +0200
committerKarel Zak2019-06-17 15:47:39 +0200
commit5d628f37b7423c0047136c81aa7ff3b812fcaed9 (patch)
treed4c058812e57c9f24e856b344d765f96cea67da1 /sys-utils
parentwdctl: add control struct (diff)
downloadkernel-qcow2-util-linux-5d628f37b7423c0047136c81aa7ff3b812fcaed9.tar.gz
kernel-qcow2-util-linux-5d628f37b7423c0047136c81aa7ff3b812fcaed9.tar.xz
kernel-qcow2-util-linux-5d628f37b7423c0047136c81aa7ff3b812fcaed9.zip
wdctl: remove printing from main()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils')
-rw-r--r--sys-utils/wdctl.c62
1 files changed, 35 insertions, 27 deletions
diff --git a/sys-utils/wdctl.c b/sys-utils/wdctl.c
index 6b04acd8b..b4f2c6b56 100644
--- a/sys-utils/wdctl.c
+++ b/sys-utils/wdctl.c
@@ -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;