From 5d628f37b7423c0047136c81aa7ff3b812fcaed9 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 31 May 2019 14:25:41 +0200 Subject: wdctl: remove printing from main() Signed-off-by: Karel Zak --- sys-utils/wdctl.c | 62 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 27 deletions(-) (limited to 'sys-utils') 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; -- cgit v1.2.3-55-g7522