#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"
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)))
{
}
mach_timespec_t w = { 600, 0 };
kern_return_t kr;
- struct stat sb;
/*
* Too many old StartupItems had implicit dependancies on "Network" via
}
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);
}
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);
}
* 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);
/**
* Good-bye.
**/
- displayErrorMessages(aStartupContext);
+ displayErrorMessages(aStartupContext, anAction);
/* clean up */
if (aStartupContext->aStatusDict)
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);
+ }
+}