[PATCH 09/15] dmesg: add --time-format option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 sys-utils/dmesg.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 5677836..2199e7f 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 <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);
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux