[launchd-changes] [23113] trunk/launchd/src

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 27 11:52:05 PST 2007


Revision: 23113
          http://trac.macosforge.org/projects/launchd/changeset/23113
Author:   zarzycki at apple.com
Date:     2007-02-27 11:52:04 -0800 (Tue, 27 Feb 2007)

Log Message:
-----------
<rdar://problem/5026323> Only run SystemStarter when StartupItems exist

Modified Paths:
--------------
    trunk/launchd/src/SystemStarter.c
    trunk/launchd/src/com.apple.SystemStarter.plist
    trunk/launchd/src/launchctl.c
    trunk/launchd/src/rc.shutdown

Modified: trunk/launchd/src/SystemStarter.c
===================================================================
--- trunk/launchd/src/SystemStarter.c	2007-02-27 18:34:14 UTC (rev 23112)
+++ trunk/launchd/src/SystemStarter.c	2007-02-27 19:52:04 UTC (rev 23113)
@@ -24,12 +24,14 @@
 
 #include <IOKit/IOKitLib.h>
 #include <sys/types.h>
+#include <sys/event.h>
 #include <sys/stat.h>
 #include <paths.h>
 #include <unistd.h>
 #include <crt_externs.h>
 #include <fcntl.h>
 #include <syslog.h>
+#include <assert.h>
 #include <CoreFoundation/CoreFoundation.h>
 #include <NSSystemDirectories.h>
 #include "IPC.h"
@@ -44,16 +46,21 @@
 static void     usage(void) __attribute__((noreturn));
 static int      system_starter(Action anAction, const char *aService);
 static void	displayErrorMessages(StartupContext aStartupContext);
-static void	doCFnote(void);
 static pid_t	fwexec(const char *const *argv, bool _wait);
 
 int 
 main(int argc, char *argv[])
 {
+	struct kevent	kev;
 	Action          anAction = kActionStart;
-	char           *aService = NULL;
-	int             ch;
+	int             ch, kq;
 
+	assert((kq = kqueue()) != -1);
+
+	EV_SET(&kev, SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, 0);
+	assert(kevent(kq, &kev, 1, NULL, 0, NULL) != -1);
+	assert(signal(SIGTERM, SIG_IGN) != SIG_ERR);
+
 	while ((ch = getopt(argc, argv, "gvxirdDqn?")) != -1) {
 		switch (ch) {
 		case 'v':
@@ -80,15 +87,18 @@
 	argc -= optind;
 	argv += optind;
 
-	if (argc > 2)
+	if (argc > 2) {
 		usage();
+	}
 
 	openlog(getprogname(), LOG_PID|LOG_CONS|(gDebugFlag ? LOG_PERROR : 0), LOG_DAEMON);
-	setlogmask(LOG_UPTO(LOG_NOTICE));
-	if (gVerboseFlag)
-		setlogmask(LOG_UPTO(LOG_INFO));
-	if (gDebugFlag)
+	if (gDebugFlag) {
 		setlogmask(LOG_UPTO(LOG_DEBUG));
+	} else if (gVerboseFlag) {
+		setlogmask(LOG_UPTO(LOG_INFO));
+	} else {
+		setlogmask(LOG_UPTO(LOG_NOTICE));
+	}
 
 	if (!gNoRunFlag && (getuid() != 0)) {
 		syslog(LOG_ERR, "must be root to run");
@@ -107,55 +117,53 @@
 		}
 	}
 
-	atexit(doCFnote);
+	if (argc == 2) {
+		exit(system_starter(anAction, argv[1]));
+	}
 
 	unlink(kFixerPath);
 
-	if (argc == 2) {
-		aService = argv[1];
-	} else if (!gDebugFlag && anAction != kActionStop) {
-		const char *ipw_cmd[] = { "/usr/sbin/ipconfig", "waitall", NULL };
-		const char *adm_cmd[] = { "/sbin/autodiskmount", "-va", NULL };
-		mach_timespec_t w = { 600, 0 };
-		kern_return_t kr;
+	const char *ipw_cmd[] = { "/usr/sbin/ipconfig", "waitall", NULL };
+	const char *adm_cmd[] = { "/sbin/autodiskmount", "-va", NULL };
+	mach_timespec_t w = { 600, 0 };
+	kern_return_t kr;
+	struct stat sb;
 
-		/* Too many old StartupItems had implicit dependancies on
-		 * "Network" via other StartupItems that are now no-ops.
-		 *
-		 * SystemStarter is not on the critical path for boot up,
-		 * so we'll stall here to deal with this legacy dependancy
-		 * problem.
-		 */
+	/*
+	 * Too many old StartupItems had implicit dependancies on "Network" via
+	 * other StartupItems that are now no-ops.
+	 *
+	 * SystemStarter is not on the critical path for boot up, so we'll
+	 * stall here to deal with this legacy dependancy problem.
+	 */
 
-		if ((kr = IOKitWaitQuiet(kIOMasterPortDefault, &w)) != kIOReturnSuccess) {
-			syslog(LOG_NOTICE, "IOKitWaitQuiet: %d\n", kr);
-		}
-
-		fwexec(ipw_cmd, true);
-		fwexec(adm_cmd, true);
+	if ((kr = IOKitWaitQuiet(kIOMasterPortDefault, &w)) != kIOReturnSuccess) {
+		syslog(LOG_NOTICE, "IOKitWaitQuiet: %d\n", kr);
 	}
 
-	int ssec = system_starter(anAction, aService);
-	struct stat sb;
+	fwexec(ipw_cmd, true);
+	fwexec(adm_cmd, true);
 
-	if (anAction == kActionStart && stat("/etc/rc.local", &sb) != -1) {
-		int wstatus;
-		pid_t rclp;
+	system_starter(kActionStart, NULL);
 
-		switch ((rclp = fork())) {
-		case -1:
-			break;
-		case 0:
-			execlp(_PATH_BSHELL, _PATH_BSHELL, "/etc/rc.local", NULL);
-			_exit(EXIT_FAILURE);
-			break;
-		default:
-			waitpid(rclp, &wstatus, 0);
-			break;
-		}
+	if (stat("/etc/rc.local", &sb) != -1) {
+		const char *rc_local_cmd[] = { "_PATH_BSHELL", "/etc/rc.local", NULL };
+
+		fwexec(rc_local_cmd, true);
 	}
 
-	exit(ssec);
+	CFNotificationCenterPostNotificationWithOptions(
+			CFNotificationCenterGetDistributedCenter(),
+			CFSTR("com.apple.startupitems.completed"),
+			NULL, NULL,
+			kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions);
+
+	assert(kevent(kq, NULL, 0, &kev, 1, NULL) != -1);
+	assert(kev.filter == EVFILT_SIGNAL && kev.ident == SIGTERM);
+
+	system_starter(kActionStop, NULL);
+
+	exit(EXIT_SUCCESS);
 }
 
 
@@ -383,15 +391,6 @@
 	exit(EXIT_FAILURE);
 }
 
-static void doCFnote(void)
-{
-	CFNotificationCenterPostNotificationWithOptions(
-			CFNotificationCenterGetDistributedCenter(),
-			CFSTR("com.apple.startupitems.completed"),
-			NULL, NULL,
-			kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions);
-}
-
 pid_t
 fwexec(const char *const *argv, bool _wait)
 {

Modified: trunk/launchd/src/com.apple.SystemStarter.plist
===================================================================
--- trunk/launchd/src/com.apple.SystemStarter.plist	2007-02-27 18:34:14 UTC (rev 23112)
+++ trunk/launchd/src/com.apple.SystemStarter.plist	2007-02-27 19:52:04 UTC (rev 23113)
@@ -6,7 +6,18 @@
 	<string>com.apple.SystemStarter</string>
 	<key>Program</key>
 	<string>/sbin/SystemStarter</string>
-	<key>RunAtLoad</key>
-	<true/>
+	<key>KeepAlive</key>
+	<dict>
+		<key>KeepAlive</key>
+		<dict>
+			<key>/etc/rc.local</key>
+			<true/>
+		</dict>
+	</dict>
+	<key>QueueDirectories</key>
+	<array>
+		<string>/Library/StartupItems</string>
+		<string>/System/Library/StartupItems</string>
+	</array>
 </dict>
 </plist>

Modified: trunk/launchd/src/launchctl.c
===================================================================
--- trunk/launchd/src/launchctl.c	2007-02-27 18:34:14 UTC (rev 23112)
+++ trunk/launchd/src/launchctl.c	2007-02-27 19:52:04 UTC (rev 23113)
@@ -1259,10 +1259,10 @@
 
 	EV_SET(&kev, 0, EVFILT_TIMER, EV_ADD|EV_ONESHOT, NOTE_SECONDS, 90, 0);
 	assumes(kevent(kq, &kev, 1, NULL, 0, NULL) != -1);
-	assumes(signal(SIGTERM, SIG_IGN) != SIG_ERR);
 
 	EV_SET(&kev, SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, 0);
 	assumes(kevent(kq, &kev, 1, NULL, 0, NULL) != -1);
+	assumes(signal(SIGTERM, SIG_IGN) != SIG_ERR);
 
 	if (assumes((tfp_gr = getgrnam("procview")) != NULL)) {
 		int tfp_r_mib[3] = { CTL_KERN, KERN_TFP, KERN_TFP_READ_GROUP };

Modified: trunk/launchd/src/rc.shutdown
===================================================================
--- trunk/launchd/src/rc.shutdown	2007-02-27 18:34:14 UTC (rev 23112)
+++ trunk/launchd/src/rc.shutdown	2007-02-27 19:52:04 UTC (rev 23113)
@@ -4,7 +4,5 @@
 . /etc/rc.common
 
 if [ -f /etc/rc.shutdown.local ]; then
-	sh /etc/rc.shutdown.local
+	exec sh /etc/rc.shutdown.local
 fi
-
-exec SystemStarter stop

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070227/3d332699/attachment.html


More information about the launchd-changes mailing list