Module Name:    src
Committed By:   jym
Date:           Thu Sep  8 18:15:56 UTC 2011

Modified Files:
        src/sys/kern: subr_prf.c

Log Message:
Use a scratch space in panic(9) so we can store a more meaningful
message for panicstr instead of just the format string.

Keep setting the panicstr to fmt beforehand though for safety precaution.

ok joerg@.


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/kern/subr_prf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_prf.c
diff -u src/sys/kern/subr_prf.c:1.141 src/sys/kern/subr_prf.c:1.142
--- src/sys/kern/subr_prf.c:1.141	Sun Jul 17 20:54:52 2011
+++ src/sys/kern/subr_prf.c	Thu Sep  8 18:15:56 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_prf.c,v 1.141 2011/07/17 20:54:52 joerg Exp $	*/
+/*	$NetBSD: subr_prf.c,v 1.142 2011/09/08 18:15:56 jym Exp $	*/
 
 /*-
  * Copyright (c) 1986, 1988, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.141 2011/07/17 20:54:52 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.142 2011/09/08 18:15:56 jym Exp $");
 
 #include "opt_ddb.h"
 #include "opt_ipkdb.h"
@@ -203,6 +203,7 @@
 	struct cpu_info *ci, *oci;
 	int bootopt;
 	va_list ap;
+	static char scratchstr[256]; /* stores panic message */
 
 	spldebug_stop();
 
@@ -242,18 +243,26 @@
 	} else
 		printf("Skipping crash dump on recursive panic\n");
 
-	if (!panicstr)
-		panicstr = fmt;
 	doing_shutdown = 1;
 
 	if (msgbufenabled && msgbufp->msg_magic == MSG_MAGIC)
 		panicstart = msgbufp->msg_bufx;
 
-	va_start(ap, fmt);
 	printf("panic: ");
-	vprintf(fmt, ap);
-	printf("\n");
+	if (panicstr == NULL) {
+		/* first time in panic - store fmt first for precaution */
+		panicstr = fmt;
+
+		va_start(ap, fmt);
+		vsnprintf(scratchstr, sizeof(scratchstr), fmt, ap);
+		printf("%s", scratchstr);
+		panicstr = scratchstr;
+	} else {
+		va_start(ap, fmt);
+		vprintf(fmt, ap);
+	}
 	va_end(ap);
+	printf("\n");
 
 	if (msgbufenabled && msgbufp->msg_magic == MSG_MAGIC)
 		panicend = msgbufp->msg_bufx;

Reply via email to