kern_shutdown.c (131481) | kern_shutdown.c (131927) |
---|---|
1/*- 2 * Copyright (c) 1986, 1988, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94 35 */ 36 37#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1986, 1988, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94 35 */ 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/sys/kern/kern_shutdown.c 131481 2004-07-02 20:21:44Z jhb $"); | 38__FBSDID("$FreeBSD: head/sys/kern/kern_shutdown.c 131927 2004-07-10 21:36:01Z marcel $"); |
39 | 39 |
40#include "opt_ddb.h" 41#include "opt_ddb_trace.h" 42#include "opt_ddb_unattended.h" | 40#include "opt_kdb.h" |
43#include "opt_hw_wdog.h" 44#include "opt_mac.h" 45#include "opt_panic.h" 46#include "opt_show_busybufs.h" 47 48#include <sys/param.h> 49#include <sys/systm.h> 50#include <sys/bio.h> 51#include <sys/buf.h> 52#include <sys/conf.h> 53#include <sys/cons.h> 54#include <sys/eventhandler.h> | 41#include "opt_hw_wdog.h" 42#include "opt_mac.h" 43#include "opt_panic.h" 44#include "opt_show_busybufs.h" 45 46#include <sys/param.h> 47#include <sys/systm.h> 48#include <sys/bio.h> 49#include <sys/buf.h> 50#include <sys/conf.h> 51#include <sys/cons.h> 52#include <sys/eventhandler.h> |
53#include <sys/kdb.h> |
|
55#include <sys/kernel.h> 56#include <sys/kthread.h> 57#include <sys/mac.h> 58#include <sys/malloc.h> 59#include <sys/mount.h> 60#include <sys/proc.h> 61#include <sys/reboot.h> 62#include <sys/resourcevar.h> 63#include <sys/smp.h> /* smp_active */ 64#include <sys/sysctl.h> 65#include <sys/sysproto.h> 66#include <sys/vnode.h> 67 68#include <machine/cpu.h> 69#include <machine/pcb.h> 70#include <machine/smp.h> 71 72#include <sys/signalvar.h> | 54#include <sys/kernel.h> 55#include <sys/kthread.h> 56#include <sys/mac.h> 57#include <sys/malloc.h> 58#include <sys/mount.h> 59#include <sys/proc.h> 60#include <sys/reboot.h> 61#include <sys/resourcevar.h> 62#include <sys/smp.h> /* smp_active */ 63#include <sys/sysctl.h> 64#include <sys/sysproto.h> 65#include <sys/vnode.h> 66 67#include <machine/cpu.h> 68#include <machine/pcb.h> 69#include <machine/smp.h> 70 71#include <sys/signalvar.h> |
73#ifdef DDB 74#include <ddb/ddb.h> 75#endif | |
76 77#ifndef PANIC_REBOOT_WAIT_TIME 78#define PANIC_REBOOT_WAIT_TIME 15 /* default to 15 seconds */ 79#endif 80 81/* 82 * Note that stdarg.h and the ANSI style va_start macro is used for both 83 * ANSI and traditional C compilers. 84 */ 85#include <machine/stdarg.h> 86 | 72 73#ifndef PANIC_REBOOT_WAIT_TIME 74#define PANIC_REBOOT_WAIT_TIME 15 /* default to 15 seconds */ 75#endif 76 77/* 78 * Note that stdarg.h and the ANSI style va_start macro is used for both 79 * ANSI and traditional C compilers. 80 */ 81#include <machine/stdarg.h> 82 |
87#ifdef DDB 88#ifdef DDB_UNATTENDED | 83#ifdef KDB 84#ifdef KDB_UNATTENDED |
89int debugger_on_panic = 0; 90#else 91int debugger_on_panic = 1; 92#endif 93SYSCTL_INT(_debug, OID_AUTO, debugger_on_panic, CTLFLAG_RW, 94 &debugger_on_panic, 0, "Run debugger on kernel panic"); 95 | 85int debugger_on_panic = 0; 86#else 87int debugger_on_panic = 1; 88#endif 89SYSCTL_INT(_debug, OID_AUTO, debugger_on_panic, CTLFLAG_RW, 90 &debugger_on_panic, 0, "Run debugger on kernel panic"); 91 |
96#ifdef DDB_TRACE | 92#ifdef KDB_TRACE |
97int trace_on_panic = 1; 98#else 99int trace_on_panic = 0; 100#endif 101SYSCTL_INT(_debug, OID_AUTO, trace_on_panic, CTLFLAG_RW, 102 &trace_on_panic, 0, "Print stack trace on kernel panic"); | 93int trace_on_panic = 1; 94#else 95int trace_on_panic = 0; 96#endif 97SYSCTL_INT(_debug, OID_AUTO, trace_on_panic, CTLFLAG_RW, 98 &trace_on_panic, 0, "Print stack trace on kernel panic"); |
103#endif | 99#endif /* KDB */ |
104 105int sync_on_panic = 1; 106SYSCTL_INT(_kern, OID_AUTO, sync_on_panic, CTLFLAG_RW, 107 &sync_on_panic, 0, "Do a sync before rebooting from a panic"); 108 109SYSCTL_NODE(_kern, OID_AUTO, shutdown, CTLFLAG_RW, 0, "Shutdown environment"); 110 111#ifdef HW_WDOG --- 10 unchanged lines hidden (view full) --- 122/* 123 * Variable panicstr contains argument to first call to panic; used as flag 124 * to indicate that the kernel has already called panic. 125 */ 126const char *panicstr; 127 128int dumping; /* system is dumping */ 129static struct dumperinfo dumper; /* our selected dumper */ | 100 101int sync_on_panic = 1; 102SYSCTL_INT(_kern, OID_AUTO, sync_on_panic, CTLFLAG_RW, 103 &sync_on_panic, 0, "Do a sync before rebooting from a panic"); 104 105SYSCTL_NODE(_kern, OID_AUTO, shutdown, CTLFLAG_RW, 0, "Shutdown environment"); 106 107#ifdef HW_WDOG --- 10 unchanged lines hidden (view full) --- 118/* 119 * Variable panicstr contains argument to first call to panic; used as flag 120 * to indicate that the kernel has already called panic. 121 */ 122const char *panicstr; 123 124int dumping; /* system is dumping */ 125static struct dumperinfo dumper; /* our selected dumper */ |
130static struct pcb dumppcb; /* "You Are Here" sign for dump-debuggers */ | |
131 | 126 |
127/* Context information for dump-debuggers. */ 128static struct pcb dumppcb; /* Registers. */ 129static lwpid_t dumptid; /* Thread ID. */ 130 |
|
132static void boot(int) __dead2; 133static void poweroff_wait(void *, int); 134static void shutdown_halt(void *junk, int howto); 135static void shutdown_panic(void *junk, int howto); 136static void shutdown_reset(void *junk, int howto); 137 138/* register various local shutdown events */ 139static void --- 88 unchanged lines hidden (view full) --- 228 printf("%lds\n", (long)ts.tv_sec); 229} 230 231static void 232doadump(void) 233{ 234 235 savectx(&dumppcb); | 131static void boot(int) __dead2; 132static void poweroff_wait(void *, int); 133static void shutdown_halt(void *junk, int howto); 134static void shutdown_panic(void *junk, int howto); 135static void shutdown_reset(void *junk, int howto); 136 137/* register various local shutdown events */ 138static void --- 88 unchanged lines hidden (view full) --- 227 printf("%lds\n", (long)ts.tv_sec); 228} 229 230static void 231doadump(void) 232{ 233 234 savectx(&dumppcb); |
235 dumptid = curthread->td_tid; |
|
236 dumping++; 237 dumpsys(&dumper); 238} 239 240/* 241 * Go through the rigmarole of shutting down.. 242 * this used to be in machdep.c but I'll be dammned if I could see 243 * anything machine dependant in it. 244 */ 245static void 246boot(int howto) 247{ 248 249 /* collect extra flags that shutdown_nice might have set */ 250 howto |= shutdown_howto; 251 | 236 dumping++; 237 dumpsys(&dumper); 238} 239 240/* 241 * Go through the rigmarole of shutting down.. 242 * this used to be in machdep.c but I'll be dammned if I could see 243 * anything machine dependant in it. 244 */ 245static void 246boot(int howto) 247{ 248 249 /* collect extra flags that shutdown_nice might have set */ 250 howto |= shutdown_howto; 251 |
252#ifdef DDB | |
253 /* We are out of the debugger now. */ | 252 /* We are out of the debugger now. */ |
254 db_active = 0; 255#endif | 253 kdb_active = 0; |
256 257#ifdef SMP 258 if (smp_active) 259 printf("boot() called on cpu#%d\n", PCPU_GET(cpuid)); 260#endif 261 /* 262 * Do any callouts that should be done BEFORE syncing the filesystems. 263 */ --- 188 unchanged lines hidden (view full) --- 452 453 printf("Rebooting...\n"); 454 DELAY(1000000); /* wait 1 sec for printf's to complete and be read */ 455 /* cpu_boot(howto); */ /* doesn't do anything at the moment */ 456 cpu_reset(); 457 /* NOTREACHED */ /* assuming reset worked */ 458} 459 | 254 255#ifdef SMP 256 if (smp_active) 257 printf("boot() called on cpu#%d\n", PCPU_GET(cpuid)); 258#endif 259 /* 260 * Do any callouts that should be done BEFORE syncing the filesystems. 261 */ --- 188 unchanged lines hidden (view full) --- 450 451 printf("Rebooting...\n"); 452 DELAY(1000000); /* wait 1 sec for printf's to complete and be read */ 453 /* cpu_boot(howto); */ /* doesn't do anything at the moment */ 454 cpu_reset(); 455 /* NOTREACHED */ /* assuming reset worked */ 456} 457 |
460/* 461 * Print a backtrace if we can. 462 */ 463 464void 465backtrace(void) 466{ 467 468#ifdef DDB 469 printf("Stack backtrace:\n"); 470 db_print_backtrace(); 471#else 472 printf("Sorry, need DDB option to print backtrace"); 473#endif 474} 475 | |
476#ifdef SMP 477static u_int panic_cpu = NOCPU; 478#endif 479 480/* 481 * Panic is called on unresolvable fatal errors. It prints "panic: mesg", 482 * and then reboots. If we are called twice, then we avoid trying to sync 483 * the disks as this often leads to recursive panics. --- 47 unchanged lines hidden (view full) --- 531 printf("cpuid = %d; ", PCPU_GET(cpuid)); 532#ifdef APIC_IO 533 printf("lapic.id = %08x\n", lapic.id); 534#else 535 printf("\n"); 536#endif 537#endif 538 | 458#ifdef SMP 459static u_int panic_cpu = NOCPU; 460#endif 461 462/* 463 * Panic is called on unresolvable fatal errors. It prints "panic: mesg", 464 * and then reboots. If we are called twice, then we avoid trying to sync 465 * the disks as this often leads to recursive panics. --- 47 unchanged lines hidden (view full) --- 513 printf("cpuid = %d; ", PCPU_GET(cpuid)); 514#ifdef APIC_IO 515 printf("lapic.id = %08x\n", lapic.id); 516#else 517 printf("\n"); 518#endif 519#endif 520 |
539#if defined(DDB) | 521#ifdef KDB |
540 if (newpanic && trace_on_panic) | 522 if (newpanic && trace_on_panic) |
541 backtrace(); | 523 kdb_backtrace(); |
542 if (debugger_on_panic) | 524 if (debugger_on_panic) |
543 Debugger ("panic"); | 525 kdb_enter("panic"); |
544#ifdef RESTARTABLE_PANICS 545 /* See if the user aborted the panic, in which case we continue. */ 546 if (panicstr == NULL) { 547#ifdef SMP 548 atomic_store_rel_int(&panic_cpu, NOCPU); 549#endif 550 return; 551 } --- 84 unchanged lines hidden --- | 526#ifdef RESTARTABLE_PANICS 527 /* See if the user aborted the panic, in which case we continue. */ 528 if (panicstr == NULL) { 529#ifdef SMP 530 atomic_store_rel_int(&panic_cpu, NOCPU); 531#endif 532 return; 533 } --- 84 unchanged lines hidden --- |