From: Karel Zak Date: Fri, 20 Jul 2012 11:24:42 +0000 (+0200) Subject: dmesg: support --clear for kmsg X-Git-Tag: v2.22-rc1~115 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c677ffba974b29f6bd61aba161c219b3757bcfc1;p=thirdparty%2Futil-linux.git dmesg: support --clear for kmsg Signed-off-by: Karel Zak --- diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 57ba7d26be..46d1e31062 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -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; } /*