Date: Mon, 16 Mar 2015 21:09:12 +0000 (UTC) From: Ian Lepore <ian@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r280156 - head/sbin/dmesg Message-ID: <201503162109.t2GL9CCK035346@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ian Date: Mon Mar 16 21:09:11 2015 New Revision: 280156 URL: https://svnweb.freebsd.org/changeset/base/280156 Log: Fix minor fallout from sysctl strings being nulterminated now. The dmesg code can read the buffer via sysctl or from a core file. In the core file case there will be no nulterm, and the code copes with that, but now in the sysctl case there is a nulterm (there didn't used to be). The least disruptive way to restore the old behavior (and eliminate a spurious '\000' at the end of the output) is to remove the nulterm (by decrementing the buffer length) in the sysctl case. Modified: head/sbin/dmesg/dmesg.c Modified: head/sbin/dmesg/dmesg.c ============================================================================== --- head/sbin/dmesg/dmesg.c Mon Mar 16 20:24:37 2015 (r280155) +++ head/sbin/dmesg/dmesg.c Mon Mar 16 21:09:11 2015 (r280156) @@ -111,8 +111,10 @@ main(int argc, char *argv[]) if (memf == NULL) { /* - * Running kernel. Use sysctl. This gives an unwrapped - * buffer as a side effect. + * Running kernel. Use sysctl. This gives an unwrapped buffer + * as a side effect. Remove nulterm (if present) so the value + * returned by sysctl is formatted as the rest of the code + * expects (the same as the value read from a core file below). */ if (sysctlbyname("kern.msgbuf", NULL, &buflen, NULL, 0) == -1) err(1, "sysctl kern.msgbuf"); @@ -120,6 +122,8 @@ main(int argc, char *argv[]) errx(1, "malloc failed"); if (sysctlbyname("kern.msgbuf", bp, &buflen, NULL, 0) == -1) err(1, "sysctl kern.msgbuf"); + if (buflen > 0 && bp[buflen - 1] == '\0') + buflen--; if (clear) if (sysctlbyname("kern.msgbuf_clear", NULL, NULL, &clear, sizeof(int))) err(1, "sysctl kern.msgbuf_clear");
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201503162109.t2GL9CCK035346>