]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: add long options, --help and --version
authorKarel Zak <kzak@redhat.com>
Fri, 1 Jul 2011 11:24:04 +0000 (13:24 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 1 Jul 2011 11:36:11 +0000 (13:36 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.1
sys-utils/dmesg.c

index d7af1dad1073b1556cd0d70dda57eef4b38aeaec..c56bc9e575e1f86cb15b5e3be65c4bdef1be816f 100644 (file)
@@ -5,12 +5,7 @@
 dmesg \- print or control the kernel ring buffer
 .SH SYNOPSIS
 .B dmesg
-.RB [ \-c ]
-.RB [ \-r ]
-.RB [ \-n
-.IR level ]
-.RB [ \-s
-.IR bufsize ]
+.RB [ options ]
 .SH DESCRIPTION
 .B dmesg
 is used to examine or control the kernel ring buffer.
@@ -24,23 +19,11 @@ and mail the
 .I boot.messages
 file to whoever can debug their problem.
 .SH OPTIONS
-.TP
-.B \-c
+.IP "\fB\-c, \-\-read-clear\fP"
 Clear the ring buffer contents after printing.
-.TP
-.B \-r
-Print the raw message buffer, i.e., don't strip the log level prefixes.
-.TP
-.BI \-s " bufsize"
-Use a buffer of size
-.I bufsize
-to query the kernel ring buffer.  This is 16392 by default.
-(The default kernel syslog buffer size was 4096
-at first, 8192 since 1.3.54, 16384 since 2.1.113.)
-If you have set the kernel buffer to be larger than the default
-then this option can be used to view the entire buffer.
-.TP
-.BI \-n " level"
+.IP "\fB\-h, \-\-help\fP"
+Print a help text and exit.
+.IP "\fB\-n, \-\-console-level \fIlevel\fP
 Set the
 .I level
 at which logging of messages is done to the console.  For example,
@@ -58,9 +41,18 @@ option is used,
 will
 .I not
 print or clear the kernel ring buffer.
-
-When both options are used, only the last option on the command line will
-have an effect.
+.IP "\fB\-r, \-\-raw\fP"
+Print the raw message buffer, i.e., don't strip the log level prefixes.
+.IP "\fB\-s, \-\-buffer-size \fIsize\fP
+Use a buffer of
+.I size
+to query the kernel ring buffer.  This is 16392 by default.
+(The default kernel syslog buffer size was 4096
+at first, 8192 since 1.3.54, 16384 since 2.1.113.)
+If you have set the kernel buffer to be larger than the default
+then this option can be used to view the entire buffer.
+.IP "\fB\-V, \-\-version\fP"
+Output version information and exit.
 .SH SEE ALSO
 .BR syslogd (8)
 .\" .SH AUTHOR
index c3e5659c1610dd405ce6a5ebfb63b2d4749dbf18..3d550998a9a7a885f9a0ff3e967a21dfd2e5befe 100644 (file)
 #include "strutils.h"
 #include "xalloc.h"
 
-static void __attribute__ ((noreturn)) usage(void)
+static void __attribute__((__noreturn__)) usage(FILE *out)
 {
-       fprintf(stderr,
-               _("Usage: %s [-c] [-n level] [-r] [-s bufsize]\n"),
-               program_invocation_short_name);
-       exit(EXIT_FAILURE);
-
+       fprintf(out, _(
+               "\nUsage:\n"
+               " %s [options]\n"), program_invocation_short_name);
+
+       fprintf(out, _(
+               "\nOptions:\n"
+               " -c, --read-clear          read and clear all messages\n"
+               " -r, --raw                 print the raw message buffer\n"
+               " -s, --buffer-size=SIZE    buffer size to query the kernel ring buffer\n"
+               " -n, --console-level=LEVEL set level of messages printed to console\n"
+               " -V, --version             output version information and exit\n"
+               " -h, --help                display this help and exit\n\n"));
+
+       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 int main(int argc, char *argv[])
@@ -63,11 +72,21 @@ int main(int argc, char *argv[])
        int  cmd = 3;           /* Read all messages in the ring buffer */
        int  raw = 0;
 
+       static const struct option longopts[] = {
+               { "read-clear",    no_argument,       NULL, 'c' },
+               { "raw",           no_argument,       NULL, 'r' },
+               { "buffer-size",   required_argument, NULL, 's' },
+               { "console-level", required_argument, NULL, 'n' },
+               { "version",       no_argument,       NULL, 'V' },
+               { "help",          no_argument,       NULL, 'h' },
+               { NULL,            0, NULL, 0 }
+       };
+
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
 
-       while ((c = getopt(argc, argv, "crn:s:")) != -1) {
+       while ((c = getopt_long(argc, argv, "chrn:s:V", longopts, NULL)) != -1) {
                switch (c) {
                case 'c':
                        cmd = 4;        /* Read and clear all messages */
@@ -84,16 +103,23 @@ int main(int argc, char *argv[])
                        if (bufsize < 4096)
                                bufsize = 4096;
                        break;
+               case 'V':
+                       printf(_("%s from %s\n"), program_invocation_short_name,
+                                                 PACKAGE_STRING);
+                       return EXIT_SUCCESS;
+               case 'h':
+                       usage(stdout);
+                       break;
                case '?':
                default:
-                       usage();
+                       usage(stderr);
                }
        }
        argc -= optind;
        argv += optind;
 
        if (argc > 1)
-               usage();
+               usage(stderr);
 
        if (cmd == 8) {
                n = klogctl(cmd, NULL, level);