Revision
23041
Author
zarzycki@apple.com
Date
2007-02-07 17:28:03 -0800 (Wed, 07 Feb 2007)

Log Message

With this change, you can now: "sudo kill -TERM 1" and the machine will gracefully power off.

Modified Paths

Diff

Modified: trunk/launchd/src/launchd.c (23040 => 23041)


--- trunk/launchd/src/launchd.c	2007-02-07 23:39:58 UTC (rev 23040)
+++ trunk/launchd/src/launchd.c	2007-02-08 01:28:03 UTC (rev 23041)
@@ -41,6 +41,7 @@
 #include <sys/ioctl.h>
 #include <sys/mount.h>
 #include <sys/kern_event.h>
+#include <sys/reboot.h>
 #include <net/if.h>
 #include <netinet/in.h>
 #include <netinet/in_var.h>
@@ -678,12 +679,14 @@
 	if (shutdown_in_progress && jobmgr_is_idle(root_jobmgr)) {
 		shutdown_in_progress = false;
 
-		if (getpid() != 1) {
+		if (getpid() == 1) {
+			if (re_exec_in_single_user_mode) {
+				kill(-1, SIGKILL); /* One last time, just to clear the room */
+				launchd_assumes(execl("/sbin/launchd", "/sbin/launchd", "-s", NULL) != -1);
+			}
+			launchd_assumes(reboot(RB_HALT) != -1);
+		} else {
 			exit(EXIT_SUCCESS);
-		} else if (re_exec_in_single_user_mode) {
-			re_exec_in_single_user_mode = false;
-			kill(-1, SIGKILL); /* One last time, just to clear the room */
-			launchd_assumes(execl("/sbin/launchd", "/sbin/launchd", "-s", NULL) != -1);
 		}
 	}
 	if (getpid() == 1) {