]> git.ipfire.org Git - thirdparty/util-linux.git/commit
dmesg: fix and cleanup --read-clear
authorKarel Zak <kzak@redhat.com>
Mon, 1 Mar 2021 15:50:20 +0000 (16:50 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 1 Mar 2021 15:50:20 +0000 (16:50 +0100)
commit50cc633257aa0844dd01e9572d6b0ddbfb19f6d5
tree88953b4c19482e20019f1212a3262ce9821b1718
parent66134b5c2bbd22bf69d5afc0f6fbd7b827b37305
dmesg: fix and cleanup --read-clear

The function read_buffer() implements read and clear functionally, but
we do not differentiate between these actions in main() for error
messages, and one generic "dmesg: read kernel buffer failed" is used
in all cases. That's a bug.

This patch removes the "clear" action from read_buffer() and keeps it
for buffer reading only.  The "clear" action is implemented in main()
by separate klogctl(SYSLOG_ACTION_CLEAR) for cases. It means also for
"dmesg --read-clear"; we do not use SYSLOG_ACTION_READ_CLEAR anymore.

Now "clear+read" is:

 * syslog: SYSLOG_ACTION_READ_ALL + SYSLOG_ACTION_CLEAR
 * kmsg:   /dev/kmsg read()       + SYSLOG_ACTION_CLEAR

In old versions "dmesg --syslog --read-clear" (syalog backed) was
implemented by      logctl(SYSLOG_ACTION_READ_CLEAR) and it returns no
data for non-root  users (due to EPERM), "dmesg --read-clear" (kmsg)
returns data and EPERM for the "clear" action.

Now the command "dmesg --syslog --read-clear" and "dmesg --read-clear"
behaves in the same way -- returns data and EPERM for the "clear"
action.

Fixes: https://github.com/karelzak/util-linux/issues/1255
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.c