1996-08-19 02:19:23 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1986, 1988, 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
* (c) UNIX System Laboratories, Inc.
|
|
|
|
* All or some portions of this file are derived from material licensed
|
|
|
|
* to the University of California by American Telephone and Telegraph
|
|
|
|
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
|
|
|
* the permission of UNIX System Laboratories, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94
|
1999-07-01 22:54:55 +00:00
|
|
|
* $Id: kern_shutdown.c,v 1.53 1999/06/26 02:46:02 mckusick Exp $
|
1996-08-19 02:19:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_ddb.h"
|
1998-02-16 23:57:49 +00:00
|
|
|
#include "opt_hw_wdog.h"
|
1997-08-31 23:08:38 +00:00
|
|
|
#include "opt_panic.h"
|
|
|
|
#include "opt_show_busybufs.h"
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1997-11-18 15:16:43 +00:00
|
|
|
#include <sys/buf.h>
|
1996-08-19 02:19:23 +00:00
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/proc.h>
|
1998-11-13 22:40:37 +00:00
|
|
|
#include <sys/vnode.h>
|
1996-08-19 02:19:23 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
1997-01-16 15:58:32 +00:00
|
|
|
#include <sys/mount.h>
|
1998-09-15 08:49:52 +00:00
|
|
|
#include <sys/queue.h>
|
1996-08-19 02:19:23 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/sysproto.h>
|
|
|
|
|
|
|
|
#include <machine/pcb.h>
|
|
|
|
#include <machine/clock.h>
|
|
|
|
#include <machine/cons.h>
|
|
|
|
#include <machine/md_var.h>
|
1997-06-22 16:04:22 +00:00
|
|
|
#ifdef SMP
|
|
|
|
#include <machine/smp.h> /* smp_active, cpuid */
|
|
|
|
#endif
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
|
|
|
|
#ifndef PANIC_REBOOT_WAIT_TIME
|
|
|
|
#define PANIC_REBOOT_WAIT_TIME 15 /* default to 15 seconds */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that stdarg.h and the ANSI style va_start macro is used for both
|
|
|
|
* ANSI and traditional C compilers.
|
|
|
|
*/
|
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
1997-08-26 00:24:25 +00:00
|
|
|
#ifdef DDB
|
1996-08-19 02:19:23 +00:00
|
|
|
#ifdef DDB_UNATTENDED
|
Improved DDB_UNATTENDED behaviour. From the submitter:
There's something that's been bugging me for a while, so I decided to fix it.
FreeBSD now will DTRT WRT DDB and DDB_UNATTENDED (!debugger_on_panic), at least
in my opinion. The behavior change is such that:
1. Nothing changes when debugger_on_panic != 0.
2. When DDB_UNATTENDED (!debugger_on_panic), if a panic occurs, the
machine will reboot. Also, if a trap occurs, the machine will
panic and reboot, unlike how it broke to DDB before. HOWEVER,
a trap inside DDB will not cause a panic, allowing full use
of DDB without having to worry about the machine being stuck
at a DDB prompt if something goes wrong during the day.
Patches for this behavior follow my signature, and it would
be a boon to anyone (like me) who uses DDB_UNATTENDED, but
actually wants the machine to panic on a trap (otherwise,
what's the use, if the machine causes a fatal trap rather than
a true panic, of debugger_on_panic?). The changes cause no
adverse behavior, but do involve two symbols becoming global
Submitted by: Brian Feldman <green@unixhelp.org>
1998-12-28 23:03:00 +00:00
|
|
|
int debugger_on_panic = 0;
|
1996-08-19 02:19:23 +00:00
|
|
|
#else
|
Improved DDB_UNATTENDED behaviour. From the submitter:
There's something that's been bugging me for a while, so I decided to fix it.
FreeBSD now will DTRT WRT DDB and DDB_UNATTENDED (!debugger_on_panic), at least
in my opinion. The behavior change is such that:
1. Nothing changes when debugger_on_panic != 0.
2. When DDB_UNATTENDED (!debugger_on_panic), if a panic occurs, the
machine will reboot. Also, if a trap occurs, the machine will
panic and reboot, unlike how it broke to DDB before. HOWEVER,
a trap inside DDB will not cause a panic, allowing full use
of DDB without having to worry about the machine being stuck
at a DDB prompt if something goes wrong during the day.
Patches for this behavior follow my signature, and it would
be a boon to anyone (like me) who uses DDB_UNATTENDED, but
actually wants the machine to panic on a trap (otherwise,
what's the use, if the machine causes a fatal trap rather than
a true panic, of debugger_on_panic?). The changes cause no
adverse behavior, but do involve two symbols becoming global
Submitted by: Brian Feldman <green@unixhelp.org>
1998-12-28 23:03:00 +00:00
|
|
|
int debugger_on_panic = 1;
|
1996-08-19 02:19:23 +00:00
|
|
|
#endif
|
|
|
|
SYSCTL_INT(_debug, OID_AUTO, debugger_on_panic, CTLFLAG_RW,
|
1999-05-03 23:57:32 +00:00
|
|
|
&debugger_on_panic, 0, "Run debugger on kernel panic");
|
1996-08-19 02:19:23 +00:00
|
|
|
#endif
|
|
|
|
|
1999-01-30 19:28:30 +00:00
|
|
|
SYSCTL_NODE(_kern, OID_AUTO, shutdown, CTLFLAG_RW, 0, "Shutdown environment");
|
|
|
|
|
1997-08-09 01:44:25 +00:00
|
|
|
#ifdef HW_WDOG
|
1997-08-09 01:25:54 +00:00
|
|
|
/*
|
|
|
|
* If there is a hardware watchdog, point this at the function needed to
|
|
|
|
* hold it off.
|
|
|
|
* It's needed when the kernel needs to do some lengthy operations.
|
|
|
|
* e.g. in wd.c when dumping core.. It's most annoying to have
|
|
|
|
* your precious core-dump only half written because the wdog kicked in.
|
|
|
|
*/
|
|
|
|
watchdog_tickle_fn wdog_tickler = NULL;
|
1997-08-09 01:44:25 +00:00
|
|
|
#endif /* HW_WDOG */
|
1997-08-09 01:25:54 +00:00
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
/*
|
|
|
|
* Variable panicstr contains argument to first call to panic; used as flag
|
|
|
|
* to indicate that the kernel has already called panic.
|
|
|
|
*/
|
|
|
|
const char *panicstr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* callout list for things to do a shutdown
|
|
|
|
*/
|
|
|
|
typedef struct shutdown_list_element {
|
1998-09-15 08:49:52 +00:00
|
|
|
LIST_ENTRY(shutdown_list_element) links;
|
1996-08-19 02:19:23 +00:00
|
|
|
bootlist_fn function;
|
|
|
|
void *arg;
|
1998-10-30 05:41:15 +00:00
|
|
|
int priority;
|
1996-08-19 02:19:23 +00:00
|
|
|
} *sle_p;
|
|
|
|
|
1996-08-22 03:50:33 +00:00
|
|
|
/*
|
1998-09-15 08:49:52 +00:00
|
|
|
* There are three shutdown lists. Some things need to be shut down
|
|
|
|
* earlier than others.
|
1996-08-22 03:50:33 +00:00
|
|
|
*/
|
1998-09-15 08:49:52 +00:00
|
|
|
LIST_HEAD(shutdown_list, shutdown_list_element);
|
|
|
|
|
|
|
|
static struct shutdown_list shutdown_lists[SHUTDOWN_FINAL + 1];
|
1996-08-19 02:19:23 +00:00
|
|
|
|
1997-11-18 15:16:43 +00:00
|
|
|
static void boot __P((int)) __dead2;
|
|
|
|
static void dumpsys __P((void));
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
#ifndef _SYS_SYSPROTO_H_
|
|
|
|
struct reboot_args {
|
|
|
|
int opt;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
/* ARGSUSED */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The system call that results in a reboot
|
|
|
|
*/
|
|
|
|
int
|
1997-11-06 19:29:57 +00:00
|
|
|
reboot(p, uap)
|
1996-08-19 02:19:23 +00:00
|
|
|
struct proc *p;
|
|
|
|
struct reboot_args *uap;
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
1999-04-27 11:18:52 +00:00
|
|
|
if ((error = suser(p)))
|
1996-08-19 02:19:23 +00:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
boot(uap->opt);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by events that want to shut down.. e.g <CTL><ALT><DEL> on a PC
|
|
|
|
*/
|
|
|
|
void
|
1997-08-26 00:24:25 +00:00
|
|
|
shutdown_nice()
|
1996-08-19 02:19:23 +00:00
|
|
|
{
|
|
|
|
/* Send a signal to init(8) and have it shutdown the world */
|
|
|
|
if (initproc != NULL) {
|
|
|
|
psignal(initproc, SIGINT);
|
|
|
|
} else {
|
|
|
|
/* No init(8) running, so simply reboot */
|
|
|
|
boot(RB_NOSYNC);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
static int waittime = -1;
|
|
|
|
static struct pcb dumppcb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go through the rigmarole of shutting down..
|
|
|
|
* this used to be in machdep.c but I'll be dammned if I could see
|
|
|
|
* anything machine dependant in it.
|
|
|
|
*/
|
1997-11-18 15:16:43 +00:00
|
|
|
static void
|
1996-08-19 02:19:23 +00:00
|
|
|
boot(howto)
|
|
|
|
int howto;
|
|
|
|
{
|
1996-08-22 03:50:33 +00:00
|
|
|
sle_p ep;
|
1996-08-19 02:19:23 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
#ifdef SMP
|
|
|
|
if (smp_active) {
|
1997-06-22 16:04:22 +00:00
|
|
|
printf("boot() called on cpu#%d\n", cpuid);
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
1997-08-09 01:25:54 +00:00
|
|
|
/*
|
|
|
|
* Do any callouts that should be done BEFORE syncing the filesystems.
|
|
|
|
*/
|
1998-09-15 08:49:52 +00:00
|
|
|
LIST_FOREACH(ep, &shutdown_lists[SHUTDOWN_PRE_SYNC], links)
|
1996-08-19 02:19:23 +00:00
|
|
|
(*ep->function)(howto, ep->arg);
|
1997-08-09 01:25:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now sync filesystems
|
|
|
|
*/
|
1996-08-19 02:19:23 +00:00
|
|
|
if (!cold && (howto & RB_NOSYNC) == 0 && waittime < 0) {
|
|
|
|
register struct buf *bp;
|
|
|
|
int iter, nbusy;
|
|
|
|
|
|
|
|
waittime = 0;
|
|
|
|
printf("\nsyncing disks... ");
|
|
|
|
|
1997-11-06 19:29:57 +00:00
|
|
|
sync(&proc0, NULL);
|
1996-08-19 02:19:23 +00:00
|
|
|
|
1998-03-08 09:59:44 +00:00
|
|
|
/*
|
|
|
|
* With soft updates, some buffers that are
|
|
|
|
* written will be remarked as dirty until other
|
|
|
|
* buffers are written.
|
|
|
|
*/
|
1996-08-19 02:19:23 +00:00
|
|
|
for (iter = 0; iter < 20; iter++) {
|
|
|
|
nbusy = 0;
|
|
|
|
for (bp = &buf[nbuf]; --bp >= buf; ) {
|
1999-06-26 02:47:16 +00:00
|
|
|
if ((bp->b_flags & B_INVAL) == 0 &&
|
|
|
|
BUF_REFCNT(bp) > 0) {
|
1996-08-19 02:19:23 +00:00
|
|
|
nbusy++;
|
1998-03-08 09:59:44 +00:00
|
|
|
} else if ((bp->b_flags & (B_DELWRI | B_INVAL))
|
|
|
|
== B_DELWRI) {
|
|
|
|
/* bawrite(bp);*/
|
|
|
|
nbusy++;
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nbusy == 0)
|
|
|
|
break;
|
|
|
|
printf("%d ", nbusy);
|
1998-03-08 09:59:44 +00:00
|
|
|
sync(&proc0, NULL);
|
|
|
|
DELAY(50000 * iter);
|
1998-11-13 22:40:37 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Count only busy local buffers to prevent forcing
|
|
|
|
* a fsck if we're just a client of a wedged NFS server
|
|
|
|
*/
|
|
|
|
nbusy = 0;
|
|
|
|
for (bp = &buf[nbuf]; --bp >= buf; ) {
|
1999-06-26 02:47:16 +00:00
|
|
|
if (((bp->b_flags&B_INVAL) == 0 && BUF_REFCNT(bp)) ||
|
|
|
|
((bp->b_flags & (B_DELWRI|B_INVAL)) == B_DELWRI)) {
|
|
|
|
if (bp->b_dev == NODEV)
|
|
|
|
CIRCLEQ_REMOVE(&mountlist,
|
|
|
|
bp->b_vp->v_mount, mnt_list);
|
1998-11-13 22:40:37 +00:00
|
|
|
else
|
|
|
|
nbusy++;
|
1999-05-06 18:13:11 +00:00
|
|
|
}
|
1998-11-13 22:40:37 +00:00
|
|
|
|
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
|
|
|
if (nbusy) {
|
|
|
|
/*
|
|
|
|
* Failed to sync all blocks. Indicate this and don't
|
|
|
|
* unmount filesystems (thus forcing an fsck on reboot).
|
|
|
|
*/
|
|
|
|
printf("giving up\n");
|
|
|
|
#ifdef SHOW_BUSYBUFS
|
|
|
|
nbusy = 0;
|
|
|
|
for (bp = &buf[nbuf]; --bp >= buf; ) {
|
1999-06-26 02:47:16 +00:00
|
|
|
if ((bp->b_flags & B_INVAL) == 0 &&
|
|
|
|
BUF_REFCNT(bp) > 0) {
|
1996-08-19 02:19:23 +00:00
|
|
|
nbusy++;
|
1998-07-11 07:46:16 +00:00
|
|
|
printf(
|
|
|
|
"%d: dev:%08lx, flags:%08lx, blkno:%ld, lblkno:%ld\n",
|
|
|
|
nbusy, (u_long)bp->b_dev,
|
|
|
|
bp->b_flags, (long)bp->b_blkno,
|
|
|
|
(long)bp->b_lblkno);
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DELAY(5000000); /* 5 seconds */
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
printf("done\n");
|
|
|
|
/*
|
|
|
|
* Unmount filesystems
|
|
|
|
*/
|
|
|
|
if (panicstr == 0)
|
|
|
|
vfs_unmountall();
|
|
|
|
}
|
1998-09-15 08:49:52 +00:00
|
|
|
DELAY(100000); /* wait for console output to finish */
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
1997-08-09 01:25:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, now do things that assume all filesystem activity has
|
|
|
|
* been completed.
|
|
|
|
*/
|
1998-09-15 08:49:52 +00:00
|
|
|
LIST_FOREACH(ep, &shutdown_lists[SHUTDOWN_POST_SYNC], links)
|
1996-08-22 03:50:33 +00:00
|
|
|
(*ep->function)(howto, ep->arg);
|
1996-08-19 02:19:23 +00:00
|
|
|
splhigh();
|
1998-09-20 16:50:31 +00:00
|
|
|
if ((howto & (RB_HALT|RB_DUMP)) == RB_DUMP && !cold) {
|
1998-09-15 08:49:52 +00:00
|
|
|
savectx(&dumppcb);
|
|
|
|
#ifdef __i386__
|
|
|
|
dumppcb.pcb_cr3 = rcr3();
|
|
|
|
#endif
|
|
|
|
dumpsys();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now that we're going to really halt the system... */
|
|
|
|
LIST_FOREACH(ep, &shutdown_lists[SHUTDOWN_FINAL], links)
|
|
|
|
(*ep->function)(howto, ep->arg);
|
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
if (howto & RB_HALT) {
|
|
|
|
printf("\n");
|
|
|
|
printf("The operating system has halted.\n");
|
|
|
|
printf("Please press any key to reboot.\n\n");
|
1996-10-31 00:57:28 +00:00
|
|
|
switch (cngetc()) {
|
|
|
|
case -1: /* No console, just die */
|
|
|
|
cpu_halt();
|
|
|
|
/* NOTREACHED */
|
|
|
|
default:
|
1998-09-15 08:49:52 +00:00
|
|
|
howto &= ~RB_HALT;
|
1996-10-31 00:57:28 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-09-15 08:49:52 +00:00
|
|
|
} else if (howto & RB_DUMP) {
|
|
|
|
/* System Paniced */
|
|
|
|
|
|
|
|
if (PANIC_REBOOT_WAIT_TIME != 0) {
|
|
|
|
if (PANIC_REBOOT_WAIT_TIME != -1) {
|
|
|
|
int loop;
|
|
|
|
printf("Automatic reboot in %d seconds - "
|
|
|
|
"press a key on the console to abort\n",
|
|
|
|
PANIC_REBOOT_WAIT_TIME);
|
|
|
|
for (loop = PANIC_REBOOT_WAIT_TIME * 10;
|
|
|
|
loop > 0; --loop) {
|
|
|
|
DELAY(1000 * 100); /* 1/10th second */
|
|
|
|
/* Did user type a key? */
|
|
|
|
if (cncheckc() != -1)
|
|
|
|
break;
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
1998-09-15 08:49:52 +00:00
|
|
|
if (!loop)
|
|
|
|
goto die;
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
1998-09-15 08:49:52 +00:00
|
|
|
} else { /* zero time specified - reboot NOW */
|
|
|
|
goto die;
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
1998-09-15 08:49:52 +00:00
|
|
|
printf("--> Press a key on the console to reboot <--\n");
|
|
|
|
cngetc();
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
|
|
|
die:
|
|
|
|
printf("Rebooting...\n");
|
|
|
|
DELAY(1000000); /* wait 1 sec for printf's to complete and be read */
|
1996-08-19 20:07:07 +00:00
|
|
|
/* cpu_boot(howto); */ /* doesn't do anything at the moment */
|
1996-08-19 02:19:23 +00:00
|
|
|
cpu_reset();
|
|
|
|
for(;;) ;
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Magic number for savecore
|
|
|
|
*
|
|
|
|
* exported (symorder) and used at least by savecore(8)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static u_long const dumpmag = 0x8fca0101UL;
|
|
|
|
|
|
|
|
static int dumpsize = 0; /* also for savecore */
|
|
|
|
|
|
|
|
static int dodump = 1;
|
1999-05-03 23:57:32 +00:00
|
|
|
SYSCTL_INT(_machdep, OID_AUTO, do_dump, CTLFLAG_RW,
|
|
|
|
&dodump, 0, "Do coredump on kernel panic");
|
1996-08-19 02:19:23 +00:00
|
|
|
|
1997-11-25 07:07:48 +00:00
|
|
|
/* ARGSUSED */
|
|
|
|
static void dump_conf __P((void *dummy));
|
|
|
|
static void
|
|
|
|
dump_conf(dummy)
|
|
|
|
void *dummy;
|
|
|
|
{
|
|
|
|
cpu_dumpconf();
|
|
|
|
}
|
|
|
|
SYSINIT(dump_conf, SI_SUB_DUMP_CONF, SI_ORDER_FIRST, dump_conf, NULL)
|
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
/*
|
|
|
|
* Doadump comes here after turning off memory management and
|
|
|
|
* getting on the dump stack, either when called above, or by
|
|
|
|
* the auto-restart code.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
dumpsys(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!dodump)
|
|
|
|
return;
|
|
|
|
if (dumpdev == NODEV)
|
|
|
|
return;
|
1999-05-08 06:40:31 +00:00
|
|
|
if (!(bdevsw(dumpdev)))
|
1996-08-19 02:19:23 +00:00
|
|
|
return;
|
1999-05-08 06:40:31 +00:00
|
|
|
if (!(bdevsw(dumpdev)->d_dump))
|
1996-08-19 02:19:23 +00:00
|
|
|
return;
|
|
|
|
dumpsize = Maxmem;
|
1999-05-12 22:30:50 +00:00
|
|
|
printf("\ndumping to dev (%d,%d), offset %ld\n",
|
|
|
|
major(dumpdev), minor(dumpdev), dumplo);
|
1996-08-19 02:19:23 +00:00
|
|
|
printf("dump ");
|
1999-05-08 06:40:31 +00:00
|
|
|
switch ((*bdevsw(dumpdev)->d_dump)(dumpdev)) {
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
case ENXIO:
|
|
|
|
printf("device bad\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EFAULT:
|
|
|
|
printf("device not ready\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EINVAL:
|
|
|
|
printf("area improper\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EIO:
|
|
|
|
printf("i/o error\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EINTR:
|
|
|
|
printf("aborted from console\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("succeeded\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Panic is called on unresolvable fatal errors. It prints "panic: mesg",
|
|
|
|
* and then reboots. If we are called twice, then we avoid trying to sync
|
|
|
|
* the disks as this often leads to recursive panics.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
panic(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
int bootopt;
|
|
|
|
va_list ap;
|
1998-09-06 06:25:18 +00:00
|
|
|
static char buf[256];
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
bootopt = RB_AUTOBOOT | RB_DUMP;
|
|
|
|
if (panicstr)
|
|
|
|
bootopt |= RB_NOSYNC;
|
|
|
|
else
|
|
|
|
panicstr = fmt;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
1998-12-04 22:54:57 +00:00
|
|
|
(void)vsnprintf(buf, sizeof(buf), fmt, ap);
|
1998-09-06 06:25:18 +00:00
|
|
|
if (panicstr == fmt)
|
|
|
|
panicstr = buf;
|
1996-08-19 02:19:23 +00:00
|
|
|
va_end(ap);
|
1998-09-06 06:25:18 +00:00
|
|
|
printf("panic: %s\n", buf);
|
1997-05-24 18:35:44 +00:00
|
|
|
#ifdef SMP
|
1997-09-05 08:54:55 +00:00
|
|
|
/* three seperate prints in case of an unmapped page and trap */
|
|
|
|
printf("mp_lock = %08x; ", mp_lock);
|
|
|
|
printf("cpuid = %d; ", cpuid);
|
|
|
|
printf("lapic.id = %08x\n", lapic.id);
|
1997-05-24 18:35:44 +00:00
|
|
|
#endif
|
1996-08-19 02:19:23 +00:00
|
|
|
|
|
|
|
#if defined(DDB)
|
|
|
|
if (debugger_on_panic)
|
|
|
|
Debugger ("panic");
|
|
|
|
#endif
|
|
|
|
boot(bootopt);
|
|
|
|
}
|
|
|
|
|
1996-08-22 03:50:33 +00:00
|
|
|
/*
|
1998-10-30 05:41:15 +00:00
|
|
|
* Three routines to handle adding/deleting items on the
|
1996-08-22 03:50:33 +00:00
|
|
|
* shutdown callout lists
|
|
|
|
*
|
|
|
|
* at_shutdown():
|
1996-08-19 02:19:23 +00:00
|
|
|
* Take the arguments given and put them onto the shutdown callout list.
|
|
|
|
* However first make sure that it's not already there.
|
|
|
|
* returns 0 on success.
|
|
|
|
*/
|
|
|
|
int
|
1998-09-15 08:49:52 +00:00
|
|
|
at_shutdown(bootlist_fn function, void *arg, int queue)
|
1996-08-19 02:19:23 +00:00
|
|
|
{
|
1998-10-30 05:41:15 +00:00
|
|
|
return(at_shutdown_pri(function, arg, queue, SHUTDOWN_PRI_DEFAULT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* at_shutdown_pri():
|
|
|
|
* Take the arguments given and put them onto the shutdown callout list
|
|
|
|
* with the given execution priority.
|
|
|
|
* returns 0 on success.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
at_shutdown_pri(bootlist_fn function, void *arg, int queue, int pri)
|
|
|
|
{
|
1999-01-30 19:28:30 +00:00
|
|
|
sle_p op, ep, ip;
|
1996-08-22 03:50:33 +00:00
|
|
|
|
1999-07-01 22:54:55 +00:00
|
|
|
op = NULL; /* shut up gcc */
|
1998-09-15 08:49:52 +00:00
|
|
|
if (queue < SHUTDOWN_PRE_SYNC
|
|
|
|
|| queue > SHUTDOWN_FINAL) {
|
|
|
|
printf("at_shutdown: bad exit callout queue %d specified\n",
|
|
|
|
queue);
|
1996-08-22 03:50:33 +00:00
|
|
|
return (EINVAL);
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
1996-08-22 03:50:33 +00:00
|
|
|
if (rm_at_shutdown(function, arg))
|
1998-09-15 08:49:52 +00:00
|
|
|
printf("at_shutdown: exit callout entry was already present\n");
|
1996-08-22 03:50:33 +00:00
|
|
|
ep = malloc(sizeof(*ep), M_TEMP, M_NOWAIT);
|
|
|
|
if (ep == NULL)
|
|
|
|
return (ENOMEM);
|
1996-08-19 02:19:23 +00:00
|
|
|
ep->function = function;
|
|
|
|
ep->arg = arg;
|
1998-10-30 05:41:15 +00:00
|
|
|
ep->priority = pri;
|
|
|
|
|
|
|
|
/* Sort into list of items on this queue */
|
|
|
|
ip = LIST_FIRST(&shutdown_lists[queue]);
|
|
|
|
if (ip == NULL) {
|
|
|
|
LIST_INSERT_HEAD(&shutdown_lists[queue], ep, links);
|
|
|
|
} else {
|
1999-01-30 19:28:30 +00:00
|
|
|
for (; ip != NULL; op = ip, ip = LIST_NEXT(ip, links)) {
|
1998-10-30 05:41:15 +00:00
|
|
|
if (ep->priority < ip->priority) {
|
|
|
|
LIST_INSERT_BEFORE(ip, ep, links);
|
|
|
|
ep = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ep != NULL)
|
1999-01-30 19:28:30 +00:00
|
|
|
LIST_INSERT_AFTER(op, ep, links);
|
1998-10-30 05:41:15 +00:00
|
|
|
}
|
1996-08-22 03:50:33 +00:00
|
|
|
return (0);
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
1996-08-22 03:50:33 +00:00
|
|
|
|
1996-08-19 02:19:23 +00:00
|
|
|
/*
|
1996-08-22 03:50:33 +00:00
|
|
|
* Scan the exit callout lists for the given items and remove them.
|
1996-08-19 02:19:23 +00:00
|
|
|
* Returns the number of items removed.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
rm_at_shutdown(bootlist_fn function, void *arg)
|
|
|
|
{
|
1998-09-15 08:49:52 +00:00
|
|
|
sle_p ep;
|
|
|
|
int count;
|
|
|
|
int queue;
|
1996-08-19 02:19:23 +00:00
|
|
|
|
1996-08-22 03:50:33 +00:00
|
|
|
count = 0;
|
1998-09-15 08:49:52 +00:00
|
|
|
for (queue = SHUTDOWN_PRE_SYNC; queue < SHUTDOWN_FINAL; queue++) {
|
|
|
|
LIST_FOREACH(ep, &shutdown_lists[queue], links) {
|
|
|
|
if ((ep->function == function) && (ep->arg == arg)) {
|
|
|
|
LIST_REMOVE(ep, links);
|
|
|
|
free(ep, M_TEMP);
|
|
|
|
count++;
|
|
|
|
}
|
1996-08-22 03:50:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (count);
|
1996-08-19 02:19:23 +00:00
|
|
|
}
|
1999-01-30 19:28:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Support for poweroff delay.
|
|
|
|
*/
|
|
|
|
static int poweroff_delay = 0;
|
|
|
|
SYSCTL_INT(_kern_shutdown, OID_AUTO, poweroff_delay, CTLFLAG_RW,
|
|
|
|
&poweroff_delay, 0, "");
|
|
|
|
|
|
|
|
static void poweroff_wait(int howto, void *unused)
|
|
|
|
{
|
|
|
|
if(!(howto & RB_POWEROFF) || poweroff_delay <= 0)
|
|
|
|
return;
|
|
|
|
DELAY(poweroff_delay * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX OK? This implies I know SHUTDOWN_PRI_LAST > SHUTDOWN_PRI_FIRST
|
|
|
|
*/
|
|
|
|
static void poweroff_conf(void *unused)
|
|
|
|
{
|
|
|
|
at_shutdown_pri(poweroff_wait, NULL, SHUTDOWN_FINAL, SHUTDOWN_PRI_FIRST);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(poweroff_conf, SI_SUB_INTRINSIC, SI_ORDER_ANY, poweroff_conf, NULL)
|