[PATCH 4/5] dmesg: inform user when klogctl() or read_buffer() fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fix to small regression which made 'dmesg --clear' not to error
when running without root privileges.  Same happen with '-D' and
few other options as well.

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 sys-utils/dmesg.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 1819c7c..15b9fae 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -985,7 +985,7 @@ static int read_kmsg(struct dmesg_control *ctl)
 int main(int argc, char *argv[])
 {
 	char *buf = NULL;
-	ssize_t  n;
+	ssize_t  n, r;
 	int  c;
 	int  console_level = 0;
 	static struct dmesg_control ctl = {
@@ -1138,6 +1138,7 @@ int main(int argc, char *argv[])
 	argc -= optind;
 	argv += optind;
 	n = 0;
+	r = 0;
 
 	if (argc > 1)
 		usage(stderr);
@@ -1158,9 +1159,9 @@ int main(int argc, char *argv[])
 		if (ctl.method == DMESG_METHOD_KMSG && init_kmsg(&ctl) != 0)
 			ctl.method = DMESG_METHOD_SYSLOG;
 
-		n = read_buffer(&ctl, &buf);
-		if (n > 0)
-			print_buffer(&ctl, buf, n);
+		r = read_buffer(&ctl, &buf);
+		if (r > 0)
+			print_buffer(&ctl, buf, r);
 		if (!ctl.mmap_buff)
 			free(buf);
 		break;
@@ -1180,8 +1181,10 @@ int main(int argc, char *argv[])
 	if (ctl.kmsg >= 0)
 		close(ctl.kmsg);
 
-	if (n < 0 && ctl.method == DMESG_METHOD_SYSLOG)
+	if (n < 0)
 		err(EXIT_FAILURE, _("klogctl failed"));
+	if (r < 0)
+		err(EXIT_FAILURE, _("read_buffer failed"));
 
 	return EXIT_SUCCESS;
 }
-- 
1.7.11.3

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux