[launchd-changes] [23842] branches/PR-6564965/launchd/src/launchctl.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Feb 26 18:34:46 PST 2009
Revision: 23842
http://trac.macosforge.org/projects/launchd/changeset/23842
Author: dsorresso at apple.com
Date: 2009-02-26 18:34:46 -0800 (Thu, 26 Feb 2009)
Log Message:
-----------
Adjusted the "-w" option for load and unload to write to the override database.
Modified Paths:
--------------
branches/PR-6564965/launchd/src/launchctl.c
Modified: branches/PR-6564965/launchd/src/launchctl.c
===================================================================
--- branches/PR-6564965/launchd/src/launchctl.c 2009-02-27 00:43:16 UTC (rev 23841)
+++ branches/PR-6564965/launchd/src/launchctl.c 2009-02-27 02:34:46 UTC (rev 23842)
@@ -104,6 +104,7 @@
#define assumes(e) \
(__builtin_expect(!(e), 0) ? _log_launchctl_bug(__rcs_file_version__, __FILE__, __LINE__, #e), false : true)
+#define CFTypeCheck(cf, type) (CFGetTypeID(cf) == type ## GetTypeID())
struct load_unload_state {
launch_data_t pass0;
@@ -259,8 +260,9 @@
static bool rootuser_context;
static bool g_shutdown_debugging = false;
+static bool g_job_overrides_db_has_changed = false;
+static CFDictionaryRef g_job_overrides_db = NULL;
char g_job_overrides_db_path[PATH_MAX];
-CFDictionaryRef g_job_overrides_db = NULL;
int
main(int argc, char *const argv[])
@@ -710,15 +712,13 @@
void
job_override(CFTypeRef key, CFTypeRef val, CFMutableDictionaryRef job)
{
- if( CFGetTypeID(key) != CFStringGetTypeID() ) {
+ if( !CFTypeCheck(key, CFString) ) {
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);
}
@@ -734,25 +734,34 @@
}
CFStringRef label = CFDictionaryGetValue(plist, CFSTR(LAUNCH_JOBKEY_LABEL));
- if( g_job_overrides_db && label && CFGetTypeID(label) == CFStringGetTypeID() ) {
+ if( g_job_overrides_db && label && CFTypeCheck(label, CFString) ) {
CFDictionaryRef overrides = CFDictionaryGetValue(g_job_overrides_db, label);
- if( overrides ) {
+ if( overrides && CFTypeCheck(label, CFDictionary) ) {
CFDictionaryApplyFunction(overrides, (CFDictionaryApplierFunction)job_override, (void *)plist);
}
}
if (editondisk) {
- if (load) {
- CFDictionaryRemoveValue((CFMutableDictionaryRef)plist, CFSTR(LAUNCH_JOBKEY_DISABLED));
+ if( g_job_overrides_db ) {
+ CFMutableDictionaryRef job = (CFMutableDictionaryRef)CFDictionaryGetValue(g_job_overrides_db, label);
+ if( job && CFTypeCheck(job, CFDictionary) ) {
+ CFDictionarySetValue(job, CFSTR(LAUNCH_JOBKEY_DISABLED), load ? kCFBooleanFalse : kCFBooleanTrue);
+ g_job_overrides_db_has_changed = true;
+ }
} else {
- CFDictionarySetValue((CFMutableDictionaryRef)plist, CFSTR(LAUNCH_JOBKEY_DISABLED), kCFBooleanTrue);
+ if (load) {
+ CFDictionaryRemoveValue((CFMutableDictionaryRef)plist, CFSTR(LAUNCH_JOBKEY_DISABLED));
+ } else {
+ CFDictionarySetValue((CFMutableDictionaryRef)plist, CFSTR(LAUNCH_JOBKEY_DISABLED), kCFBooleanTrue);
+ }
+ WriteMyPropertyListToFile(plist, file);
}
- WriteMyPropertyListToFile(plist, file);
}
r = CF2launch_data(plist);
CFRelease(plist);
+ CFReleaseIfNotNULL(label);
return r;
}
@@ -2296,6 +2305,10 @@
}
}
+ if( g_job_overrides_db ) {
+ WriteMyPropertyListToFile(g_job_overrides_db, g_job_overrides_db_path);
+ }
+
return 0;
}
@@ -3581,7 +3594,7 @@
{ _PATH_TMP, 0, 0, S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO, S_ISUID|S_ISGID, true },
{ _PATH_VARTMP, 0, 0, S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO, S_ISUID|S_ISGID, true },
{ "/var/folders", 0, 0, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH, S_ISUID | S_ISGID, true },
- { LAUNCHD_JOB_OVERRIDES_DB_PREFIX, 0, 0, S_IRWXU, S_IRWXG | S_IRWXO, true }
+ { LAUNCHD_JOB_OVERRIDES_DB_PREFIX, 0, 0, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH, S_IRWXG | S_IRWXO, true }
};
struct stat sb;
size_t i;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/launchd-changes/attachments/20090226/21ae6bbc/attachment-0001.html>
More information about the launchd-changes
mailing list