Deleted Added
full compact
kern_shutdown.c (110778) kern_shutdown.c (110859)
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 110778 2003-02-13 01:33:59Z peter $
39 * $FreeBSD: head/sys/kern/kern_shutdown.c 110859 2003-02-14 12:44:48Z alfred $
40 */
41
42#include "opt_ddb.h"
43#include "opt_ddb_trace.h"
44#include "opt_ddb_unattended.h"
45#include "opt_hw_wdog.h"
46#include "opt_mac.h"
47#include "opt_panic.h"

--- 86 unchanged lines hidden (view full) ---

134
135static void boot(int) __dead2;
136static void poweroff_wait(void *, int);
137static void shutdown_halt(void *junk, int howto);
138static void shutdown_panic(void *junk, int howto);
139static void shutdown_reset(void *junk, int howto);
140
141/* register various local shutdown events */
40 */
41
42#include "opt_ddb.h"
43#include "opt_ddb_trace.h"
44#include "opt_ddb_unattended.h"
45#include "opt_hw_wdog.h"
46#include "opt_mac.h"
47#include "opt_panic.h"

--- 86 unchanged lines hidden (view full) ---

134
135static void boot(int) __dead2;
136static void poweroff_wait(void *, int);
137static void shutdown_halt(void *junk, int howto);
138static void shutdown_panic(void *junk, int howto);
139static void shutdown_reset(void *junk, int howto);
140
141/* register various local shutdown events */
142static void
142static void
143shutdown_conf(void *unused)
144{
143shutdown_conf(void *unused)
144{
145 EVENTHANDLER_REGISTER(shutdown_final, poweroff_wait, NULL, SHUTDOWN_PRI_FIRST);
146 EVENTHANDLER_REGISTER(shutdown_final, shutdown_halt, NULL, SHUTDOWN_PRI_LAST + 100);
147 EVENTHANDLER_REGISTER(shutdown_final, shutdown_panic, NULL, SHUTDOWN_PRI_LAST + 100);
148 EVENTHANDLER_REGISTER(shutdown_final, shutdown_reset, NULL, SHUTDOWN_PRI_LAST + 200);
145
146 EVENTHANDLER_REGISTER(shutdown_final, poweroff_wait, NULL,
147 SHUTDOWN_PRI_FIRST);
148 EVENTHANDLER_REGISTER(shutdown_final, shutdown_halt, NULL,
149 SHUTDOWN_PRI_LAST + 100);
150 EVENTHANDLER_REGISTER(shutdown_final, shutdown_panic, NULL,
151 SHUTDOWN_PRI_LAST + 100);
152 EVENTHANDLER_REGISTER(shutdown_final, shutdown_reset, NULL,
153 SHUTDOWN_PRI_LAST + 200);
149}
150
151SYSINIT(shutdown_conf, SI_SUB_INTRINSIC, SI_ORDER_ANY, shutdown_conf, NULL)
152
153/*
154 * The system call that results in a reboot
155 *
156 * MPSAFE

--- 21 unchanged lines hidden (view full) ---

178/*
179 * Called by events that want to shut down.. e.g <CTL><ALT><DEL> on a PC
180 */
181static int shutdown_howto = 0;
182
183void
184shutdown_nice(int howto)
185{
154}
155
156SYSINIT(shutdown_conf, SI_SUB_INTRINSIC, SI_ORDER_ANY, shutdown_conf, NULL)
157
158/*
159 * The system call that results in a reboot
160 *
161 * MPSAFE

--- 21 unchanged lines hidden (view full) ---

183/*
184 * Called by events that want to shut down.. e.g <CTL><ALT><DEL> on a PC
185 */
186static int shutdown_howto = 0;
187
188void
189shutdown_nice(int howto)
190{
191
186 shutdown_howto = howto;
192 shutdown_howto = howto;
187
193
188 /* Send a signal to init(8) and have it shutdown the world */
189 if (initproc != NULL) {
190 PROC_LOCK(initproc);
191 psignal(initproc, SIGINT);
192 PROC_UNLOCK(initproc);
193 } else {
194 /* No init(8) running, so simply reboot */
195 boot(RB_NOSYNC);

--- 27 unchanged lines hidden (view full) ---

223 f = 1;
224 }
225 printf("%lds\n", (long)ts.tv_sec);
226}
227
228static void
229doadump(void)
230{
194 /* Send a signal to init(8) and have it shutdown the world */
195 if (initproc != NULL) {
196 PROC_LOCK(initproc);
197 psignal(initproc, SIGINT);
198 PROC_UNLOCK(initproc);
199 } else {
200 /* No init(8) running, so simply reboot */
201 boot(RB_NOSYNC);

--- 27 unchanged lines hidden (view full) ---

229 f = 1;
230 }
231 printf("%lds\n", (long)ts.tv_sec);
232}
233
234static void
235doadump(void)
236{
237
231 savectx(&dumppcb);
232 dumping++;
233 dumpsys(&dumper);
234}
235
236/*
237 * Go through the rigmarole of shutting down..
238 * this used to be in machdep.c but I'll be dammned if I could see

--- 132 unchanged lines hidden (view full) ---

371}
372
373/*
374 * If the shutdown was a clean halt, behave accordingly.
375 */
376static void
377shutdown_halt(void *junk, int howto)
378{
238 savectx(&dumppcb);
239 dumping++;
240 dumpsys(&dumper);
241}
242
243/*
244 * Go through the rigmarole of shutting down..
245 * this used to be in machdep.c but I'll be dammned if I could see

--- 132 unchanged lines hidden (view full) ---

378}
379
380/*
381 * If the shutdown was a clean halt, behave accordingly.
382 */
383static void
384shutdown_halt(void *junk, int howto)
385{
386
379 if (howto & RB_HALT) {
380 printf("\n");
381 printf("The operating system has halted.\n");
382 printf("Please press any key to reboot.\n\n");
383 switch (cngetc()) {
384 case -1: /* No console, just die */
385 cpu_halt();
386 /* NOTREACHED */

--- 39 unchanged lines hidden (view full) ---

426}
427
428/*
429 * Everything done, now reset
430 */
431static void
432shutdown_reset(void *junk, int howto)
433{
387 if (howto & RB_HALT) {
388 printf("\n");
389 printf("The operating system has halted.\n");
390 printf("Please press any key to reboot.\n\n");
391 switch (cngetc()) {
392 case -1: /* No console, just die */
393 cpu_halt();
394 /* NOTREACHED */

--- 39 unchanged lines hidden (view full) ---

434}
435
436/*
437 * Everything done, now reset
438 */
439static void
440shutdown_reset(void *junk, int howto)
441{
442
434 printf("Rebooting...\n");
435 DELAY(1000000); /* wait 1 sec for printf's to complete and be read */
436 /* cpu_boot(howto); */ /* doesn't do anything at the moment */
437 cpu_reset();
438 /* NOTREACHED */ /* assuming reset worked */
439}
440
441/*
442 * Print a backtrace if we can.
443 */
444
445void
446backtrace(void)
447{
443 printf("Rebooting...\n");
444 DELAY(1000000); /* wait 1 sec for printf's to complete and be read */
445 /* cpu_boot(howto); */ /* doesn't do anything at the moment */
446 cpu_reset();
447 /* NOTREACHED */ /* assuming reset worked */
448}
449
450/*
451 * Print a backtrace if we can.
452 */
453
454void
455backtrace(void)
456{
457
448#ifdef DDB
449 printf("Stack backtrace:\n");
450 db_print_backtrace();
451#else
452 printf("Sorry, need DDB option to print backtrace");
453#endif
454}
455

--- 82 unchanged lines hidden (view full) ---

538#ifndef POWEROFF_DELAY
539# define POWEROFF_DELAY 5000
540#endif
541static int poweroff_delay = POWEROFF_DELAY;
542
543SYSCTL_INT(_kern_shutdown, OID_AUTO, poweroff_delay, CTLFLAG_RW,
544 &poweroff_delay, 0, "");
545
458#ifdef DDB
459 printf("Stack backtrace:\n");
460 db_print_backtrace();
461#else
462 printf("Sorry, need DDB option to print backtrace");
463#endif
464}
465

--- 82 unchanged lines hidden (view full) ---

548#ifndef POWEROFF_DELAY
549# define POWEROFF_DELAY 5000
550#endif
551static int poweroff_delay = POWEROFF_DELAY;
552
553SYSCTL_INT(_kern_shutdown, OID_AUTO, poweroff_delay, CTLFLAG_RW,
554 &poweroff_delay, 0, "");
555
546static void
556static void
547poweroff_wait(void *junk, int howto)
548{
557poweroff_wait(void *junk, int howto)
558{
549 if(!(howto & RB_POWEROFF) || poweroff_delay <= 0)
559
560 if (!(howto & RB_POWEROFF) || poweroff_delay <= 0)
550 return;
551 DELAY(poweroff_delay * 1000);
552}
553
554/*
555 * Some system processes (e.g. syncer) need to be stopped at appropriate
556 * points in their main loops prior to a system shutdown, so that they
557 * won't interfere with the shutdown process (e.g. by holding a disk buf

--- 23 unchanged lines hidden (view full) ---

581 else
582 printf("stopped\n");
583}
584
585/* Registration of dumpers */
586int
587set_dumper(struct dumperinfo *di)
588{
561 return;
562 DELAY(poweroff_delay * 1000);
563}
564
565/*
566 * Some system processes (e.g. syncer) need to be stopped at appropriate
567 * points in their main loops prior to a system shutdown, so that they
568 * won't interfere with the shutdown process (e.g. by holding a disk buf

--- 23 unchanged lines hidden (view full) ---

592 else
593 printf("stopped\n");
594}
595
596/* Registration of dumpers */
597int
598set_dumper(struct dumperinfo *di)
599{
600
589 if (di == NULL) {
590 bzero(&dumper, sizeof dumper);
591 return (0);
592 }
593 if (dumper.dumper != NULL)
594 return (EBUSY);
595 dumper = *di;
596 return (0);
597}
598
599#if defined(__powerpc__)
600void
601dumpsys(struct dumperinfo *di __unused)
602{
603
604 printf("Kernel dumps not implemented on this architecture\n");
605}
606#endif
601 if (di == NULL) {
602 bzero(&dumper, sizeof dumper);
603 return (0);
604 }
605 if (dumper.dumper != NULL)
606 return (EBUSY);
607 dumper = *di;
608 return (0);
609}
610
611#if defined(__powerpc__)
612void
613dumpsys(struct dumperinfo *di __unused)
614{
615
616 printf("Kernel dumps not implemented on this architecture\n");
617}
618#endif