]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: support --clear for kmsg
authorKarel Zak <kzak@redhat.com>
Fri, 20 Jul 2012 11:24:42 +0000 (13:24 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 20 Jul 2012 11:24:42 +0000 (13:24 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.c

index 57ba7d26bee8e5e262483a3cf6f8a69a3e55a138..46d1e310622683ad1988e9a01ab0099c106e609d 100644 (file)
@@ -495,6 +495,8 @@ static ssize_t read_buffer(struct dmesg_control *ctl, char **buf)
                 * Since kernel 3.5.0
                 */
                n = read_kmsg(ctl);
+               if (n == 0 && ctl->action == SYSLOG_ACTION_READ_CLEAR)
+                       n = klogctl(SYSLOG_ACTION_CLEAR, NULL, 0);
                break;
        }
 
@@ -769,7 +771,17 @@ 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);
-       return ctl->kmsg < 0 ? -1 : 0;
+       if (ctl->kmsg < 0)
+               return -1;
+
+       /*
+        * Seek after the last record available at the time
+        * the last SYSLOG_ACTION_CLEAR was issued.
+        *
+        * ... otherwise SYSLOG_ACTION_CLEAR will have no effect for kmsg.
+        */
+       lseek(ctl->kmsg, 0, SEEK_DATA);
+       return 0;
 }
 
 /*