[launchd-changes] [23739] trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Oct 16 17:55:13 PDT 2008


Revision: 23739
          http://trac.macosforge.org/projects/launchd/changeset/23739
Author:   dsorresso at apple.com
Date:     2008-10-16 17:55:13 -0700 (Thu, 16 Oct 2008)
Log Message:
-----------
<rdar://problem/5119327> SystemStarter: remove more entries from /etc/hostconfig
<rdar://problem/6132016> SystemStarter: leaks
<rdar://problem/6200354> SystemStarter: rc.local file automatically executes when copied or moved to the /private/etc/ folder
<rdar://problem/6245735> SystemStarter: "failed to start" reported on shutdown path
<rdar://problem/6268534> SystemStarter: 10A179: /sbin/autodiskmount is not 64-bit

Modified Paths:
--------------
    trunk/launchd/src/Makefile.am
    trunk/launchd/src/Makefile.in
    trunk/launchd/src/StartupItems.c
    trunk/launchd/src/StartupItems.h
    trunk/launchd/src/SystemStarter.8
    trunk/launchd/src/SystemStarter.c
    trunk/launchd/src/hostconfig

Property Changed:
----------------
    trunk/


Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/PR-5898404:23681-23700
/branches/PR-5978442:23651-23701
   + /branches/PR-5898404:23681-23700
/branches/PR-5978442:23651-23701
/branches/PR-6132016:23719-23738

Modified: trunk/launchd/src/Makefile.am
===================================================================
--- trunk/launchd/src/Makefile.am	2008-10-17 00:18:37 UTC (rev 23738)
+++ trunk/launchd/src/Makefile.am	2008-10-17 00:55:13 UTC (rev 23739)
@@ -53,7 +53,7 @@
 if DO_EMBEDDED_MAGIC
 else
 SystemStarter_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS)
-SystemStarter_LDFLAGS = $(AM_LDFLAGS) -framework CoreFoundation -framework IOKit
+SystemStarter_LDFLAGS = $(AM_LDFLAGS) -framework CoreFoundation -framework IOKit -framework DiskArbitration
 SystemStarter_SOURCES = StartupItems.c IPC.c SystemStarter.c
 endif
 

Modified: trunk/launchd/src/Makefile.in
===================================================================
--- trunk/launchd/src/Makefile.in	2008-10-17 00:18:37 UTC (rev 23738)
+++ trunk/launchd/src/Makefile.in	2008-10-17 00:55:13 UTC (rev 23739)
@@ -264,7 +264,7 @@
 @LIBS_ONLY_FALSE at launchctl_CFLAGS = $(AM_CFLAGS) -isystem $(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders
 @LIBS_ONLY_FALSE at launchctl_LDFLAGS = $(AM_LDFLAGS) -framework CoreFoundation -framework IOKit $(LIBS_SECURITY) -weak_library /usr/lib/libedit.dylib
 @DO_EMBEDDED_MAGIC_FALSE@@LIBS_ONLY_FALSE at SystemStarter_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS)
- at DO_EMBEDDED_MAGIC_FALSE@@LIBS_ONLY_FALSE at SystemStarter_LDFLAGS = $(AM_LDFLAGS) -framework CoreFoundation -framework IOKit
+ at DO_EMBEDDED_MAGIC_FALSE@@LIBS_ONLY_FALSE at SystemStarter_LDFLAGS = $(AM_LDFLAGS) -framework CoreFoundation -framework IOKit -framework DiskArbitration
 @DO_EMBEDDED_MAGIC_FALSE@@LIBS_ONLY_FALSE at SystemStarter_SOURCES = StartupItems.c IPC.c SystemStarter.c
 @LIBS_ONLY_FALSE at launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS)
 @LIBS_ONLY_FALSE at launchd_LDFLAGS = $(AM_LDFLAGS) -lbsm

Modified: trunk/launchd/src/StartupItems.c
===================================================================
--- trunk/launchd/src/StartupItems.c	2008-10-17 00:18:37 UTC (rev 23738)
+++ trunk/launchd/src/StartupItems.c	2008-10-17 00:55:13 UTC (rev 23739)
@@ -112,9 +112,9 @@
 }
 
 /**
- * startupItemListGetMatches returns an array of items which contain the string aService in the key aKey
+ * startupItemListCopyMatches returns an array of items which contain the string aService in the key aKey
  **/
-static CFMutableArrayRef startupItemListGetMatches(CFArrayRef anItemList, CFStringRef aKey, CFStringRef aService)
+static CFMutableArrayRef startupItemListCopyMatches(CFArrayRef anItemList, CFStringRef aKey, CFStringRef aService)
 {
 	CFMutableArrayRef aResult = NULL;
 
@@ -190,6 +190,7 @@
 		}
 
 		CFDictionaryReplaceValue(aConfig, type, aNewList);
+		CFRelease(aNewList);
 	}
 	if (type == kUsesKey)
 		return;
@@ -216,7 +217,7 @@
 	return aResult;
 }
 
-static bool StartupItemSecurityCheck(const char *aPath)
+bool StartupItemSecurityCheck(const char *aPath)
 {
 	static struct timeval boot_time;
 	struct stat aStatBuf;
@@ -430,11 +431,13 @@
 CFMutableDictionaryRef StartupItemListGetProvider(CFArrayRef anItemList, CFStringRef aService)
 {
 	CFMutableDictionaryRef aResult = NULL;
-	CFMutableArrayRef aList = startupItemListGetMatches(anItemList, kProvidesKey, aService);
+	CFMutableArrayRef aList = startupItemListCopyMatches(anItemList, kProvidesKey, aService);
 
 	if (aList && CFArrayGetCount(aList) > 0)
 		aResult = (CFMutableDictionaryRef) CFArrayGetValueAtIndex(aList, 0);
 
+	if (aList) CFRelease(aList);
+
 	return aResult;
 }
 
@@ -578,7 +581,7 @@
 
 	for (anItemIndex = 0; anItemIndex < anItemCount; anItemIndex++) {
 		CFStringRef anItem = CFArrayGetValueAtIndex(anItemList, anItemIndex);
-		CFArrayRef aMatchesList = startupItemListGetMatches(aWaitingList, aKey, anItem);
+		CFArrayRef aMatchesList = startupItemListCopyMatches(aWaitingList, aKey, anItem);
 
 		if (aMatchesList) {
 			aCount = aCount + CFArrayGetCount(aMatchesList);
@@ -604,7 +607,7 @@
 	for (anAntecedentIndex = 0; anAntecedentIndex < anAntecedentCount; ++anAntecedentIndex) {
 		CFStringRef anAntecedent = CFArrayGetValueAtIndex(anAntecedentList, anAntecedentIndex);
 		CFStringRef aKey = (anAction == kActionStart) ? kProvidesKey : kUsesKey;
-		CFArrayRef aMatchesList = startupItemListGetMatches(aWaitingList, aKey, anAntecedent);
+		CFArrayRef aMatchesList = startupItemListCopyMatches(aWaitingList, aKey, anAntecedent);
 
 		if (aMatchesList) {
 			CFIndex aMatchesListCount = CFArrayGetCount(aMatchesList);
@@ -655,7 +658,7 @@
 		 * might provide that service.
 		 */
 		else {
-			CFArrayRef aMatchesList = startupItemListGetMatches(aWaitingList, kProvidesKey, aProvides);
+			CFArrayRef aMatchesList = startupItemListCopyMatches(aWaitingList, kProvidesKey, aProvides);
 			if (aMatchesList) {
 				CFIndex aMatchesListCount = CFArrayGetCount(aMatchesList);
 				CFIndex aMatchesListIndex;

Modified: trunk/launchd/src/StartupItems.h
===================================================================
--- trunk/launchd/src/StartupItems.h	2008-10-17 00:18:37 UTC (rev 23738)
+++ trunk/launchd/src/StartupItems.h	2008-10-17 00:55:13 UTC (rev 23739)
@@ -107,4 +107,9 @@
 void StartupItemExit (CFMutableDictionaryRef aStatusDict, CFMutableDictionaryRef anItem, Boolean aSuccess);		     
 void StartupItemSetStatus(CFMutableDictionaryRef aStatusDict, CFMutableDictionaryRef anItem, CFStringRef aServiceName, Boolean aSuccess, Boolean aReplaceFlag);
 
+/*
+ * Check whether file was created before boot and has proper permissions to run.
+ */
+bool StartupItemSecurityCheck(const char *aPath);
+
 #endif /* _StartupItems_H_ */

Modified: trunk/launchd/src/SystemStarter.8
===================================================================
--- trunk/launchd/src/SystemStarter.8	2008-10-17 00:18:37 UTC (rev 23738)
+++ trunk/launchd/src/SystemStarter.8	2008-10-17 00:55:13 UTC (rev 23739)
@@ -12,9 +12,20 @@
 .Op Fl gvxdDqn
 .Op Ar action Op Ar service
 .Sh DESCRIPTION
-The 
+The
+.Nm
+utility is deprecated.  System services should instead be described by a
+.Xr launchd.plist 5 .
+See
+.Xr launchd 8
+for more details.
+The
+.Nm launchd
+utility is available on Mac OS X 10.4 and later.
+.Pp
+In earlier versions of Mac OS X, the 
 .Nm 
-utility may be used to start, stop, and restart the system services which
+utility is used to start, stop, and restart the system services which
 are described in the
 .Pa /Library/StartupItems/
 and
@@ -36,8 +47,8 @@
 During boot 
 .Nm
 is invoked by
-.Nm rc
-(see rc(8)) and is responsible for
+.Xr launchd 8
+and is responsible for
 starting all startup items in an order that satisfies each item's 
 requirements.
 .Sh ACTIONS
@@ -80,12 +91,6 @@
 .Nm
 examines the exit status of the startup item scripts to determine the success or failure of the services provided by that script.
 .Pp
-In Darwin it is preferable to create custom startup items than to modify
-.Nm rc ,
-and at some point
-.Nm
-may entirely encompass the role of
-.Nm rc .
 .Sh FILES
 .Bl -tag -width -/System/Library/StartupItems -compact
 .It Pa /Library/StartupItems/
@@ -96,14 +101,17 @@
 .Sh SEE ALSO 
 .\" List links in ascending order by section, alphabetically within a section.
 .\" Please do not reference files that do not exist without filing a bug report
-.Xr ConsoleMessage 8
-.Pp
+.Xr ConsoleMessage 8 ,
+.Xr launchd 8 ,
+.Xr launchd.plist 5 ,
 .Xr rc 8
 .\" .Sh BUGS              \" Document known, unremedied bugs 
 .Sh HISTORY
 The
 .Nm
-utility appeared in Darwin 1.0
-.Pp
+utility appeared in Darwin 1.0 and
+was extended in Darwin 6.0 to support partial startup and interprocess communication.
 .Nm
-was extended in Darwin 6.0 to support partial startup and interprocess communication.
+was deprecated by
+.Xr launchd 8
+in Darwin 8.0.

Modified: trunk/launchd/src/SystemStarter.c
===================================================================
--- trunk/launchd/src/SystemStarter.c	2008-10-17 00:18:37 UTC (rev 23738)
+++ trunk/launchd/src/SystemStarter.c	2008-10-17 00:55:13 UTC (rev 23739)
@@ -33,6 +33,8 @@
 #include <syslog.h>
 #include <assert.h>
 #include <CoreFoundation/CoreFoundation.h>
+#include <DiskArbitration/DiskArbitration.h>
+#include <DiskArbitration/DiskArbitrationPrivate.h>
 #include <NSSystemDirectories.h>
 #include "IPC.h"
 #include "StartupItems.h"
@@ -45,8 +47,9 @@
 
 static void     usage(void) __attribute__((noreturn));
 static int      system_starter(Action anAction, const char *aService);
-static void	displayErrorMessages(StartupContext aStartupContext);
+static void	displayErrorMessages(StartupContext aStartupContext, Action anAction);
 static pid_t	fwexec(const char *cmd, ...) __attribute__((sentinel));
+static void	autodiskmount(void);
 static void	dummy_sig(int signo __attribute__((unused)))
 {
 }
@@ -129,7 +132,6 @@
 
 	mach_timespec_t w = { 600, 0 };
 	kern_return_t kr;
-	struct stat sb;
 
 	/*
 	 * Too many old StartupItems had implicit dependancies on "Network" via
@@ -144,11 +146,11 @@
 	}
 
 	fwexec("/usr/sbin/ipconfig", "waitall", NULL);
-	fwexec("/sbin/autodiskmount", "-va", NULL);
+	autodiskmount(); /* wait for Disk Arbitration to report idle */
 
 	system_starter(kActionStart, NULL);
 
-	if (stat("/etc/rc.local", &sb) != -1) {
+	if (StartupItemSecurityCheck("/etc/rc.local")) {
 		fwexec(_PATH_BSHELL, "/etc/rc.local", NULL);
 	}
 
@@ -162,7 +164,7 @@
 	assert(r != -1);
 	assert(kev.filter == EVFILT_SIGNAL && kev.ident == SIGTERM);
 
-	if (stat("/etc/rc.shutdown.local", &sb) != -1) {
+	if (StartupItemSecurityCheck("/etc/rc.shutdown.local")) {
 		fwexec(_PATH_BSHELL, "/etc/rc.shutdown.local", NULL);
 	}
 
@@ -214,14 +216,14 @@
  * print out any error messages to the log regarding non starting StartupItems
  */
 void 
-displayErrorMessages(StartupContext aStartupContext)
+displayErrorMessages(StartupContext aStartupContext, Action anAction)
 {
 	if (aStartupContext->aFailedList && CFArrayGetCount(aStartupContext->aFailedList) > 0) {
 		CFIndex         anItemCount = CFArrayGetCount(aStartupContext->aFailedList);
 		CFIndex         anItemIndex;
 
 
-		syslog(LOG_WARNING, "The following StartupItems failed to properly start:");
+		syslog(LOG_WARNING, "The following StartupItems failed to %s properly:", (anAction == kActionStart) ? "start" : "stop");
 
 		for (anItemIndex = 0; anItemIndex < anItemCount; anItemIndex++) {
 			CFMutableDictionaryRef anItem = (CFMutableDictionaryRef) CFArrayGetValueAtIndex(aStartupContext->aFailedList, anItemIndex);
@@ -349,7 +351,7 @@
 	/**
          * Good-bye.
          **/
-	displayErrorMessages(aStartupContext);
+	displayErrorMessages(aStartupContext, anAction);
 
 	/* clean up  */
 	if (aStartupContext->aStatusDict)
@@ -435,3 +437,21 @@
 
 	return -1;
 }
+
+static void
+autodiskmount_idle(void* context __attribute__((unused)))
+{
+	CFRunLoopStop(CFRunLoopGetCurrent());
+}
+
+static void
+autodiskmount(void)
+{
+	DASessionRef session = DASessionCreate(NULL);
+	if (session) {
+		DASessionScheduleWithRunLoop(session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
+		DARegisterIdleCallback(session, autodiskmount_idle, NULL);
+		CFRunLoopRun();
+		CFRelease(session);
+	}
+}

Modified: trunk/launchd/src/hostconfig
===================================================================
--- trunk/launchd/src/hostconfig	2008-10-17 00:18:37 UTC (rev 23738)
+++ trunk/launchd/src/hostconfig	2008-10-17 00:55:13 UTC (rev 23739)
@@ -2,11 +2,5 @@
 
 AFPSERVER=-NO-
 AUTHSERVER=-NO-
-AUTOMOUNT=-YES-
-NFSLOCKS=-AUTOMATIC-
-NISDOMAIN=-NO-
 TIMESYNC=-NO-
 QTSSERVER=-NO-
-WEBSERVER=-NO-
-SMBSERVER=-NO-
-SNMPSERVER=-NO-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20081016/d048c20c/attachment-0001.html 


More information about the launchd-changes mailing list