kern_shutdown.c (82223) | kern_shutdown.c (82749) |
---|---|
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. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94 | 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. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94 |
39 * $FreeBSD: head/sys/kern/kern_shutdown.c 82223 2001-08-23 20:32:21Z jhb $ | 39 * $FreeBSD: head/sys/kern/kern_shutdown.c 82749 2001-09-01 19:04:37Z dillon $ |
40 */ 41 42#include "opt_ddb.h" 43#include "opt_hw_wdog.h" 44#include "opt_panic.h" 45#include "opt_show_busybufs.h" 46 47#include <sys/param.h> --- 78 unchanged lines hidden (view full) --- 126 EVENTHANDLER_REGISTER(shutdown_final, poweroff_wait, NULL, SHUTDOWN_PRI_FIRST); 127 EVENTHANDLER_REGISTER(shutdown_final, shutdown_halt, NULL, SHUTDOWN_PRI_LAST + 100); 128 EVENTHANDLER_REGISTER(shutdown_final, shutdown_panic, NULL, SHUTDOWN_PRI_LAST + 100); 129 EVENTHANDLER_REGISTER(shutdown_final, shutdown_reset, NULL, SHUTDOWN_PRI_LAST + 200); 130} 131 132SYSINIT(shutdown_conf, SI_SUB_INTRINSIC, SI_ORDER_ANY, shutdown_conf, NULL) 133 | 40 */ 41 42#include "opt_ddb.h" 43#include "opt_hw_wdog.h" 44#include "opt_panic.h" 45#include "opt_show_busybufs.h" 46 47#include <sys/param.h> --- 78 unchanged lines hidden (view full) --- 126 EVENTHANDLER_REGISTER(shutdown_final, poweroff_wait, NULL, SHUTDOWN_PRI_FIRST); 127 EVENTHANDLER_REGISTER(shutdown_final, shutdown_halt, NULL, SHUTDOWN_PRI_LAST + 100); 128 EVENTHANDLER_REGISTER(shutdown_final, shutdown_panic, NULL, SHUTDOWN_PRI_LAST + 100); 129 EVENTHANDLER_REGISTER(shutdown_final, shutdown_reset, NULL, SHUTDOWN_PRI_LAST + 200); 130} 131 132SYSINIT(shutdown_conf, SI_SUB_INTRINSIC, SI_ORDER_ANY, shutdown_conf, NULL) 133 |
134/* ARGSUSED */ 135 | |
136/* 137 * The system call that results in a reboot | 134/* 135 * The system call that results in a reboot |
136 * 137 * MPSAFE |
|
138 */ | 138 */ |
139/* ARGSUSED */ |
|
139int 140reboot(struct proc *p, struct reboot_args *uap) 141{ 142 int error; 143 | 140int 141reboot(struct proc *p, struct reboot_args *uap) 142{ 143 int error; 144 |
144 if ((error = suser(p))) 145 return (error); 146 147 boot(uap->opt); 148 return (0); | 145 mtx_lock(&Giant); 146 if ((error = suser(p)) == 0) { 147 boot(uap->opt); 148 } 149 mtx_unlock(&Giant); 150 return (error); |
149} 150 151/* 152 * Called by events that want to shut down.. e.g <CTL><ALT><DEL> on a PC 153 */ 154static int shutdown_howto = 0; 155 156void --- 403 unchanged lines hidden (view full) --- 560#ifdef SMP 561static u_int panic_cpu = NOCPU; 562#endif 563 564/* 565 * Panic is called on unresolvable fatal errors. It prints "panic: mesg", 566 * and then reboots. If we are called twice, then we avoid trying to sync 567 * the disks as this often leads to recursive panics. | 151} 152 153/* 154 * Called by events that want to shut down.. e.g <CTL><ALT><DEL> on a PC 155 */ 156static int shutdown_howto = 0; 157 158void --- 403 unchanged lines hidden (view full) --- 562#ifdef SMP 563static u_int panic_cpu = NOCPU; 564#endif 565 566/* 567 * Panic is called on unresolvable fatal errors. It prints "panic: mesg", 568 * and then reboots. If we are called twice, then we avoid trying to sync 569 * the disks as this often leads to recursive panics. |
570 * 571 * MPSAFE |
|
568 */ 569void 570panic(const char *fmt, ...) 571{ 572 int bootopt; | 572 */ 573void 574panic(const char *fmt, ...) 575{ 576 int bootopt; |
577 int holding_giant = 0; |
|
573 va_list ap; 574 static char buf[256]; 575 | 578 va_list ap; 579 static char buf[256]; 580 |
581#if 0 582 /* 583 * We must hold Giant when entering a panic 584 */ 585 if (!mtx_owned(&Giant)) { 586 mtx_lock(&Giant); 587 holding_giant = 1; 588 } 589#endif 590 |
|
576#ifdef SMP 577 /* 578 * We don't want multiple CPU's to panic at the same time, so we 579 * use panic_cpu as a simple spinlock. We have to keep checking 580 * panic_cpu if we are spinning in case the panic on the first 581 * CPU is canceled. 582 */ | 591#ifdef SMP 592 /* 593 * We don't want multiple CPU's to panic at the same time, so we 594 * use panic_cpu as a simple spinlock. We have to keep checking 595 * panic_cpu if we are spinning in case the panic on the first 596 * CPU is canceled. 597 */ |
583 if (panic_cpu != PCPU_GET(cpuid)) | 598 if (panic_cpu != PCPU_GET(cpuid)) { |
584 while (atomic_cmpset_int(&panic_cpu, NOCPU, | 599 while (atomic_cmpset_int(&panic_cpu, NOCPU, |
585 PCPU_GET(cpuid)) == 0) | 600 PCPU_GET(cpuid)) == 0) { |
586 while (panic_cpu != NOCPU) 587 ; /* nothing */ | 601 while (panic_cpu != NOCPU) 602 ; /* nothing */ |
603 } 604 } |
|
588#endif 589 590 bootopt = RB_AUTOBOOT | RB_DUMP; 591 if (panicstr) 592 bootopt |= RB_NOSYNC; 593 else 594 panicstr = fmt; 595 --- 15 unchanged lines hidden (view full) --- 611 if (debugger_on_panic) 612 Debugger ("panic"); 613#ifdef RESTARTABLE_PANICS 614 /* See if the user aborted the panic, in which case we continue. */ 615 if (panicstr == NULL) { 616#ifdef SMP 617 atomic_store_rel_int(&panic_cpu, NOCPU); 618#endif | 605#endif 606 607 bootopt = RB_AUTOBOOT | RB_DUMP; 608 if (panicstr) 609 bootopt |= RB_NOSYNC; 610 else 611 panicstr = fmt; 612 --- 15 unchanged lines hidden (view full) --- 628 if (debugger_on_panic) 629 Debugger ("panic"); 630#ifdef RESTARTABLE_PANICS 631 /* See if the user aborted the panic, in which case we continue. */ 632 if (panicstr == NULL) { 633#ifdef SMP 634 atomic_store_rel_int(&panic_cpu, NOCPU); 635#endif |
636 if (holding_giant) 637 mtx_unlock(&Giant); |
|
619 return; 620 } 621#endif 622#endif 623 boot(bootopt); 624} 625 626/* --- 48 unchanged lines hidden --- | 638 return; 639 } 640#endif 641#endif 642 boot(bootopt); 643} 644 645/* --- 48 unchanged lines hidden --- |