From babf605d2ca969a434f2f14579ddf44252adff4f Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 16 Jun 2013 19:53:50 +0100 Subject: dmesg: add --time-format option Signed-off-by: Sami Kerola --- sys-utils/dmesg.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'sys-utils/dmesg.c') diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 56778360f..2199e7fea 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -257,6 +257,8 @@ static void __attribute__((__noreturn__)) usage(FILE *out) fputs(_(" -u, --userspace display userspace messages\n"), out); fputs(_(" -w, --follow wait for new messages\n"), out); fputs(_(" -x, --decode decode facility and level to readable string\n"), out); + fputs(_(" --time-format show time stamp using format:\n" + " [delta|reltime|ctime|notime]\n"), out); fputs(USAGE_SEPARATOR, out); fputs(USAGE_HELP, out); fputs(USAGE_VERSION, out); @@ -1119,6 +1121,19 @@ static int read_kmsg(struct dmesg_control *ctl) return 0; } +static int which_time_format(const char *optarg) +{ + if (!strcmp(optarg, "notime")) + return DMESG_TIMEFTM_NONE; + if (!strcmp(optarg, "ctime")) + return DMESG_TIMEFTM_CTIME; + if (!strcmp(optarg, "delta")) + return DMESG_TIMEFTM_DELTA; + if (!strcmp(optarg, "reltime")) + return DMESG_TIMEFTM_RELTIME; + errx(EXIT_FAILURE, _("unknown time format: %s"), optarg); +} + #undef is_timefmt #define is_timefmt(c, f) (c.time_fmt == (DMESG_TIMEFTM_ ##f)) int main(int argc, char *argv[]) @@ -1137,6 +1152,9 @@ int main(int argc, char *argv[]) .time_fmt = DMESG_TIMEFTM_TIME, }; int colormode = UL_COLORMODE_NEVER; + enum { + OPT_TIME_FORMAT = CHAR_MAX + 1, + }; static const struct option longopts[] = { { "buffer-size", required_argument, NULL, 's' }, @@ -1163,6 +1181,7 @@ int main(int argc, char *argv[]) { "nopager", no_argument, NULL, 'P' }, { "userspace", no_argument, NULL, 'u' }, { "version", no_argument, NULL, 'V' }, + { "time-format", required_argument, NULL, OPT_TIME_FORMAT }, { NULL, 0, NULL, 0 } }; @@ -1281,6 +1300,9 @@ int main(int argc, char *argv[]) case 'x': ctl.decode = 1; break; + case OPT_TIME_FORMAT: + ctl.time_fmt = which_time_format(optarg); + break; case '?': default: usage(stderr); -- cgit v1.2.3-55-g7522