From f0a3a1caacd002e6890b29e6f7c265c62bfa2e85 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 18 Mar 2013 12:38:28 +0100 Subject: dmesg: add --human * enable --reltime * enable --color * a little bit cleanup main() Signed-off-by: Karel Zak --- sys-utils/dmesg.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'sys-utils/dmesg.c') diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 685d415aa..4076cf6b5 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -232,6 +232,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) fputs(_(" -E, --console-on enable printing messages to console\n"), out); fputs(_(" -F, --file use the file instead of the kernel log buffer\n"), out); fputs(_(" -f, --facility restrict output to defined facilities\n"), out); + fputs(_(" -H, --human human readable output\n"), out); fputs(_(" -k, --kernel display kernel messages\n"), out); fputs(_(" -L, --color colorize messages\n"), out); fputs(_(" -l, --level restrict output to defined levels\n"), out); @@ -1160,6 +1161,7 @@ int main(int argc, char *argv[]) { "file", required_argument, NULL, 'F' }, { "facility", required_argument, NULL, 'f' }, { "follow", no_argument, NULL, 'w' }, + { "human", no_argument, NULL, 'H' }, { "help", no_argument, NULL, 'h' }, { "kernel", no_argument, NULL, 'k' }, { "level", required_argument, NULL, 'l' }, @@ -1177,6 +1179,7 @@ int main(int argc, char *argv[]) static const ul_excl_t excl[] = { /* rows and cols in in ASCII order */ { 'C','D','E','c','n' }, /* clear,off,on,read-clear,level*/ + { 'H','r' }, /* human, raw */ { 'L','r' }, /* color, raw */ { 'S','w' }, /* syslog,follow */ { 0 } @@ -1188,7 +1191,7 @@ int main(int argc, char *argv[]) textdomain(PACKAGE); atexit(close_stdout); - while ((c = getopt_long(argc, argv, "CcDdEeF:f:hkLl:n:rSs:TtuVwx", + while ((c = getopt_long(argc, argv, "CcDdEeF:f:HhkLl:n:rSs:TtuVwx", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -1210,9 +1213,7 @@ int main(int argc, char *argv[]) ctl.action = SYSLOG_ACTION_CONSOLE_ON; break; case 'e': - ctl.boot_time = get_boot_time(); - if (ctl.boot_time) - ctl.reltime = 1; + ctl.reltime = 1; break; case 'F': ctl.filename = optarg; @@ -1224,6 +1225,10 @@ int main(int argc, char *argv[]) ctl.facilities, parse_facility) < 0) return EXIT_FAILURE; break; + case 'H': + ctl.reltime = 1; + ctl.color = 1; + break; case 'h': usage(stdout); break; @@ -1232,8 +1237,7 @@ int main(int argc, char *argv[]) setbit(ctl.facilities, FAC_BASE(LOG_KERN)); break; case 'L': - if (colors_init()) - ctl.color = 1; + ctl.color = 1; break; case 'l': ctl.fltr_lev= 1; @@ -1301,6 +1305,15 @@ int main(int argc, char *argv[]) if (ctl.reltime && ctl.ctime) errx(EXIT_FAILURE, _("--reltime can't be used together with --ctime ")); + if (ctl.reltime) { + ctl.boot_time = get_boot_time(); + if (!ctl.boot_time) + ctl.reltime = 0; + } + + if (ctl.color) + ctl.color = colors_init() ? 1 : 0; + switch (ctl.action) { case SYSLOG_ACTION_READ_ALL: case SYSLOG_ACTION_READ_CLEAR: -- cgit v1.2.3-55-g7522