]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: add --follow feature
authorKarel Zak <kzak@redhat.com>
Fri, 20 Jul 2012 12:04:48 +0000 (14:04 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 20 Jul 2012 12:04:48 +0000 (14:04 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.1
sys-utils/dmesg.c

index 8e6088e499c33053b828bc145f0b109ed7c064a9..ff149a9e37fdac7b3b5b9f768a5f709608527c33 100644 (file)
@@ -127,6 +127,9 @@ Do not print kernel's timestamps.
 Print userspace messages.
 .IP "\fB\-V\fR, \fB\-\-version\fR"
 Output version information and exit.
+.IP "\fB\-w\fR, \fB\-\-follow\fR"
+Wait for new messages. This feature is supported on systems with readable
+/dev/kmsg only (since kernel 3.5.0).
 .IP "\fB\-x\fR, \fB\-\-decode\fR"
 Decode facility and level (priority) number to human readable prefixes.
 .SH SEE ALSO
index 46d1e310622683ad1988e9a01ab0099c106e609d..319fcd5f8f57403aab118c835ca2bf91bccd6f5c 100644 (file)
@@ -136,7 +136,8 @@ struct dmesg_control {
        char            *mmap_buff;
        size_t          pagesize;
 
-       unsigned int    raw:1,          /* raw mode */
+       unsigned int    follow:1,       /* wait for new messages */
+                       raw:1,          /* raw mode */
                        fltr_lev:1,     /* filter out by levels[] */
                        fltr_fac:1,     /* filter out by facilities[] */
                        decode:1,       /* use "facility: level: " prefix */
@@ -197,6 +198,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
                " -t, --notime                don't print messages timestamp\n"
                " -u, --userspace             display userspace messages\n"
                " -V, --version               output version information and exit\n"
+               " -w, --follow                wait for new messages\n"
                " -x, --decode                decode facility and level to readable string\n"), out);
 
        fputs(_("\nSupported log facilities:\n"), out);
@@ -770,7 +772,12 @@ static void print_buffer(struct dmesg_control *ctl,
 
 static int init_kmsg(struct dmesg_control *ctl)
 {
-       ctl->kmsg = open("/dev/kmsg", O_RDONLY|O_NONBLOCK);
+       int mode = O_RDONLY;
+
+       if (!ctl->follow)
+               mode |= O_NONBLOCK;
+
+       ctl->kmsg = open("/dev/kmsg", mode);
        if (ctl->kmsg < 0)
                return -1;
 
@@ -913,9 +920,11 @@ int main(int argc, char *argv[])
                EXCL_READ_CLEAR,
                EXCL_CONSOLE_LEVEL,
                EXCL_CONSOLE_ON,
-               EXCL_CONSOLE_OFF
+               EXCL_CONSOLE_OFF,
+               EXCL_FOLLOW,
+               EXCL_SYSLOG
        };
-       int excl_any = EXCL_NONE;
+       int excl_any = EXCL_NONE, excl_sys = EXCL_NONE;
 
        static const struct option longopts[] = {
                { "buffer-size",   required_argument, NULL, 's' },
@@ -926,6 +935,7 @@ int main(int argc, char *argv[])
                { "decode",        no_argument,       NULL, 'x' },
                { "file",          required_argument, NULL, 'F' },
                { "facility",      required_argument, NULL, 'f' },
+               { "follow",        no_argument,       NULL, 'w' },
                { "help",          no_argument,       NULL, 'h' },
                { "kernel",        no_argument,       NULL, 'k' },
                { "level",         required_argument, NULL, 'l' },
@@ -945,7 +955,7 @@ int main(int argc, char *argv[])
        textdomain(PACKAGE);
        atexit(close_stdout);
 
-       while ((c = getopt_long(argc, argv, "CcDdEF:f:hkl:n:rSs:TtuVx",
+       while ((c = getopt_long(argc, argv, "CcDdEF:f:hkl:n:rSs:TtuVwx",
                                longopts, NULL)) != -1) {
                switch (c) {
                case 'C':
@@ -999,6 +1009,7 @@ int main(int argc, char *argv[])
                        ctl.raw = 1;
                        break;
                case 'S':
+                       exclusive_option(&excl_sys, EXCL_SYSLOG, "--{syslog,follow}");
                        ctl.method = DMESG_METHOD_SYSLOG;
                        break;
                case 's':
@@ -1024,6 +1035,10 @@ int main(int argc, char *argv[])
                        printf(_("%s from %s\n"), program_invocation_short_name,
                                                  PACKAGE_STRING);
                        return EXIT_SUCCESS;
+               case 'w':
+                       exclusive_option(&excl_sys, EXCL_FOLLOW, "--{syslog,follow}");
+                       ctl.follow = 1;
+                       break;
                case 'x':
                        ctl.decode = 1;
                        break;