1 /*
2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * File: bsd/kern/kern_shutdown.c
30 *
31 * Copyright (C) 1989, NeXT, Inc.
32 *
33 */
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/vm.h>
39 #include <sys/proc_internal.h>
40 #include <sys/user.h>
41 #include <sys/reboot.h>
42 #include <sys/conf.h>
43 #include <sys/vnode_internal.h>
44 #include <sys/file_internal.h>
45 #include <sys/mbuf.h>
46 #include <sys/msgbuf.h>
47 #include <sys/ioctl.h>
48 #include <sys/signal.h>
49 #include <sys/tty.h>
50 #include <kern/task.h>
51 #include <sys/quota.h>
52 #include <vm/vm_kern.h>
53 #include <mach/vm_param.h>
54 #include <sys/filedesc.h>
55 #include <mach/host_priv.h>
56 #include <mach/host_reboot.h>
57
58 #include <security/audit/audit.h>
59
60 #include <kern/sched_prim.h> /* for thread_block() */
61 #include <kern/host.h> /* for host_priv_self() */
62 #include <net/if_var.h> /* for if_down_all() */
63 #include <sys/buf_internal.h> /* for count_busy_buffers() */
64 #include <sys/mount_internal.h> /* for vfs_unmountall() */
65 #include <mach/task.h> /* for task_suspend() */
66 #include <sys/sysproto.h> /* abused for sync() */
67 #include <kern/clock.h> /* for delay_for_interval() */
68 #include <libkern/OSAtomic.h>
69 #include <IOKit/IOPlatformExpert.h>
70 #include <IOKit/IOMessage.h>
71
72 #include <sys/kdebug.h>
73
74 uint32_t system_inshutdown = 0;
75
76 #if XNU_TARGET_OS_OSX
77 /* XXX should be in a header file somewhere, but isn't */
78 extern void (*unmountroot_pre_hook)(void);
79 #endif
80
81 unsigned int proc_shutdown_exitcount = 0;
82
83 static int sd_openlog(vfs_context_t);
84 static int sd_closelog(vfs_context_t);
85 static void sd_log(vfs_context_t, const char *, ...);
86 static void proc_shutdown(int only_non_dext);
87 static void zprint_panic_info(void);
88 extern void halt_log_enter(const char * what, const void * pc, uint64_t time);
89
90 #if DEVELOPMENT || DEBUG
91 extern boolean_t kdp_has_polled_corefile(void);
92 #endif /* DEVELOPMENT || DEBUG */
93
94 struct sd_filterargs {
95 int delayterm;
96 int shutdownstate;
97 int only_non_dext;
98 };
99
100
101 struct sd_iterargs {
102 int signo; /* the signal to be posted */
103 int setsdstate; /* shutdown state to be set */
104 int countproc; /* count processes on action */
105 int activecount; /* number of processes on which action was done */
106 };
107
108 static vnode_t sd_logvp = NULLVP;
109 static off_t sd_log_offset = 0;
110
111
112 static int sd_filt1(proc_t, void *);
113 static int sd_filt2(proc_t, void *);
114 static int sd_callback1(proc_t p, void * arg);
115 static int sd_callback2(proc_t p, void * arg);
116 static int sd_callback3(proc_t p, void * arg);
117
118 extern bool panic_include_zprint;
119 extern mach_memory_info_t *panic_kext_memory_info;
120 extern vm_size_t panic_kext_memory_size;
121
122 static void
zprint_panic_info(void)123 zprint_panic_info(void)
124 {
125 unsigned int num_sites;
126 kern_return_t kr;
127
128 panic_include_zprint = true;
129 panic_kext_memory_info = NULL;
130 panic_kext_memory_size = 0;
131
132 num_sites = vm_page_diagnose_estimate();
133 panic_kext_memory_size = num_sites * sizeof(panic_kext_memory_info[0]);
134
135 kr = kmem_alloc(kernel_map, (vm_offset_t *)&panic_kext_memory_info, round_page(panic_kext_memory_size), VM_KERN_MEMORY_OSFMK);
136 if (kr != KERN_SUCCESS) {
137 panic_kext_memory_info = NULL;
138 return;
139 }
140
141 vm_page_diagnose(panic_kext_memory_info, num_sites, 0);
142 }
143
144 int
get_system_inshutdown()145 get_system_inshutdown()
146 {
147 return system_inshutdown;
148 }
149
150 __abortlike
151 static void
panic_kernel(int howto,char * message)152 panic_kernel(int howto, char *message)
153 {
154 if ((howto & RB_PANIC_ZPRINT) == RB_PANIC_ZPRINT) {
155 zprint_panic_info();
156 }
157 panic("userspace panic: %s", message);
158 }
159
160 extern boolean_t compressor_store_stop_compaction;
161 extern lck_mtx_t vm_swap_data_lock;
162 extern int vm_swapfile_create_thread_running;
163 extern int vm_swapfile_gc_thread_running;
164 extern uint32_t cl_sparse_push_error;
165
166 int
reboot_kernel(int howto,char * message)167 reboot_kernel(int howto, char *message)
168 {
169 int hostboot_option = 0;
170 uint64_t startTime;
171
172 if ((howto & (RB_PANIC | RB_QUICK)) == (RB_PANIC | RB_QUICK)) {
173 panic_kernel(howto, message);
174 }
175
176 if (!OSCompareAndSwap(0, 1, &system_inshutdown)) {
177 if ((howto & RB_QUICK) == RB_QUICK) {
178 goto force_reboot;
179 }
180 return EBUSY;
181 }
182
183 lck_mtx_lock(&vm_swap_data_lock);
184
185 /* Turn OFF future swapfile reclaimation / compaction etc.*/
186 compressor_store_stop_compaction = TRUE;
187
188 /* wait for any current swapfile work to end */
189 while (vm_swapfile_create_thread_running || vm_swapfile_gc_thread_running) {
190 assert_wait((event_t)&compressor_store_stop_compaction, THREAD_UNINT);
191
192 lck_mtx_unlock(&vm_swap_data_lock);
193
194 thread_block(THREAD_CONTINUE_NULL);
195
196 lck_mtx_lock(&vm_swap_data_lock);
197 }
198
199 lck_mtx_unlock(&vm_swap_data_lock);
200
201 /*
202 * Notify the power management root domain that the system will shut down.
203 */
204 IOSystemShutdownNotification(howto, kIOSystemShutdownNotificationStageProcessExit);
205
206 if ((howto & RB_QUICK) == RB_QUICK) {
207 printf("Quick reboot...\n");
208 if ((howto & RB_NOSYNC) == 0) {
209 sync((proc_t)NULL, (void *)NULL, (int *)NULL);
210 }
211 } else if ((howto & RB_NOSYNC) == 0) {
212 int iter, nbusy;
213
214 printf("syncing disks... ");
215
216 /*
217 * Release vnodes held by texts before sync.
218 */
219
220 /* handle live procs (deallocate their root and current directories), suspend initproc */
221
222 startTime = mach_absolute_time();
223 proc_shutdown(TRUE);
224 halt_log_enter("proc_shutdown", 0, mach_absolute_time() - startTime);
225
226 #if CONFIG_AUDIT
227 startTime = mach_absolute_time();
228 audit_shutdown();
229 halt_log_enter("audit_shutdown", 0, mach_absolute_time() - startTime);
230 #endif
231
232 #if XNU_TARGET_OS_OSX
233 if (unmountroot_pre_hook != NULL) {
234 unmountroot_pre_hook();
235 }
236 #endif
237
238 startTime = mach_absolute_time();
239 sync((proc_t)NULL, (void *)NULL, (int *)NULL);
240
241 if (kdebug_enable) {
242 startTime = mach_absolute_time();
243 kdbg_dump_trace_to_file("/var/log/shutdown/shutdown.trace", true);
244 halt_log_enter("shutdown.trace", 0, mach_absolute_time() - startTime);
245 }
246
247 IOSystemShutdownNotification(howto, kIOSystemShutdownNotificationStageRootUnmount);
248
249 if (cl_sparse_push_error) {
250 panic("system_shutdown cluster_push_err failed with ENOSPC %d times\n", cl_sparse_push_error);
251 }
252
253 /*
254 * Unmount filesystems
255 */
256
257 #if DEVELOPMENT || DEBUG
258 if (!(howto & RB_PANIC) || !kdp_has_polled_corefile())
259 #endif /* DEVELOPMENT || DEBUG */
260 {
261 startTime = mach_absolute_time();
262 vfs_unmountall(TRUE);
263 halt_log_enter("vfs_unmountall", 0, mach_absolute_time() - startTime);
264 }
265
266 IOSystemShutdownNotification(howto, kIOSystemShutdownNotificationTerminateDEXTs);
267
268 startTime = mach_absolute_time();
269 proc_shutdown(FALSE);
270 halt_log_enter("proc_shutdown", 0, mach_absolute_time() - startTime);
271
272 #if DEVELOPMENT || DEBUG
273 if (!(howto & RB_PANIC) || !kdp_has_polled_corefile())
274 #endif /* DEVELOPMENT || DEBUG */
275 {
276 startTime = mach_absolute_time();
277 vfs_unmountall(FALSE);
278 halt_log_enter("vfs_unmountall", 0, mach_absolute_time() - startTime);
279 }
280
281
282
283 /* Wait for the buffer cache to clean remaining dirty buffers */
284 startTime = mach_absolute_time();
285 for (iter = 0; iter < 100; iter++) {
286 nbusy = count_busy_buffers();
287 if (nbusy == 0) {
288 break;
289 }
290 printf("%d ", nbusy);
291 delay_for_interval( 1 * nbusy, 1000 * 1000);
292 }
293 if (nbusy) {
294 printf("giving up\n");
295 } else {
296 printf("done\n");
297 }
298 halt_log_enter("bufferclean", 0, mach_absolute_time() - startTime);
299 }
300 #if NETWORKING
301 /*
302 * Can't just use an splnet() here to disable the network
303 * because that will lock out softints which the disk
304 * drivers depend on to finish DMAs.
305 */
306 startTime = mach_absolute_time();
307 if_down_all();
308 halt_log_enter("if_down_all", 0, mach_absolute_time() - startTime);
309 #endif /* NETWORKING */
310
311 force_reboot:
312
313 if (howto & RB_PANIC) {
314 panic_kernel(howto, message);
315 }
316
317 if (howto & RB_HALT) {
318 hostboot_option = HOST_REBOOT_HALT;
319 }
320
321 if (howto & RB_UPSDELAY) {
322 hostboot_option = HOST_REBOOT_UPSDELAY;
323 }
324
325 host_reboot(host_priv_self(), hostboot_option);
326 /*
327 * should not be reached
328 */
329 return 0;
330 }
331
332 static int
sd_openlog(vfs_context_t ctx)333 sd_openlog(vfs_context_t ctx)
334 {
335 int error = 0;
336 struct timeval tv;
337
338 /* Open shutdown log */
339 if ((error = vnode_open(PROC_SHUTDOWN_LOG, (O_CREAT | FWRITE | O_NOFOLLOW), 0644, 0, &sd_logvp, ctx))) {
340 printf("Failed to open %s: error %d\n", PROC_SHUTDOWN_LOG, error);
341 sd_logvp = NULLVP;
342 return error;
343 }
344
345 vnode_setsize(sd_logvp, (off_t)0, 0, ctx);
346
347 /* Write a little header */
348 microtime(&tv);
349 sd_log(ctx, "Process shutdown log. Current time is %lu (in seconds).\n\n", tv.tv_sec);
350
351 return 0;
352 }
353
354 static int
sd_closelog(vfs_context_t ctx)355 sd_closelog(vfs_context_t ctx)
356 {
357 int error = 0;
358 if (sd_logvp != NULLVP) {
359 VNOP_FSYNC(sd_logvp, MNT_WAIT, ctx);
360 error = vnode_close(sd_logvp, FWRITE, ctx);
361 sd_logvp = NULLVP;
362 }
363
364 return error;
365 }
366
367 __printflike(2, 3)
368 static void
sd_log(vfs_context_t ctx,const char * fmt,...)369 sd_log(vfs_context_t ctx, const char *fmt, ...)
370 {
371 int resid, log_error, len;
372 char logbuf[100];
373 va_list arglist;
374
375 /* If the log isn't open yet, open it */
376 if (sd_logvp == NULLVP) {
377 if (sd_openlog(ctx) != 0) {
378 /* Couldn't open, we fail out */
379 return;
380 }
381 }
382
383 va_start(arglist, fmt);
384 len = vsnprintf(logbuf, sizeof(logbuf), fmt, arglist);
385 log_error = vn_rdwr(UIO_WRITE, sd_logvp, (caddr_t)logbuf, len, sd_log_offset,
386 UIO_SYSSPACE, IO_UNIT | IO_NOAUTH, vfs_context_ucred(ctx), &resid, vfs_context_proc(ctx));
387 if (log_error == EIO || log_error == 0) {
388 sd_log_offset += (len - resid);
389 }
390
391 va_end(arglist);
392 }
393
394 #define proc_is_driver(p) (task_is_driver((p)->task))
395
396 static int
sd_filt1(proc_t p,void * args)397 sd_filt1(proc_t p, void * args)
398 {
399 proc_t self = current_proc();
400 struct sd_filterargs * sf = (struct sd_filterargs *)args;
401 int delayterm = sf->delayterm;
402 int shutdownstate = sf->shutdownstate;
403
404 if (sf->only_non_dext && proc_is_driver(p)) {
405 return 0;
406 }
407
408 if (((p->p_flag & P_SYSTEM) != 0) || (p->p_ppid == 0)
409 || (p == self) || (p->p_stat == SZOMB)
410 || (p->p_shutdownstate != shutdownstate)
411 || ((delayterm == 0) && ((p->p_lflag & P_LDELAYTERM) == P_LDELAYTERM))
412 || ((p->p_sigcatch & sigmask(SIGTERM)) == 0)) {
413 return 0;
414 } else {
415 return 1;
416 }
417 }
418
419
420 static int
sd_callback1(proc_t p,void * args)421 sd_callback1(proc_t p, void * args)
422 {
423 struct sd_iterargs * sd = (struct sd_iterargs *)args;
424 int signo = sd->signo;
425 int setsdstate = sd->setsdstate;
426 int countproc = sd->countproc;
427
428 proc_lock(p);
429 p->p_shutdownstate = (char)setsdstate;
430 if (p->p_stat != SZOMB) {
431 proc_unlock(p);
432 if (countproc != 0) {
433 proc_list_lock();
434 p->p_listflag |= P_LIST_EXITCOUNT;
435 proc_shutdown_exitcount++;
436 proc_list_unlock();
437 }
438 if (proc_is_driver(p)) {
439 printf("lingering dext %s signal(%d)\n", p->p_name, signo);
440 }
441 psignal(p, signo);
442 if (countproc != 0) {
443 sd->activecount++;
444 }
445 } else {
446 proc_unlock(p);
447 }
448
449 return PROC_RETURNED;
450 }
451
452 static int
sd_filt2(proc_t p,void * args)453 sd_filt2(proc_t p, void * args)
454 {
455 proc_t self = current_proc();
456 struct sd_filterargs * sf = (struct sd_filterargs *)args;
457 int delayterm = sf->delayterm;
458 int shutdownstate = sf->shutdownstate;
459
460 if (sf->only_non_dext && proc_is_driver(p)) {
461 return 0;
462 }
463
464 if (((p->p_flag & P_SYSTEM) != 0) || (p->p_ppid == 0)
465 || (p == self) || (p->p_stat == SZOMB)
466 || (p->p_shutdownstate == shutdownstate)
467 || ((delayterm == 0) && ((p->p_lflag & P_LDELAYTERM) == P_LDELAYTERM))) {
468 return 0;
469 } else {
470 return 1;
471 }
472 }
473
474 static int
sd_callback2(proc_t p,void * args)475 sd_callback2(proc_t p, void * args)
476 {
477 struct sd_iterargs * sd = (struct sd_iterargs *)args;
478 int signo = sd->signo;
479 int setsdstate = sd->setsdstate;
480 int countproc = sd->countproc;
481
482 proc_lock(p);
483 p->p_shutdownstate = (char)setsdstate;
484 if (p->p_stat != SZOMB) {
485 proc_unlock(p);
486 if (countproc != 0) {
487 proc_list_lock();
488 p->p_listflag |= P_LIST_EXITCOUNT;
489 proc_shutdown_exitcount++;
490 proc_list_unlock();
491 }
492 if (proc_is_driver(p)) {
493 printf("lingering dext %s signal(%d)\n", p->p_name, signo);
494 }
495 psignal(p, signo);
496 if (countproc != 0) {
497 sd->activecount++;
498 }
499 } else {
500 proc_unlock(p);
501 }
502
503 return PROC_RETURNED;
504 }
505
506 static int
sd_callback3(proc_t p,void * args)507 sd_callback3(proc_t p, void * args)
508 {
509 struct sd_iterargs * sd = (struct sd_iterargs *)args;
510 vfs_context_t ctx = vfs_context_current();
511
512 int setsdstate = sd->setsdstate;
513
514 proc_lock(p);
515 p->p_shutdownstate = (char)setsdstate;
516 if (p->p_stat != SZOMB) {
517 /*
518 * NOTE: following code ignores sig_lock and plays
519 * with exit_thread correctly. This is OK unless we
520 * are a multiprocessor, in which case I do not
521 * understand the sig_lock. This needs to be fixed.
522 * XXX
523 */
524 if (p->exit_thread) { /* someone already doing it */
525 proc_unlock(p);
526 /* give him a chance */
527 thread_block(THREAD_CONTINUE_NULL);
528 } else {
529 p->exit_thread = current_thread();
530 printf(".");
531
532 sd_log(ctx, "%s[%d] had to be forced closed with exit1().\n", p->p_comm, proc_getpid(p));
533
534 proc_unlock(p);
535 KERNEL_DEBUG_CONSTANT(BSDDBG_CODE(DBG_BSD_PROC, BSD_PROC_FRCEXIT) | DBG_FUNC_NONE,
536 proc_getpid(p), 0, 1, 0, 0);
537 sd->activecount++;
538 exit1(p, 1, (int *)NULL);
539 }
540 } else {
541 proc_unlock(p);
542 }
543
544 return PROC_RETURNED;
545 }
546
547
548 /*
549 * proc_shutdown()
550 *
551 * Shutdown down proc system (release references to current and root
552 * dirs for each process).
553 *
554 * POSIX modifications:
555 *
556 * For POSIX fcntl() file locking call vno_lockrelease() on
557 * the file to release all of its record locks, if any.
558 */
559
560 static void
proc_shutdown(int only_non_dext)561 proc_shutdown(int only_non_dext)
562 {
563 vfs_context_t ctx = vfs_context_current();
564 struct proc *p, *self;
565 int delayterm = 0;
566 struct sd_filterargs sfargs;
567 struct sd_iterargs sdargs;
568 int error = 0;
569 struct timespec ts;
570
571 /*
572 * Kill as many procs as we can. (Except ourself...)
573 */
574 self = (struct proc *)current_proc();
575
576 /*
577 * Signal the init with SIGTERM so that he does not launch
578 * new processes
579 */
580 p = proc_find(1);
581 if (p && p != self) {
582 psignal(p, SIGTERM);
583 }
584 proc_rele(p);
585
586 printf("Killing all processes ");
587
588 sigterm_loop:
589 /*
590 * send SIGTERM to those procs interested in catching one
591 */
592 sfargs.delayterm = delayterm;
593 sfargs.shutdownstate = 0;
594 sfargs.only_non_dext = only_non_dext;
595 sdargs.signo = SIGTERM;
596 sdargs.setsdstate = 1;
597 sdargs.countproc = 1;
598 sdargs.activecount = 0;
599
600 error = 0;
601 /* post a SIGTERM to all that catch SIGTERM and not marked for delay */
602 proc_rebootscan(sd_callback1, (void *)&sdargs, sd_filt1, (void *)&sfargs);
603
604 if (sdargs.activecount != 0 && proc_shutdown_exitcount != 0) {
605 proc_list_lock();
606 if (proc_shutdown_exitcount != 0) {
607 /*
608 * now wait for up to 3 seconds to allow those procs catching SIGTERM
609 * to digest it
610 * as soon as these procs have exited, we'll continue on to the next step
611 */
612 ts.tv_sec = 3;
613 ts.tv_nsec = 0;
614 error = msleep(&proc_shutdown_exitcount, &proc_list_mlock, PWAIT, "shutdownwait", &ts);
615 if (error != 0) {
616 for (p = allproc.lh_first; p; p = p->p_list.le_next) {
617 if ((p->p_listflag & P_LIST_EXITCOUNT) == P_LIST_EXITCOUNT) {
618 p->p_listflag &= ~P_LIST_EXITCOUNT;
619 }
620 }
621 for (p = zombproc.lh_first; p; p = p->p_list.le_next) {
622 if ((p->p_listflag & P_LIST_EXITCOUNT) == P_LIST_EXITCOUNT) {
623 p->p_listflag &= ~P_LIST_EXITCOUNT;
624 }
625 }
626 }
627 }
628 proc_list_unlock();
629 }
630 if (error == ETIMEDOUT) {
631 /*
632 * log the names of the unresponsive tasks
633 */
634
635 proc_list_lock();
636
637 for (p = allproc.lh_first; p; p = p->p_list.le_next) {
638 if (p->p_shutdownstate == 1) {
639 printf("%s[%d]: didn't act on SIGTERM\n", p->p_comm, proc_getpid(p));
640 sd_log(ctx, "%s[%d]: didn't act on SIGTERM\n", p->p_comm, proc_getpid(p));
641 }
642 }
643
644 proc_list_unlock();
645 }
646
647 /*
648 * send a SIGKILL to all the procs still hanging around
649 */
650 sfargs.delayterm = delayterm;
651 sfargs.shutdownstate = 2;
652 sdargs.signo = SIGKILL;
653 sdargs.setsdstate = 2;
654 sdargs.countproc = 1;
655 sdargs.activecount = 0;
656
657 /* post a SIGKILL to all that catch SIGTERM and not marked for delay */
658 proc_rebootscan(sd_callback2, (void *)&sdargs, sd_filt2, (void *)&sfargs);
659
660 error = 0;
661
662 if (sdargs.activecount != 0 && proc_shutdown_exitcount != 0) {
663 proc_list_lock();
664 if (proc_shutdown_exitcount != 0) {
665 /*
666 * wait for up to 60 seconds to allow these procs to exit normally
667 *
668 * History: The delay interval was changed from 100 to 200
669 * for NFS requests in particular.
670 */
671 ts.tv_sec = 10;
672 ts.tv_nsec = 0;
673 error = msleep(&proc_shutdown_exitcount, &proc_list_mlock, PWAIT, "shutdownwait", &ts);
674 if (error != 0) {
675 for (p = allproc.lh_first; p; p = p->p_list.le_next) {
676 if ((p->p_listflag & P_LIST_EXITCOUNT) == P_LIST_EXITCOUNT) {
677 p->p_listflag &= ~P_LIST_EXITCOUNT;
678 }
679 }
680 for (p = zombproc.lh_first; p; p = p->p_list.le_next) {
681 if ((p->p_listflag & P_LIST_EXITCOUNT) == P_LIST_EXITCOUNT) {
682 p->p_listflag &= ~P_LIST_EXITCOUNT;
683 }
684 }
685 }
686 }
687 proc_list_unlock();
688 }
689
690 if (error == ETIMEDOUT) {
691 /*
692 * log the names of the unresponsive tasks
693 */
694
695 proc_list_lock();
696
697 for (p = allproc.lh_first; p; p = p->p_list.le_next) {
698 if (p->p_shutdownstate == 2) {
699 printf("%s[%d]: didn't act on SIGKILL\n", p->p_comm, proc_getpid(p));
700 sd_log(ctx, "%s[%d]: didn't act on SIGKILL\n", p->p_comm, proc_getpid(p));
701 }
702 }
703
704 proc_list_unlock();
705 }
706
707 /*
708 * if we still have procs that haven't exited, then brute force 'em
709 */
710 sfargs.delayterm = delayterm;
711 sfargs.shutdownstate = 3;
712 sdargs.signo = 0;
713 sdargs.setsdstate = 3;
714 sdargs.countproc = 0;
715 sdargs.activecount = 0;
716
717
718
719 /* post a SIGTERM to all that catch SIGTERM and not marked for delay */
720 proc_rebootscan(sd_callback3, (void *)&sdargs, sd_filt2, (void *)&sfargs);
721 printf("\n");
722
723 /* Now start the termination of processes that are marked for delayed termn */
724 if (delayterm == 0) {
725 delayterm = 1;
726 goto sigterm_loop;
727 }
728
729 sd_closelog(ctx);
730
731 if (only_non_dext) {
732 return;
733 }
734
735 /*
736 * Now that all other processes have been terminated, suspend init
737 */
738 task_suspend_internal(initproc->task);
739
740 /* drop the ref on initproc */
741 proc_rele(initproc);
742 printf("continuing\n");
743 }
744