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

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 18 09:05:53 PDT 2007


Revision: 23227
          http://trac.macosforge.org/projects/launchd/changeset/23227
Author:   zarzycki at apple.com
Date:     2007-04-18 09:05:52 -0700 (Wed, 18 Apr 2007)

Log Message:
-----------
<rdar://problem/5133890> Kerberos needs to be enabled only when one or more other jobs are enabled

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

Modified: trunk/launchd/src/launchd.plist.5
===================================================================
--- trunk/launchd/src/launchd.plist.5	2007-04-17 20:41:58 UTC (rev 23226)
+++ trunk/launchd/src/launchd.plist.5	2007-04-18 16:05:52 UTC (rev 23227)
@@ -155,6 +155,11 @@
 true, then the job will be kept alive as long as the path exists.
 If false, the job will be kept alive in the inverse condition. The intent of this
 feature is that two or more jobs may create semaphores in the file-system namespace.
+.It Sy OtherJobEnabled <dictionary of booleans>
+Each key in this dictionary is the label of another job. If the value of the key is
+true, then this job is kept alive as long as that other job is enabled. Otherwise,
+if the value is false, then this job is kept alive as long as the other job is disabled.
+This feature should not be considered a substitute for the use of IPC.
 .El
 .It Sy RunAtLoad <boolean>
 This optional key is used to control whether your job is launched once at the time the job is loaded. The default is false.

Modified: trunk/launchd/src/launchd_core_logic.c
===================================================================
--- trunk/launchd/src/launchd_core_logic.c	2007-04-17 20:41:58 UTC (rev 23226)
+++ trunk/launchd/src/launchd_core_logic.c	2007-04-18 16:05:52 UTC (rev 23227)
@@ -195,6 +195,8 @@
 	FAILED_EXIT,
 	PATH_EXISTS,
 	PATH_MISSING,
+	OTHER_JOB_ENABLED,
+	OTHER_JOB_DISABLED,
 	OTHER_JOB_ACTIVE,
 	OTHER_JOB_INACTIVE,
 	PATH_CHANGES,
@@ -209,11 +211,16 @@
 	char what[0];
 };
 
+struct semaphoreitem_dict_iter_context {
+	job_t j;
+	semaphore_reason_t why_true;
+	semaphore_reason_t why_false;
+};
+
 static bool semaphoreitem_new(job_t j, semaphore_reason_t why, const char *what);
 static void semaphoreitem_delete(job_t j, struct semaphoreitem *si);
 static void semaphoreitem_setup(launch_data_t obj, const char *key, void *context);
-static void semaphoreitem_setup_paths(launch_data_t obj, const char *key, void *context);
-static void semaphoreitem_setup_otherjobs(launch_data_t obj, const char *key, void *context);
+static void semaphoreitem_setup_dict_iter(launch_data_t obj, const char *key, void *context);
 static void semaphoreitem_callback(job_t j, struct kevent *kev);
 static void semaphoreitem_watch(job_t j, struct semaphoreitem *si);
 static void semaphoreitem_ignore(job_t j, struct semaphoreitem *si);
@@ -3239,6 +3246,14 @@
 				return true;
 			}
 			break;
+		case OTHER_JOB_ENABLED:
+			wanted_state = true;
+		case OTHER_JOB_DISABLED:
+			if ((bool)job_find(si->what) == wanted_state) {
+				job_log(j, LOG_DEBUG, "KeepAlive: The following job is %s: %s", wanted_state ? "enabled" : "disabled", si->what);
+				return true;
+			}
+			break;
 		case OTHER_JOB_ACTIVE:
 			wanted_state = true;
 		case OTHER_JOB_INACTIVE:
@@ -4154,46 +4169,56 @@
 }
 
 void
-semaphoreitem_setup_otherjobs(launch_data_t obj, const char *key, void *context)
+semaphoreitem_setup_dict_iter(launch_data_t obj, const char *key, void *context)
 {
-	job_t j = context;
+	struct semaphoreitem_dict_iter_context *sdic = context;
 	semaphore_reason_t why;
 
-	why = launch_data_get_bool(obj) ? OTHER_JOB_ACTIVE : OTHER_JOB_INACTIVE;
+	why = launch_data_get_bool(obj) ? sdic->why_true : sdic->why_false;
 
-	semaphoreitem_new(j, why, key);
+	semaphoreitem_new(sdic->j, why, key);
 }
 
 void
-semaphoreitem_setup_paths(launch_data_t obj, const char *key, void *context)
+semaphoreitem_setup(launch_data_t obj, const char *key, void *context)
 {
+	struct semaphoreitem_dict_iter_context sdic = { context, 0, 0 };
 	job_t j = context;
 	semaphore_reason_t why;
 
-	why = launch_data_get_bool(obj) ? PATH_EXISTS : PATH_MISSING;
+	switch (launch_data_get_type(obj)) {
+	case LAUNCH_DATA_BOOL:
+		if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_NETWORKSTATE) == 0) {
+			why = launch_data_get_bool(obj) ? NETWORK_UP : NETWORK_DOWN;
+			semaphoreitem_new(j, why, NULL);
+		} else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT) == 0) {
+			why = launch_data_get_bool(obj) ? SUCCESSFUL_EXIT : FAILED_EXIT;
+			semaphoreitem_new(j, why, NULL);
+			j->runatload = true;
+		} else {
+			job_assumes(j, false);
+		}
+		break;
+	case LAUNCH_DATA_DICTIONARY:
+		if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_PATHSTATE) == 0) {
+			sdic.why_true = PATH_EXISTS;
+			sdic.why_false = PATH_MISSING;
+		} else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBACTIVE) == 0) {
+			sdic.why_true = OTHER_JOB_ACTIVE;
+			sdic.why_false = OTHER_JOB_INACTIVE;
+		} else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBENABLED) == 0) {
+			sdic.why_true = OTHER_JOB_ENABLED;
+			sdic.why_false = OTHER_JOB_DISABLED;
+		} else {
+			job_assumes(j, false);
+			break;
+		}
 
-	semaphoreitem_new(j, why, key);
-}
-
-void
-semaphoreitem_setup(launch_data_t obj, const char *key, void *context)
-{
-	job_t j = context;
-	semaphore_reason_t why;
-
-	if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_NETWORKSTATE) == 0) {
-		why = launch_data_get_bool(obj) ? NETWORK_UP : NETWORK_DOWN;
-		semaphoreitem_new(j, why, NULL);
-	} else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT) == 0) {
-		why = launch_data_get_bool(obj) ? SUCCESSFUL_EXIT : FAILED_EXIT;
-		semaphoreitem_new(j, why, NULL);
-		j->runatload = true;
-	} else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_PATHSTATE) == 0 &&
-			launch_data_get_type(obj) == LAUNCH_DATA_DICTIONARY) {
-		launch_data_dict_iterate(obj, semaphoreitem_setup_paths, j);
-	} else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBSTATE) == 0 &&
-			launch_data_get_type(obj) == LAUNCH_DATA_DICTIONARY) {
-		launch_data_dict_iterate(obj, semaphoreitem_setup_otherjobs, j);
+		launch_data_dict_iterate(obj, semaphoreitem_setup_dict_iter, &sdic);
+		break;
+	default:
+		job_assumes(j, false);
+		break;
 	}
 }
 

Modified: trunk/launchd/src/liblaunch_public.h
===================================================================
--- trunk/launchd/src/liblaunch_public.h	2007-04-17 20:41:58 UTC (rev 23226)
+++ trunk/launchd/src/liblaunch_public.h	2007-04-18 16:05:52 UTC (rev 23227)
@@ -108,7 +108,8 @@
 #define LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT	"SuccessfulExit"
 #define LAUNCH_JOBKEY_KEEPALIVE_NETWORKSTATE	"NetworkState"
 #define LAUNCH_JOBKEY_KEEPALIVE_PATHSTATE	"PathState"
-#define LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBSTATE	"OtherJobState"
+#define LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBACTIVE	"OtherJobActive"
+#define LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBENABLED	"OtherJobEnabled"
 
 #define LAUNCH_JOBKEY_CAL_MINUTE		"Minute"
 #define LAUNCH_JOBKEY_CAL_HOUR			"Hour"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070418/630873f8/attachment.html


More information about the launchd-changes mailing list