]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: add --human
authorKarel Zak <kzak@redhat.com>
Mon, 18 Mar 2013 11:38:28 +0000 (12:38 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 18 Mar 2013 11:38:28 +0000 (12:38 +0100)
 * enable --reltime
 * enable --color
 * a little bit cleanup main()

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.1
sys-utils/dmesg.c

index 860e556e1f996ba607f0300aa52f989ee3cb7824..b9bdf406e1ca2fd3476eb1b2b32747e390730dd7 100644 (file)
@@ -56,6 +56,8 @@ will print messages from system daemons only.  For all supported facilities
 see
 .B dmesg \-\-help
 output.
+.IP "\fB\-H\fR, \fB\-\-human\fR"
+Enable human readable output.
 .IP "\fB\-h\fR, \fB\-\-help\fR"
 Print a help text and exit.
 .IP "\fB\-k\fR, \fB\-\-kernel\fR"
index 685d415aa86443f03deae75bd8f4bafdf9eff331..4076cf6b563dcbefd847090bf21b46e228c015c9 100644 (file)
@@ -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 <file>           use the file instead of the kernel log buffer\n"), out);
        fputs(_(" -f, --facility <list>       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 <list>          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: