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,
136 round_page(panic_kext_memory_size), KMA_DATA | KMA_ZERO,
137 VM_KERN_MEMORY_OSFMK);
138 if (kr != KERN_SUCCESS) {
139 panic_kext_memory_info = NULL;
140 return;
141 }
142
143 vm_page_diagnose(panic_kext_memory_info, num_sites, 0);
144 }
145
146 int
get_system_inshutdown()147 get_system_inshutdown()
148 {
149 return system_inshutdown;
150 }
151
152 __abortlike
153 static void
panic_kernel(int howto,char * message)154 panic_kernel(int howto, char *message)
155 {
156 uint64_t opts = DEBUGGER_OPTION_NONE;
157
158 if ((howto & RB_PANIC_ZPRINT) == RB_PANIC_ZPRINT) {
159 zprint_panic_info();
160 }
161
162 if ((howto & RB_PANIC_FORCERESET) == RB_PANIC_FORCERESET) {
163 opts |= DEBUGGER_OPTION_PANICLOGANDREBOOT;
164 }
165
166 panic_with_options(0, NULL, opts, "userspace panic: %s", message);
167 }
168
169 extern boolean_t compressor_store_stop_compaction;
170 extern lck_mtx_t vm_swap_data_lock;
171 extern int vm_swapfile_create_thread_running;
172 extern int vm_swapfile_gc_thread_running;
173 extern uint32_t cl_sparse_push_error;
174
175 int
reboot_kernel(int howto,char * message)176 reboot_kernel(int howto, char *message)
177 {
178 int hostboot_option = 0;
179 uint64_t startTime;
180
181 if ((howto & (RB_PANIC | RB_QUICK)) == (RB_PANIC | RB_QUICK)) {
182 panic_kernel(howto, message);
183 }
184
185 if (!OSCompareAndSwap(0, 1, &system_inshutdown)) {
186 if ((howto & RB_QUICK) == RB_QUICK) {
187 goto force_reboot;
188 }
189 return EBUSY;
190 }
191
192 lck_mtx_lock(&vm_swap_data_lock);
193
194 /* Turn OFF future swapfile reclaimation / compaction etc.*/
195 compressor_store_stop_compaction = TRUE;
196
197 /* wait for any current swapfile work to end */
198 while (vm_swapfile_create_thread_running || vm_swapfile_gc_thread_running) {
199 assert_wait((event_t)&compressor_store_stop_compaction, THREAD_UNINT);
200
201 lck_mtx_unlock(&vm_swap_data_lock);
202
203 thread_block(THREAD_CONTINUE_NULL);
204
205 lck_mtx_lock(&vm_swap_data_lock);
206 }
207
208 lck_mtx_unlock(&vm_swap_data_lock);
209
210 /*
211 * Notify the power management root domain that the system will shut down.
212 */
213 IOSystemShutdownNotification(howto, kIOSystemShutdownNotificationStageProcessExit);
214
215 if ((howto & RB_QUICK) == RB_QUICK) {
216 printf("Quick reboot...\n");
217 if ((howto & RB_NOSYNC) == 0) {
218 sync((proc_t)NULL, (void *)NULL, (int *)NULL);
219 }
220 } else if ((howto & RB_NOSYNC) == 0) {
221 int iter, nbusy;
222
223 printf("syncing disks... ");
224
225 /*
226 * Release vnodes held by texts before sync.
227 */
228
229 /* handle live procs (deallocate their root and current directories), suspend initproc */
230
231 startTime = mach_absolute_time();
232 proc_shutdown(TRUE);
233 halt_log_enter("proc_shutdown", 0, mach_absolute_time() - startTime);
234
235 #if CONFIG_AUDIT
236 startTime = mach_absolute_time();
237 audit_shutdown();
238 halt_log_enter("audit_shutdown", 0, mach_absolute_time() - startTime);
239 #endif
240
241 #if XNU_TARGET_OS_OSX
242 if (unmountroot_pre_hook != NULL) {
243 unmountroot_pre_hook();
244 }
245 #endif
246
247 startTime = mach_absolute_time();
248 sync((proc_t)NULL, (void *)NULL, (int *)NULL);
249
250 if (kdebug_enable) {
251 startTime = mach_absolute_time();
252 kdbg_dump_trace_to_file("/var/log/shutdown/shutdown.trace", true);
253 halt_log_enter("shutdown.trace", 0, mach_absolute_time() - startTime);
254 }
255
256 IOSystemShutdownNotification(howto, kIOSystemShutdownNotificationStageRootUnmount);
257
258 if (cl_sparse_push_error) {
259 panic("system_shutdown cluster_push_err failed with ENOSPC %d times\n", cl_sparse_push_error);
260 }
261
262 /*
263 * Unmount filesystems
264 */
265
266 #if DEVELOPMENT || DEBUG
267 if (!(howto & RB_PANIC) || !kdp_has_polled_corefile())
268 #endif /* DEVELOPMENT || DEBUG */
269 {
270 startTime = mach_absolute_time();
271 vfs_unmountall(TRUE);
272 halt_log_enter("vfs_unmountall", 0, mach_absolute_time() - startTime);
273 }
274
275 IOSystemShutdownNotification(howto, kIOSystemShutdownNotificationTerminateDEXTs);
276
277 startTime = mach_absolute_time();
278 proc_shutdown(FALSE);
279 halt_log_enter("proc_shutdown", 0, mach_absolute_time() - startTime);
280
281 #if DEVELOPMENT || DEBUG
282 if (!(howto & RB_PANIC) || !kdp_has_polled_corefile())
283 #endif /* DEVELOPMENT || DEBUG */
284 {
285 startTime = mach_absolute_time();
286 vfs_unmountall(FALSE);
287 halt_log_enter("vfs_unmountall", 0, mach_absolute_time() - startTime);
288 }
289
290
291
292 /* Wait for the buffer cache to clean remaining dirty buffers */
293 startTime = mach_absolute_time();
294 for (iter = 0; iter < 100; iter++) {
295 nbusy = count_busy_buffers();
296 if (nbusy == 0) {
297 break;
298 }
299 printf("%d ", nbusy);
300 delay_for_interval( 1 * nbusy, 1000 * 1000);
301 }
302 if (nbusy) {
303 printf("giving up\n");
304 } else {
305 printf("done\n");
306 }
307 halt_log_enter("bufferclean", 0, mach_absolute_time() - startTime);
308 }
309 #if NETWORKING
310 /*
311 * Can't just use an splnet() here to disable the network
312 * because that will lock out softints which the disk
313 * drivers depend on to finish DMAs.
314 */
315 startTime = mach_absolute_time();
316 if_down_all();
317 halt_log_enter("if_down_all", 0, mach_absolute_time() - startTime);
318 #endif /* NETWORKING */
319
320 force_reboot:
321
322 if (howto & RB_PANIC) {
323 panic_kernel(howto, message);
324 }
325
326 if (howto & RB_HALT) {
327 hostboot_option = HOST_REBOOT_HALT;
328 }
329
330 if (howto & RB_UPSDELAY) {
331 hostboot_option = HOST_REBOOT_UPSDELAY;
332 }
333
334 host_reboot(host_priv_self(), hostboot_option);
335 /*
336 * should not be reached
337 */
338 return 0;
339 }
340
341 static int
sd_openlog(vfs_context_t ctx)342 sd_openlog(vfs_context_t ctx)
343 {
344 int error = 0;
345 struct timeval tv;
346
347 /* Open shutdown log */
348 if ((error = vnode_open(PROC_SHUTDOWN_LOG, (O_CREAT | FWRITE | O_NOFOLLOW), 0644, 0, &sd_logvp, ctx))) {
349 printf("Failed to open %s: error %d\n", PROC_SHUTDOWN_LOG, error);
350 sd_logvp = NULLVP;
351 return error;
352 }
353
354 vnode_setsize(sd_logvp, (off_t)0, 0, ctx);
355
356 /* Write a little header */
357 microtime(&tv);
358 sd_log(ctx, "Process shutdown log. Current time is %lu (in seconds).\n\n", tv.tv_sec);
359
360 return 0;
361 }
362
363 static int
sd_closelog(vfs_context_t ctx)364 sd_closelog(vfs_context_t ctx)
365 {
366 int error = 0;
367 if (sd_logvp != NULLVP) {
368 VNOP_FSYNC(sd_logvp, MNT_WAIT, ctx);
369 error = vnode_close(sd_logvp, FWRITE, ctx);
370 sd_logvp = NULLVP;
371 }
372
373 return error;
374 }
375
376 __printflike(2, 3)
377 static void
sd_log(vfs_context_t ctx,const char * fmt,...)378 sd_log(vfs_context_t ctx, const char *fmt, ...)
379 {
380 int resid, log_error, len;
381 char logbuf[100];
382 va_list arglist;
383
384 /* If the log isn't open yet, open it */
385 if (sd_logvp == NULLVP) {
386 if (sd_openlog(ctx) != 0) {
387 /* Couldn't open, we fail out */
388 return;
389 }
390 }
391
392 va_start(arglist, fmt);
393 len = vsnprintf(logbuf, sizeof(logbuf), fmt, arglist);
394 log_error = vn_rdwr(UIO_WRITE, sd_logvp, (caddr_t)logbuf, len, sd_log_offset,
395 UIO_SYSSPACE, IO_UNIT | IO_NOAUTH, vfs_context_ucred(ctx), &resid, vfs_context_proc(ctx));
396 if (log_error == EIO || log_error == 0) {
397 sd_log_offset += (len - resid);
398 }
399
400 va_end(arglist);
401 }
402
403 static int
sd_filt1(proc_t p,void * args)404 sd_filt1(proc_t p, void * args)
405 {
406 proc_t self = current_proc();
407 struct sd_filterargs * sf = (struct sd_filterargs *)args;
408 int delayterm = sf->delayterm;
409 int shutdownstate = sf->shutdownstate;
410
411 if (sf->only_non_dext && proc_is_driver(p)) {
412 return 0;
413 }
414
415 if (((p->p_flag & P_SYSTEM) != 0) || (p->p_ppid == 0)
416 || (p == self) || (p->p_stat == SZOMB)
417 || (p->p_shutdownstate != shutdownstate)
418 || ((delayterm == 0) && ((p->p_lflag & P_LDELAYTERM) == P_LDELAYTERM))
419 || ((p->p_sigcatch & sigmask(SIGTERM)) == 0)) {
420 return 0;
421 } else {
422 return 1;
423 }
424 }
425
426
427 static int
sd_callback1(proc_t p,void * args)428 sd_callback1(proc_t p, void * args)
429 {
430 struct sd_iterargs * sd = (struct sd_iterargs *)args;
431 int signo = sd->signo;
432 int setsdstate = sd->setsdstate;
433 int countproc = sd->countproc;
434
435 proc_lock(p);
436 p->p_shutdownstate = (char)setsdstate;
437 if (p->p_stat != SZOMB) {
438 proc_unlock(p);
439 if (countproc != 0) {
440 proc_list_lock();
441 p->p_listflag |= P_LIST_EXITCOUNT;
442 proc_shutdown_exitcount++;
443 proc_list_unlock();
444 }
445 if (proc_is_driver(p)) {
446 printf("lingering dext %s signal(%d)\n", p->p_name, signo);
447 }
448 psignal(p, signo);
449 if (countproc != 0) {
450 sd->activecount++;
451 }
452 } else {
453 proc_unlock(p);
454 }
455
456 return PROC_RETURNED;
457 }
458
459 static int
sd_filt2(proc_t p,void * args)460 sd_filt2(proc_t p, void * args)
461 {
462 proc_t self = current_proc();
463 struct sd_filterargs * sf = (struct sd_filterargs *)args;
464 int delayterm = sf->delayterm;
465 int shutdownstate = sf->shutdownstate;
466
467 if (sf->only_non_dext && proc_is_driver(p)) {
468 return 0;
469 }
470
471 if (((p->p_flag & P_SYSTEM) != 0) || (p->p_ppid == 0)
472 || (p == self) || (p->p_stat == SZOMB)
473 || (p->p_shutdownstate == shutdownstate)
474 || ((delayterm == 0) && ((p->p_lflag & P_LDELAYTERM) == P_LDELAYTERM))) {
475 return 0;
476 } else {
477 return 1;
478 }
479 }
480
481 static int
sd_callback2(proc_t p,void * args)482 sd_callback2(proc_t p, void * args)
483 {
484 struct sd_iterargs * sd = (struct sd_iterargs *)args;
485 int signo = sd->signo;
486 int setsdstate = sd->setsdstate;
487 int countproc = sd->countproc;
488
489 proc_lock(p);
490 p->p_shutdownstate = (char)setsdstate;
491 if (p->p_stat != SZOMB) {
492 proc_unlock(p);
493 if (countproc != 0) {
494 proc_list_lock();
495 p->p_listflag |= P_LIST_EXITCOUNT;
496 proc_shutdown_exitcount++;
497 proc_list_unlock();
498 }
499 if (proc_is_driver(p)) {
500 printf("lingering dext %s signal(%d)\n", p->p_name, signo);
501 }
502 psignal(p, signo);
503 if (countproc != 0) {
504 sd->activecount++;
505 }
506 } else {
507 proc_unlock(p);
508 }
509
510 return PROC_RETURNED;
511 }
512
513 static int
sd_callback3(proc_t p,void * args)514 sd_callback3(proc_t p, void * args)
515 {
516 struct sd_iterargs * sd = (struct sd_iterargs *)args;
517 vfs_context_t ctx = vfs_context_current();
518
519 int setsdstate = sd->setsdstate;
520
521 proc_lock(p);
522 p->p_shutdownstate = (char)setsdstate;
523 if (p->p_stat != SZOMB) {
524 /*
525 * NOTE: following code ignores sig_lock and plays
526 * with exit_thread correctly. This is OK unless we
527 * are a multiprocessor, in which case I do not
528 * understand the sig_lock. This needs to be fixed.
529 * XXX
530 */
531 if (p->exit_thread) { /* someone already doing it */
532 proc_unlock(p);
533 /* give him a chance */
534 thread_block(THREAD_CONTINUE_NULL);
535 } else {
536 p->exit_thread = current_thread();
537 printf(".");
538
539 sd_log(ctx, "%s[%d] had to be forced closed with exit1().\n", p->p_comm, proc_getpid(p));
540
541 proc_unlock(p);
542 KERNEL_DEBUG_CONSTANT(BSDDBG_CODE(DBG_BSD_PROC, BSD_PROC_FRCEXIT) | DBG_FUNC_NONE,
543 proc_getpid(p), 0, 1, 0, 0);
544 sd->activecount++;
545 exit1(p, 1, (int *)NULL);
546 }
547 } else {
548 proc_unlock(p);
549 }
550
551 return PROC_RETURNED;
552 }
553
554
555 /*
556 * proc_shutdown()
557 *
558 * Shutdown down proc system (release references to current and root
559 * dirs for each process).
560 *
561 * POSIX modifications:
562 *
563 * For POSIX fcntl() file locking call vno_lockrelease() on
564 * the file to release all of its record locks, if any.
565 */
566
567 static void
proc_shutdown(int only_non_dext)568 proc_shutdown(int only_non_dext)
569 {
570 vfs_context_t ctx = vfs_context_current();
571 struct proc *p, *self;
572 int delayterm = 0;
573 struct sd_filterargs sfargs;
574 struct sd_iterargs sdargs;
575 int error = 0;
576 struct timespec ts;
577
578 /*
579 * Kill as many procs as we can. (Except ourself...)
580 */
581 self = (struct proc *)current_proc();
582
583 /*
584 * Signal the init with SIGTERM so that he does not launch
585 * new processes
586 */
587 p = proc_find(1);
588 if (p && p != self) {
589 psignal(p, SIGTERM);
590 }
591 proc_rele(p);
592
593 printf("Killing all processes ");
594
595 sigterm_loop:
596 /*
597 * send SIGTERM to those procs interested in catching one
598 */
599 sfargs.delayterm = delayterm;
600 sfargs.shutdownstate = 0;
601 sfargs.only_non_dext = only_non_dext;
602 sdargs.signo = SIGTERM;
603 sdargs.setsdstate = 1;
604 sdargs.countproc = 1;
605 sdargs.activecount = 0;
606
607 error = 0;
608 /* post a SIGTERM to all that catch SIGTERM and not marked for delay */
609 proc_rebootscan(sd_callback1, (void *)&sdargs, sd_filt1, (void *)&sfargs);
610
611 if (sdargs.activecount != 0 && proc_shutdown_exitcount != 0) {
612 proc_list_lock();
613 if (proc_shutdown_exitcount != 0) {
614 /*
615 * now wait for up to 3 seconds to allow those procs catching SIGTERM
616 * to digest it
617 * as soon as these procs have exited, we'll continue on to the next step
618 */
619 ts.tv_sec = 3;
620 ts.tv_nsec = 0;
621 error = msleep(&proc_shutdown_exitcount, &proc_list_mlock, PWAIT, "shutdownwait", &ts);
622 if (error != 0) {
623 for (p = allproc.lh_first; p; p = p->p_list.le_next) {
624 if ((p->p_listflag & P_LIST_EXITCOUNT) == P_LIST_EXITCOUNT) {
625 p->p_listflag &= ~P_LIST_EXITCOUNT;
626 }
627 }
628 for (p = zombproc.lh_first; p; p = p->p_list.le_next) {
629 if ((p->p_listflag & P_LIST_EXITCOUNT) == P_LIST_EXITCOUNT) {
630 p->p_listflag &= ~P_LIST_EXITCOUNT;
631 }
632 }
633 }
634 }
635 proc_list_unlock();
636 }
637 if (error == ETIMEDOUT) {
638 /*
639 * log the names of the unresponsive tasks
640 */
641
642 proc_list_lock();
643
644 for (p = allproc.lh_first; p; p = p->p_list.le_next) {
645 if (p->p_shutdownstate == 1) {
646 printf("%s[%d]: didn't act on SIGTERM\n", p->p_comm, proc_getpid(p));
647 sd_log(ctx, "%s[%d]: didn't act on SIGTERM\n", p->p_comm, proc_getpid(p));
648 }
649 }
650
651 proc_list_unlock();
652 }
653
654 /*
655 * send a SIGKILL to all the procs still hanging around
656 */
657 sfargs.delayterm = delayterm;
658 sfargs.shutdownstate = 2;
659 sdargs.signo = SIGKILL;
660 sdargs.setsdstate = 2;
661 sdargs.countproc = 1;
662 sdargs.activecount = 0;
663
664 /* post a SIGKILL to all that catch SIGTERM and not marked for delay */
665 proc_rebootscan(sd_callback2, (void *)&sdargs, sd_filt2, (void *)&sfargs);
666
667 error = 0;
668
669 if (sdargs.activecount != 0 && proc_shutdown_exitcount != 0) {
670 proc_list_lock();
671 if (proc_shutdown_exitcount != 0) {
672 /*
673 * wait for up to 60 seconds to allow these procs to exit normally
674 *
675 * History: The delay interval was changed from 100 to 200
676 * for NFS requests in particular.
677 */
678 ts.tv_sec = 10;
679 ts.tv_nsec = 0;
680 error = msleep(&proc_shutdown_exitcount, &proc_list_mlock, PWAIT, "shutdownwait", &ts);
681 if (error != 0) {
682 for (p = allproc.lh_first; p; p = p->p_list.le_next) {
683 if ((p->p_listflag & P_LIST_EXITCOUNT) == P_LIST_EXITCOUNT) {
684 p->p_listflag &= ~P_LIST_EXITCOUNT;
685 }
686 }
687 for (p = zombproc.lh_first; p; p = p->p_list.le_next) {
688 if ((p->p_listflag & P_LIST_EXITCOUNT) == P_LIST_EXITCOUNT) {
689 p->p_listflag &= ~P_LIST_EXITCOUNT;
690 }
691 }
692 }
693 }
694 proc_list_unlock();
695 }
696
697 if (error == ETIMEDOUT) {
698 /*
699 * log the names of the unresponsive tasks
700 */
701
702 proc_list_lock();
703
704 for (p = allproc.lh_first; p; p = p->p_list.le_next) {
705 if (p->p_shutdownstate == 2) {
706 printf("%s[%d]: didn't act on SIGKILL\n", p->p_comm, proc_getpid(p));
707 sd_log(ctx, "%s[%d]: didn't act on SIGKILL\n", p->p_comm, proc_getpid(p));
708 }
709 }
710
711 proc_list_unlock();
712 }
713
714 /*
715 * if we still have procs that haven't exited, then brute force 'em
716 */
717 sfargs.delayterm = delayterm;
718 sfargs.shutdownstate = 3;
719 sdargs.signo = 0;
720 sdargs.setsdstate = 3;
721 sdargs.countproc = 0;
722 sdargs.activecount = 0;
723
724
725
726 /* post a SIGTERM to all that catch SIGTERM and not marked for delay */
727 proc_rebootscan(sd_callback3, (void *)&sdargs, sd_filt2, (void *)&sfargs);
728 printf("\n");
729
730 /* Now start the termination of processes that are marked for delayed termn */
731 if (delayterm == 0) {
732 delayterm = 1;
733 goto sigterm_loop;
734 }
735
736 sd_closelog(ctx);
737
738 if (only_non_dext) {
739 return;
740 }
741
742 /*
743 * Now that all other processes have been terminated, suspend init
744 */
745 task_suspend_internal(proc_task(initproc));
746
747 /* drop the ref on initproc */
748 proc_rele(initproc);
749 printf("continuing\n");
750 }
751