svn commit: r320918 - head/sbin/savecore

Mark Johnston markj at freebsd.org
Wed Jul 12 23:41:40 UTC 2017


On Wed, Jul 12, 2017 at 02:23:52PM -0700, John Baldwin wrote:
> On Wednesday, July 12, 2017 06:29:25 PM Mark Johnston wrote:
> > Author: markj
> > Date: Wed Jul 12 18:29:25 2017
> > New Revision: 320918
> > URL: https://svnweb.freebsd.org/changeset/base/320918
> > 
> > Log:
> >   Add a newline after the version string.
> >   
> >   MFC after:	3 days
> 
> I think the version string normally has a trailing \n emedded in it?  

You're right. The problem in my case is that the version string is
getting truncated in mkdumpheader(), and so the trailing \n is omitted.

> Also,
> have you verified that crashinfo is still able to match the Version String
> from the generated info.X file?  I think it might as it stops printing lines
> once it matches the second line of the version, so I think (just reading the
> awk) that it will not include the extra newline in the 'ivers' compared
> against 'version' from gdb.

That's true, but it looks like it doesn't work properly in the truncated
case. What if we declare a match when the version string in the info.X
file matches a prefix of the version string reported by gdb?

diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c
index 22b4793f4ff5..f5862782bb21 100644
--- a/sbin/savecore/savecore.c
+++ b/sbin/savecore/savecore.c
@@ -119,7 +119,7 @@ printheader(xo_handle_t *xo, const struct kerneldumpheader *h, const char *devic
 	xo_emit_h(xo, "{P:  }{Lwc:Dumptime}{:dumptime/%s}", ctime(&t));
 	xo_emit_h(xo, "{P:  }{Lwc:Hostname}{:hostname/%s}\n", h->hostname);
 	xo_emit_h(xo, "{P:  }{Lwc:Magic}{:magic/%s}\n", h->magic);
-	xo_emit_h(xo, "{P:  }{Lwc:Version String}{:version_string/%s}\n", h->versionstring);
+	xo_emit_h(xo, "{P:  }{Lwc:Version String}{:version_string/%s}", h->versionstring);
 	xo_emit_h(xo, "{P:  }{Lwc:Panic String}{:panic_string/%s}\n", h->panicstring);
 	xo_emit_h(xo, "{P:  }{Lwc:Dump Parity}{:dump_parity/%u}\n", h->parity);
 	xo_emit_h(xo, "{P:  }{Lwc:Bounds}{:bounds/%d}\n", bounds);
diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c
index 5c6c0e136769..d87b63461de5 100644
--- a/sys/kern/kern_shutdown.c
+++ b/sys/kern/kern_shutdown.c
@@ -1229,6 +1229,7 @@ void
 mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver,
     uint64_t dumplen, uint32_t dumpkeysize, uint32_t blksz)
 {
+	size_t dstsize;
 
 	bzero(kdh, sizeof(*kdh));
 	strlcpy(kdh->magic, magic, sizeof(kdh->magic));
@@ -1240,7 +1241,9 @@ mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver,
 	kdh->dumpkeysize = htod32(dumpkeysize);
 	kdh->blocksize = htod32(blksz);
 	strlcpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname));
-	strlcpy(kdh->versionstring, version, sizeof(kdh->versionstring));
+	dstsize = sizeof(kdh->versionstring);
+	if (strlcpy(kdh->versionstring, version, dstsize) >= dstsize)
+		kdh->versionstring[dstsize - 2] = '\n';
 	if (panicstr != NULL)
 		strlcpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring));
 	kdh->parity = kerneldump_parity(kdh);
diff --git a/usr.sbin/crashinfo/crashinfo.sh b/usr.sbin/crashinfo/crashinfo.sh
index e52c01419b0d..b3029c6eea4a 100755
--- a/usr.sbin/crashinfo/crashinfo.sh
+++ b/usr.sbin/crashinfo/crashinfo.sh
@@ -85,8 +85,9 @@ find_kernel()
 
 	# Look for a matching kernel version.
 	for k in `sysctl -n kern.bootfile` $(ls -t /boot/*/kernel); do
-		kvers=$(gdb_command $k 'printf "  Version String: %s", version' \
-		     2>/dev/null)
+		kvers=$(gdb_command $k 'printf "  Version String: %s", version' | \
+		    awk "{line=line\$0\"\n\"} END{print substr(line,1,${#ivers})}" \
+		    2>/dev/null)
 		if [ "$ivers" = "$kvers" ]; then
 			KERNEL=$k
 			break


More information about the svn-src-head mailing list