[launchd-changes] [23835] branches/PR-6564965/launchd/src
source_changes at macosforge.org
source_changes at macosforge.org
Thu Feb 26 15:32:14 PST 2009
Revision: 23835
http://trac.macosforge.org/projects/launchd/changeset/23835
Author: dsorresso at apple.com
Date: 2009-02-26 15:32:14 -0800 (Thu, 26 Feb 2009)
Log Message:
-----------
Changed to using plists for databases.
Modified Paths:
--------------
branches/PR-6564965/launchd/src/launch_internal.h
branches/PR-6564965/launchd/src/launchctl.c
branches/PR-6564965/launchd/src/launchd.c
branches/PR-6564965/launchd/src/launchd.h
branches/PR-6564965/launchd/src/launchd_core_logic.c
Modified: branches/PR-6564965/launchd/src/launch_internal.h
===================================================================
--- branches/PR-6564965/launchd/src/launch_internal.h 2009-02-26 19:12:16 UTC (rev 23834)
+++ branches/PR-6564965/launchd/src/launch_internal.h 2009-02-26 23:32:14 UTC (rev 23835)
@@ -22,9 +22,6 @@
#pragma GCC visibility push(default)
-#define LAUNCHD_JOB_STATE_DB_PREFIX "/var/db/launchd_job_state_db"
-extern char g_job_enabled_db[PATH_MAX];
-
size_t launch_data_pack(launch_data_t d, void *where, size_t len, int *fd_where, size_t *fdslotsleft);
launch_data_t launch_data_unpack(void *data, size_t data_size, int *fds, size_t fd_cnt, size_t *data_offset, size_t *fdoffset);
Modified: branches/PR-6564965/launchd/src/launchctl.c
===================================================================
--- branches/PR-6564965/launchd/src/launchctl.c 2009-02-26 19:12:16 UTC (rev 23834)
+++ branches/PR-6564965/launchd/src/launchctl.c 2009-02-26 23:32:14 UTC (rev 23835)
@@ -113,6 +113,7 @@
};
static void myCFDictionaryApplyFunction(const void *key, const void *value, void *context);
+static void job_override(CFTypeRef key, CFTypeRef val, CFMutableDictionaryRef job);
static CFTypeRef CFTypeCreateFromLaunchData(launch_data_t obj);
static CFArrayRef CFArrayCreateFromLaunchArray(launch_data_t arr);
static CFDictionaryRef CFDictionaryCreateFromLaunchDictionary(launch_data_t dict);
@@ -257,7 +258,8 @@
static bool rootuser_context;
static bool g_shutdown_debugging = false;
-char g_job_enabled_db[PATH_MAX];
+char g_job_overrides_db_path[PATH_MAX];
+CFDictionaryRef g_job_overrides_db = NULL;
int
main(int argc, char *const argv[])
@@ -340,10 +342,12 @@
vproc_err_t verr = vproc_swap_string(NULL, VPROC_GSK_JOB_ENABLED_DB, NULL, &db);
if( verr ) {
fprintf(stderr, "Could not get location of job state database.\n");
- g_job_enabled_db[0] = 0;
+ g_job_overrides_db_path[0] = 0;
} else {
- strncpy(g_job_enabled_db, db, strlen(db));
+ strncpy(g_job_overrides_db_path, db, strlen(db));
free(db);
+
+ g_job_overrides_db = (CFDictionaryRef)CreateMyPropertyListFromFile(g_job_overrides_db_path);
}
if (NULL == readline) {
@@ -702,6 +706,21 @@
}
}
+void
+job_override(CFTypeRef key, CFTypeRef val, CFMutableDictionaryRef job)
+{
+ if( CFGetTypeID(key) != CFStringGetTypeID() ) {
+ return;
+ }
+ if( CFStringCompare(key, CFSTR(LAUNCH_JOBKEY_LABEL), kCFCompareCaseInsensitive) == 0 ) {
+ return;
+ }
+
+ fprintf(stdout, "Overriding %s in %s...\n", CFStringGetCStringPtr(key, kCFStringEncodingUTF8), CFStringGetCStringPtr(CFDictionaryGetValue(job, CFSTR(LAUNCH_JOBKEY_LABEL)), kCFStringEncodingUTF8));
+
+ CFDictionarySetValue(job, key, val);
+}
+
launch_data_t
read_plist_file(const char *file, bool editondisk, bool load)
{
@@ -713,6 +732,14 @@
return NULL;
}
+ CFStringRef label = CFDictionaryGetValue(plist, CFSTR(LAUNCH_JOBKEY_LABEL));
+ if( label && CFGetTypeID(label) == CFStringGetTypeID() ) {
+ CFDictionaryRef overrides = CFDictionaryGetValue(g_job_overrides_db, label);
+ if( overrides ) {
+ CFDictionaryApplyFunction(overrides, (CFDictionaryApplierFunction)job_override, (void *)plist);
+ }
+ }
+
if (editondisk) {
if (load) {
CFDictionaryRemoveValue((CFMutableDictionaryRef)plist, CFSTR(LAUNCH_JOBKEY_DISABLED));
@@ -931,38 +958,18 @@
job_disabled_logic(launch_data_t obj)
{
bool r = false;
-
+
switch (launch_data_get_type(obj)) {
- case LAUNCH_DATA_DICTIONARY: {
- launch_data_t label = NULL;
- if( (label = launch_data_dict_lookup(obj, LAUNCH_JOBKEY_LABEL)) && launch_data_get_type(label) == LAUNCH_DATA_STRING ) {
- bool disabled = false;
- launch_data_t disabled_data = launch_data_dict_lookup(obj, LAUNCH_JOBKEY_DISABLED);
-
- if( disabled_data && launch_data_get_type(disabled_data) == LAUNCH_DATA_BOOL ) {
- disabled = launch_data_get_bool(disabled_data);
- }
-
- if( disabled && g_job_enabled_db[0] != 0 ) {
- char path[PATH_MAX];
- snprintf(path, sizeof(path), "%s/%s", g_job_enabled_db, launch_data_get_string(label));
-
- struct stat sb;
- r = stat(path, &sb) == -1;
- }
- } else {
+ case LAUNCH_DATA_DICTIONARY:
launch_data_dict_iterate(obj, job_disabled_dict_logic, &r);
- }
-
- break;
+ break;
+ case LAUNCH_DATA_BOOL:
+ r = launch_data_get_bool(obj);
+ break;
+ default:
+ break;
}
- case LAUNCH_DATA_BOOL:
- r = launch_data_get_bool(obj);
- break;
- default:
- break;
- }
-
+
return r;
}
Modified: branches/PR-6564965/launchd/src/launchd.c
===================================================================
--- branches/PR-6564965/launchd/src/launchd.c 2009-02-26 19:12:16 UTC (rev 23834)
+++ branches/PR-6564965/launchd/src/launchd.c 2009-02-26 23:32:14 UTC (rev 23835)
@@ -116,7 +116,7 @@
bool fake_shutdown_in_progress;
bool network_up;
char g_username[128] = "__Uninitialized__";
-char g_job_enabled_db[PATH_MAX];
+char g_job_overrides_db_path[PATH_MAX];
FILE *g_console = NULL;
int
@@ -188,7 +188,7 @@
strlcpy(g_username, pwent->pw_name, sizeof(g_username) - 1);
}
- snprintf(g_job_enabled_db, sizeof(g_job_enabled_db), LAUNCHD_JOB_STATE_DB_PREFIX "/com.apple.launchd.peruser.%u", getuid());
+ snprintf(g_job_overrides_db_path, sizeof(g_job_overrides_db_path), LAUNCHD_JOB_OVERRIDES_DB_PREFIX "/com.apple.launchd.peruser.%u/overrides.plist", getuid());
runtime_syslog(LOG_DEBUG, "Per-user launchd for UID %u (%s) has begun.", getuid(), g_username);
}
@@ -403,10 +403,10 @@
launchd_assumes(chdir("/") != -1);
launchd_assumes(setlogin("root") != -1);
- strcpy(g_job_enabled_db, LAUNCHD_JOB_STATE_DB_PREFIX "/com.apple.launchd");
+ strcpy(g_job_overrides_db_path, LAUNCHD_JOB_OVERRIDES_DB_PREFIX "/com.apple.launchd/overrides.plist");
struct stat sb;
- if( stat(g_job_enabled_db, &sb) == -1 ) {
- launchd_assumes(mkdir(g_job_enabled_db, S_IRWXO) != -1);
+ if( stat(g_job_overrides_db_path, &sb) == -1 && launchd_assumes(errno == ENOENT) ) {
+ launchd_assumes(mkdir(g_job_overrides_db_path, S_IRWXO) != -1);
}
}
Modified: branches/PR-6564965/launchd/src/launchd.h
===================================================================
--- branches/PR-6564965/launchd/src/launchd.h 2009-02-26 19:12:16 UTC (rev 23834)
+++ branches/PR-6564965/launchd/src/launchd.h 2009-02-26 23:32:14 UTC (rev 23835)
@@ -26,6 +26,8 @@
#include "bootstrap.h"
#include "launchd_runtime.h"
+#define LAUNCHD_JOB_OVERRIDES_DB_PREFIX "/var/db/launchd_job_overrides"
+
struct kevent;
struct conncb;
@@ -35,6 +37,7 @@
extern bool g_force_old_kill_path;
extern bool g_simulate_pid1_crash;
extern FILE *g_console;
+extern char g_job_overrides_db_path[PATH_MAX];
bool init_check_pid(pid_t);
Modified: branches/PR-6564965/launchd/src/launchd_core_logic.c
===================================================================
--- branches/PR-6564965/launchd/src/launchd_core_logic.c 2009-02-26 19:12:16 UTC (rev 23834)
+++ branches/PR-6564965/launchd/src/launchd_core_logic.c 2009-02-26 23:32:14 UTC (rev 23835)
@@ -3216,7 +3216,7 @@
}
if( j->clean_kill ) {
- job_log(j, LOG_DEBUG | LOG_CONSOLE, "Clean job failed to exit %u seconds after receiving SIGKILL.", LAUNCHD_CLEAN_KILL_TIMER);
+ job_log(j, LOG_DEBUG | LOG_CONSOLE, "Clean job failed to exit %u second after receiving SIGKILL.", LAUNCHD_CLEAN_KILL_TIMER);
job_assumes(j, kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, EV_DELETE, 0, 0, NULL));
j->clean_exit_timer_expired = true;
@@ -3241,7 +3241,7 @@
uint64_t td = runtime_get_nanoseconds_since(j->sent_signal_time);
td /= NSEC_PER_SEC;
- td -= j->exit_timeout;
+ td -= j->clean_kill ? 0 : j->exit_timeout;
job_log(j, LOG_WARNING | LOG_CONSOLE, "Did not die after sending SIGKILL %llu seconds ago...", td);
} else if( should_enqueue && (!j->exit_timeout || (LAUNCHD_SAMPLE_TIMEOUT < j->exit_timeout)) ) {
@@ -5406,7 +5406,7 @@
continue;
}
- bool active = job_active(ji);
+ bool active = ji->p;
if( active && !ji->stopped ) {
/* If the job is active and we haven't told it to stop yet, stop it. */
job_stop(ji);
@@ -5466,7 +5466,7 @@
continue;
}
- bool active = job_active(ji);
+ bool active = ji->p;
if( active && !ji->stopped ) {
/* If the job is active and we haven't told it to stop yet, stop it. */
job_stop(ji);
@@ -5528,7 +5528,7 @@
continue;
}
- bool active = job_active(ji);
+ bool active = ji->p;
if( active && !ji->stopped ) {
/* If the job is active and we haven't told it to stop yet, stop it. */
job_stop(ji);
@@ -6861,7 +6861,7 @@
launch_data_free(output_obj);
break;
case VPROC_GSK_JOB_ENABLED_DB:
- if( !g_job_enabled_db || (g_job_enabled_db && !(output_obj = launch_data_new_string(g_job_enabled_db))) ) {
+ if( !(output_obj = launch_data_new_string(g_job_overrides_db_path)) ) {
goto out_bad;
}
packed_size = launch_data_pack(output_obj, (void *)*outval, *outvalCnt, NULL, NULL);
@@ -7078,45 +7078,45 @@
g_shutdown_debugging = true;
}
break;
- case VPROC_GSK_PERUSER_SUSPEND:
- if( pid1_magic && ldc->euid == 0 ) {
- mach_port_t junk = MACH_PORT_NULL;
- job_t jpu = jobmgr_lookup_per_user_context_internal(j, (uid_t)inval, false, &junk);
- if( jpu ) {
- job_t ji = NULL;
- LIST_FOREACH( ji, &j->suspended_perusers, suspended_peruser_sle ) {
- if( (int64_t)(ji->mach_uid) == inval ) {
- job_log(j, LOG_WARNING, "Job tried to suspend per-user launchd for UID %u twice.", ji->mach_uid);
- break;
- }
- }
-
- if( ji == NULL ) {
- jpu->peruser_suspend_count++;
- LIST_INSERT_HEAD(&j->suspended_perusers, jpu, suspended_peruser_sle);
- job_stop(jpu);
- }
- }
- }
- break;
- case VPROC_GSK_PERUSER_RESUME:
- if( pid1_magic && ldc->euid == 0 ) {
- job_t ji = NULL, jt = NULL;
- LIST_FOREACH_SAFE( ji, &j->suspended_perusers, suspended_peruser_sle, jt ) {
+ case VPROC_GSK_PERUSER_SUSPEND:
+ if( pid1_magic && ldc->euid == 0 ) {
+ mach_port_t junk = MACH_PORT_NULL;
+ job_t jpu = jobmgr_lookup_per_user_context_internal(j, (uid_t)inval, false, &junk);
+ if( jpu ) {
+ job_t ji = NULL;
+ LIST_FOREACH( ji, &j->suspended_perusers, suspended_peruser_sle ) {
if( (int64_t)(ji->mach_uid) == inval ) {
- ji->peruser_suspend_count--;
- LIST_REMOVE(ji, suspended_peruser_sle);
+ job_log(j, LOG_WARNING, "Job tried to suspend per-user launchd for UID %u twice.", ji->mach_uid);
break;
}
}
if( ji == NULL ) {
- job_log(j, LOG_WARNING, "Job tried to resume per-user launchd for UID %llu that it did not suspend.", inval);
- } else if( ji->peruser_suspend_count == 0 ) {
- job_dispatch(ji, false);
+ jpu->peruser_suspend_count++;
+ LIST_INSERT_HEAD(&j->suspended_perusers, jpu, suspended_peruser_sle);
+ job_stop(jpu);
}
}
- break;
+ }
+ break;
+ case VPROC_GSK_PERUSER_RESUME:
+ if( pid1_magic && ldc->euid == 0 ) {
+ job_t ji = NULL, jt = NULL;
+ LIST_FOREACH_SAFE( ji, &j->suspended_perusers, suspended_peruser_sle, jt ) {
+ if( (int64_t)(ji->mach_uid) == inval ) {
+ ji->peruser_suspend_count--;
+ LIST_REMOVE(ji, suspended_peruser_sle);
+ break;
+ }
+ }
+
+ if( ji == NULL ) {
+ job_log(j, LOG_WARNING, "Job tried to resume per-user launchd for UID %llu that it did not suspend.", inval);
+ } else if( ji->peruser_suspend_count == 0 ) {
+ job_dispatch(ji, false);
+ }
+ }
+ break;
case 0:
break;
default:
@@ -7283,7 +7283,7 @@
struct stat sb;
char pu_db[PATH_MAX];
- snprintf(pu_db, sizeof(pu_db), LAUNCHD_JOB_STATE_DB_PREFIX "/%s", lbuf);
+ snprintf(pu_db, sizeof(pu_db), LAUNCHD_JOB_OVERRIDES_DB_PREFIX "/%s", lbuf);
if( stat(pu_db, &sb) == -1 && job_assumes(ji, errno == ENOENT) ) {
job_assumes(ji, mkdir(pu_db, S_IRWXO) != -1);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/launchd-changes/attachments/20090226/4ad12a87/attachment-0001.html>
More information about the launchd-changes
mailing list