]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/kern_shutdown.c
xnu-792.25.20.tar.gz
[apple/xnu.git] / bsd / kern / kern_shutdown.c
index 7c8eb53b7005051ded64b2ca3fca056b5ce7165e..931b27c3d208ab3e3552f9bdaf6b764de126eeb3 100644 (file)
@@ -60,6 +60,7 @@
 #include <bsm/audit_kernel.h>
 
 int    waittime = -1;
+static void proc_shutdown();
 
 void
 boot(paniced, howto, command)
@@ -73,7 +74,6 @@ boot(paniced, howto, command)
        int funnel_state;
        struct proc  *launchd_proc;
 
-       static void proc_shutdown();
     extern void md_prepare_for_shutdown(int paniced, int howto, char * command);
 
        funnel_state = thread_funnel_set(kernel_flock, TRUE);
@@ -141,6 +141,10 @@ boot(paniced, howto, command)
        if (paniced == RB_PANIC)
                hostboot_option = HOST_REBOOT_HALT;
 
+    if (howto & RB_UPSDELAY) {
+        hostboot_option = HOST_REBOOT_UPSDELAY;
+    }
+
        /*
         * if we're going to power down due to a halt,
         * give the disks a chance to finish getting
@@ -207,8 +211,10 @@ sigterm_loop:
                        }
                        if (p->p_sigcatch & sigmask(SIGTERM)) {
                                        p->p_shutdownstate = 1;
-                               psignal(p, SIGTERM);
-
+                                       if (proc_refinternal(p, 1) == p) {
+                                       psignal(p, SIGTERM);
+                                               proc_dropinternal(p, 1);
+                                       }
                                goto sigterm_loop;
                }
        }
@@ -258,7 +264,10 @@ sigkill_loop:
                        if ((delayterm == 0) && ((p->p_lflag& P_LDELAYTERM) == P_LDELAYTERM)) {
                                continue;
                        }
-                       psignal(p, SIGKILL);
+                       if (proc_refinternal(p, 1) == p) {
+                               psignal(p, SIGKILL);
+                               proc_dropinternal(p, 1);
+                       }
                        p->p_shutdownstate = 2;
                        goto sigkill_loop;
                }
@@ -282,11 +291,12 @@ sigkill_loop:
         */
        p = allproc.lh_first;
        while (p) {
-               if ((p->p_flag&P_SYSTEM) || (!delayterm && ((p->p_lflag& P_LDELAYTERM))) 
+               if ((p->p_shutdownstate == 3) || (p->p_flag&P_SYSTEM) || (!delayterm && ((p->p_lflag& P_LDELAYTERM))) 
                                || (p->p_pptr->p_pid == 0) || (p == self)) {
                        p = p->p_list.le_next;
                }
                else {
+                       p->p_shutdownstate = 3;
                        /*
                         * NOTE: following code ignores sig_lock and plays
                         * with exit_thread correctly.  This is OK unless we
@@ -300,7 +310,10 @@ sigkill_loop:
                        } else {
                                p->exit_thread = current_thread();
                                printf(".");
-                               exit1(p, 1, (int *)NULL);
+                               if (proc_refinternal(p, 1) == p) {
+                                       exit1(p, 1, (int *)NULL);
+                                       proc_dropinternal(p, 1);
+                               }
                        }
                        p = allproc.lh_first;
                }