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

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 19 11:26:21 PDT 2007


Revision: 23154
          http://trac.macosforge.org/projects/launchd/changeset/23154
Author:   zarzycki at apple.com
Date:     2007-03-19 11:26:21 -0700 (Mon, 19 Mar 2007)

Log Message:
-----------
<rdar://problem/5071550> launchd needs exec on disk mount option

Modified Paths:
--------------
    trunk/launchd/src/launchd.plist.5
    trunk/launchd/src/launchd_core_logic.c
    trunk/launchd/src/launchd_runtime.c
    trunk/launchd/src/liblaunch_public.h

Modified: trunk/launchd/src/launchd.plist.5
===================================================================
--- trunk/launchd/src/launchd.plist.5	2007-03-19 17:49:43 UTC (rev 23153)
+++ trunk/launchd/src/launchd.plist.5	2007-03-19 18:26:21 UTC (rev 23154)
@@ -195,6 +195,8 @@
 This optional key causes the job to be started if any one of the listed paths are modified.
 .It Sy QueueDirectories <array of strings>
 Much like the WatchPaths option, this key will watch the paths for modifications. The difference being that the job will only be started if the path is a directory and the directory is not empty.
+.It Sy StartOnMount <boolean>
+This optional key causes the job to be started every time a filesystem is mounted.
 .It Sy StartInterval <integer>
 This optional key causes the job to be started every N seconds.
 If the system is asleep, the job will be started the next time the computer

Modified: trunk/launchd/src/launchd_core_logic.c
===================================================================
--- trunk/launchd/src/launchd_core_logic.c	2007-03-19 17:49:43 UTC (rev 23153)
+++ trunk/launchd/src/launchd_core_logic.c	2007-03-19 18:26:21 UTC (rev 23154)
@@ -222,7 +222,7 @@
 static bool jobmgr_is_idle(jobmgr_t jm);
 static void jobmgr_log_stray_children(jobmgr_t jm);
 static void jobmgr_remove(jobmgr_t jm);
-static void jobmgr_dispatch_all(jobmgr_t jm);
+static void jobmgr_dispatch_all(jobmgr_t jm, bool newmounthack);
 static job_t job_mig_intran2(jobmgr_t jm, mach_port_t p);
 static void job_export_all2(jobmgr_t jm, launch_data_t where);
 static void jobmgr_callback(void *obj, struct kevent *kev);
@@ -278,7 +278,7 @@
 	mode_t mask;
 	unsigned int globargv:1, wait4debugger:1, unload_at_exit:1, stall_before_exec:1, only_once:1,
 		     currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1, hopefully_exits_last:1, removal_pending:1,
-		     wait4pipe_eof:1, sent_sigkill:1, debug_before_kill:1, weird_bootstrap:1;
+		     wait4pipe_eof:1, sent_sigkill:1, debug_before_kill:1, weird_bootstrap:1, start_on_mount:1;
 	char label[0];
 };
 
@@ -766,7 +766,7 @@
 	}
 
 	if (j->mgr->global_on_demand_cnt == 0) {
-		jobmgr_dispatch_all(j->mgr);
+		jobmgr_dispatch_all(j->mgr, false);
 	}
 
 	return true;
@@ -1089,6 +1089,8 @@
 	case 'S':
 		if (strcasecmp(key, LAUNCH_JOBKEY_SESSIONCREATE) == 0) {
 			j->session_create = value;
+		} else if (strcasecmp(key, LAUNCH_JOBKEY_STARTONMOUNT) == 0) {
+			j->start_on_mount = value;
 		}
 		break;
 	case 'l':
@@ -1751,17 +1753,17 @@
 }
 
 void
-jobmgr_dispatch_all(jobmgr_t jm)
+jobmgr_dispatch_all(jobmgr_t jm, bool newmounthack)
 {
 	jobmgr_t jmi, jmn;
 	job_t ji, jn;
 
 	SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) {
-		jobmgr_dispatch_all(jmi);
+		jobmgr_dispatch_all(jmi, newmounthack);
 	}
 
 	SLIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) {
-		job_dispatch(ji, false);
+		job_dispatch(ji, newmounthack ? ji->start_on_mount : false);
 	}
 }
 
@@ -1909,6 +1911,12 @@
 			return (void)jobmgr_assumes(jm, false);
 		}
 		break;
+	case EVFILT_FS:
+		if (kev->fflags & VQ_MOUNT) {
+			jobmgr_dispatch_all(jm, true);
+		}
+		jobmgr_dispatch_all_semaphores(jm);
+		break;
 	case EVFILT_TIMER:
 		jobmgr_log(jm, LOG_NOTICE, "Still alive with %u children.", total_children);
 		break;
@@ -3503,6 +3511,7 @@
 
 	if (!jm) {
 		jobmgr_assumes(jmr, kevent_mod(SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, jmr) != -1);
+		jobmgr_assumes(jmr, kevent_mod(0, EVFILT_FS, EV_ADD|EV_CLEAR, VQ_MOUNT|VQ_UNMOUNT|VQ_UPDATE, 0, jmr) != -1);
 	}
 
 	if (name) {

Modified: trunk/launchd/src/launchd_runtime.c
===================================================================
--- trunk/launchd/src/launchd_runtime.c	2007-03-19 17:49:43 UTC (rev 23153)
+++ trunk/launchd/src/launchd_runtime.c	2007-03-19 18:26:21 UTC (rev 23154)
@@ -42,6 +42,7 @@
 #include <sys/socket.h>
 #include <sys/mount.h>
 #include <sys/reboot.h>
+#include <sys/fcntl.h>
 #include <bsm/libbsm.h>
 #include <malloc/malloc.h>
 #include <unistd.h>
@@ -888,6 +889,15 @@
 
 		record_caller_creds(&bufRequest->Head);
 
+		/*
+		 * This is a total hack. We really need a bit in the kernel's proc
+		 * struct to declare our intent.
+		 */
+		static int no_hang_fd = -1;
+		if (no_hang_fd == -1) {
+			no_hang_fd = _fd(open("/dev/autofs_nowait", 0));
+		}
+
 		if (the_demux(&bufRequest->Head, &bufReply->Head) == FALSE) {
 			/* XXX - also gross */
 			if (bufRequest->Head.msgh_id == MACH_NOTIFY_NO_SENDERS) {

Modified: trunk/launchd/src/liblaunch_public.h
===================================================================
--- trunk/launchd/src/liblaunch_public.h	2007-03-19 17:49:43 UTC (rev 23153)
+++ trunk/launchd/src/liblaunch_public.h	2007-03-19 18:26:21 UTC (rev 23154)
@@ -81,6 +81,7 @@
 #define LAUNCH_JOBKEY_HOPEFULLYEXITSLAST	"HopefullyExitsLast"
 #define LAUNCH_JOBKEY_LOWPRIORITYIO		"LowPriorityIO"
 #define LAUNCH_JOBKEY_SESSIONCREATE		"SessionCreate"
+#define LAUNCH_JOBKEY_STARTONMOUNT		"StartOnMount"
 #define LAUNCH_JOBKEY_SOFTRESOURCELIMITS	"SoftResourceLimits"
 #define LAUNCH_JOBKEY_HARDRESOURCELIMITS	"HardResourceLimits"
 #define LAUNCH_JOBKEY_STANDARDOUTPATH		"StandardOutPath"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070319/316beb23/attachment.html


More information about the launchd-changes mailing list