Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Use a scratch space in panic(9) so we can store a m...



details:   https://anonhg.NetBSD.org/src/rev/f94384d73c2d
branches:  trunk
changeset: 769408:f94384d73c2d
user:      jym <jym%NetBSD.org@localhost>
date:      Thu Sep 08 18:15:56 2011 +0000

description:
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@.

diffstat:

 sys/kern/subr_prf.c |  23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diffs (58 lines):

diff -r b0d62e447116 -r f94384d73c2d sys/kern/subr_prf.c
--- a/sys/kern/subr_prf.c       Thu Sep 08 16:34:09 2011 +0000
+++ b/sys/kern/subr_prf.c       Thu Sep 08 18:15:56 2011 +0000
@@ -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);
+       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");
-       va_end(ap);
 
        if (msgbufenabled && msgbufp->msg_magic == MSG_MAGIC)
                panicend = msgbufp->msg_bufx;



Home | Main Index | Thread Index | Old Index