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