From source_changes at macosforge.org Mon Mar 2 14:45:26 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Mon, 2 Mar 2009 14:45:26 -0800 (PST) Subject: [launchd-changes] [23851] branches/PR-6564965/launchd/src Message-ID: <20090302224526.EEE481111BC1@beta.macosforge.org> Revision: 23851 http://trac.macosforge.org/projects/launchd/changeset/23851 Author: dsorresso at apple.com Date: 2009-03-02 14:45:26 -0800 (Mon, 02 Mar 2009) Log Message: ----------- More generalization of the job databases. Modified Paths: -------------- 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 branches/PR-6564965/launchd/src/vproc_priv.h Modified: branches/PR-6564965/launchd/src/launchctl.c =================================================================== --- branches/PR-6564965/launchd/src/launchctl.c 2009-02-28 21:16:59 UTC (rev 23850) +++ branches/PR-6564965/launchd/src/launchctl.c 2009-03-02 22:45:26 UTC (rev 23851) @@ -262,8 +262,14 @@ static bool g_job_overrides_db_has_changed = false; static CFMutableDictionaryRef g_job_overrides_db = NULL; -char g_job_overrides_db_path[PATH_MAX]; +static char g_job_overrides_db_path[PATH_MAX]; +#if 0 +static bool g_job_cache_db_has_changed = false; +static launch_data_t g_job_cache_db = NULL; +#endif +static char g_job_cache_db_path[PATH_MAX]; + int main(int argc, char *const argv[]) { @@ -344,7 +350,7 @@ char *db = NULL; vproc_err_t verr = vproc_swap_string(NULL, VPROC_GSK_JOB_OVERRIDES_DB, NULL, &db); if( verr ) { - fprintf(stderr, "Could not get location of job state database.\n"); + fprintf(stderr, "Could not get location of job overrides database.\n"); g_job_overrides_db_path[0] = 0; } else { strncpy(g_job_overrides_db_path, db, strlen(db)); @@ -356,6 +362,17 @@ } } + verr = vproc_swap_string(NULL, VPROC_GSK_JOB_CACHE_DB, NULL, &db); + if( verr ) { + fprintf(stderr, "Could not get location of job cache database.\n"); + g_job_cache_db_path[0] = 0; + } else { + strncpy(g_job_cache_db_path, db, strlen(db)); + free(db); + + /* Create our launch_data_t from the file... */ + } + if (NULL == readline) { fprintf(stderr, "missing library: readline\n"); exit(EXIT_FAILURE); Modified: branches/PR-6564965/launchd/src/launchd.c =================================================================== --- branches/PR-6564965/launchd/src/launchd.c 2009-02-28 21:16:59 UTC (rev 23850) +++ branches/PR-6564965/launchd/src/launchd.c 2009-03-02 22:45:26 UTC (rev 23851) @@ -117,7 +117,7 @@ bool fake_shutdown_in_progress; bool network_up; char g_username[128] = "__Uninitialized__"; -char g_job_overrides_db_path[PATH_MAX]; +char g_launchd_database_dir[PATH_MAX]; FILE *g_console = NULL; int @@ -189,7 +189,7 @@ strlcpy(g_username, pwent->pw_name, sizeof(g_username) - 1); } - snprintf(g_job_overrides_db_path, sizeof(g_job_overrides_db_path), LAUNCHD_DB_PREFIX "/com.apple.launchd.peruser.%u/overrides.plist", getuid()); + snprintf(g_launchd_database_dir, sizeof(g_launchd_database_dir), LAUNCHD_DB_PREFIX "/com.apple.launchd.peruser.%u", getuid()); runtime_syslog(LOG_DEBUG, "Per-user launchd for UID %u (%s) has begun.", getuid(), g_username); } @@ -404,9 +404,34 @@ launchd_assumes(chdir("/") != -1); launchd_assumes(setlogin("root") != -1); - strcpy(g_job_overrides_db_path, LAUNCHD_DB_PREFIX "/com.apple.launchd/overrides.plist"); + strcpy(g_launchd_database_dir, LAUNCHD_DB_PREFIX "/com.apple.launchd"); } +char * +launchd_data_base_path(int db_type) +{ + static char result[PATH_MAX]; + static int last_db_type = -1; + + if( db_type == last_db_type ) { + return result; + } + + switch( db_type ) { + case LAUNCHD_DB_TYPE_OVERRIDES : + snprintf(result, sizeof(result), "%s/%s", g_launchd_database_dir, "overrides.plist"); + last_db_type = db_type; + break; + case LAUNCHD_DB_TYPE_JOBCACHE : + snprintf(result, sizeof(result), "%s/%s", g_launchd_database_dir, "jobcache.launchdata"); + last_db_type = db_type; + break; + default : + break; + } + + return result; +} int _fd(int fd) Modified: branches/PR-6564965/launchd/src/launchd.h =================================================================== --- branches/PR-6564965/launchd/src/launchd.h 2009-02-28 21:16:59 UTC (rev 23850) +++ branches/PR-6564965/launchd/src/launchd.h 2009-03-02 22:45:26 UTC (rev 23851) @@ -35,7 +35,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]; +extern char g_launchd_database_dir[PATH_MAX]; bool init_check_pid(pid_t); @@ -45,6 +45,13 @@ void launchd_single_user(void); boolean_t launchd_mach_ipc_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply); +enum { + LAUNCHD_DB_TYPE_OVERRIDES, + LAUNCHD_DB_TYPE_JOBCACHE, + LAUNCHD_DB_TYPE_LAST, +}; +char *launchd_data_base_path(int db_type); + void mach_start_shutdown(void); int _fd(int fd); Modified: branches/PR-6564965/launchd/src/launchd_core_logic.c =================================================================== --- branches/PR-6564965/launchd/src/launchd_core_logic.c 2009-02-28 21:16:59 UTC (rev 23850) +++ branches/PR-6564965/launchd/src/launchd_core_logic.c 2009-03-02 22:45:26 UTC (rev 23851) @@ -6867,7 +6867,7 @@ launch_data_free(output_obj); break; case VPROC_GSK_JOB_OVERRIDES_DB: - if( !job_assumes(j, (output_obj = launch_data_new_string(g_job_overrides_db_path)) != NULL) ) { + if( !job_assumes(j, (output_obj = launch_data_new_string(launchd_data_base_path(LAUNCHD_DB_TYPE_OVERRIDES))) != NULL) ) { goto out_bad; } packed_size = launch_data_pack(output_obj, (void *)*outval, *outvalCnt, NULL, NULL); @@ -6877,6 +6877,17 @@ launch_data_free(output_obj); break; + case VPROC_GSK_JOB_CACHE_DB: + if( !job_assumes(j, (output_obj = launch_data_new_string(launchd_data_base_path(LAUNCHD_DB_TYPE_JOBCACHE))) != NULL) ) { + goto out_bad; + } + packed_size = launch_data_pack(output_obj, (void *)*outval, *outvalCnt, NULL, NULL); + if (!job_assumes(j, packed_size != 0)) { + goto out_bad; + } + + launch_data_free(output_obj); + break; case 0: mig_deallocate(*outval, *outvalCnt); *outval = 0; Modified: branches/PR-6564965/launchd/src/vproc_priv.h =================================================================== --- branches/PR-6564965/launchd/src/vproc_priv.h 2009-02-28 21:16:59 UTC (rev 23850) +++ branches/PR-6564965/launchd/src/vproc_priv.h 2009-03-02 22:45:26 UTC (rev 23851) @@ -65,6 +65,7 @@ VPROC_GSK_PERUSER_SUSPEND, VPROC_GSK_PERUSER_RESUME, VPROC_GSK_JOB_OVERRIDES_DB, + VPROC_GSK_JOB_CACHE_DB, } vproc_gsk_t; typedef unsigned int vproc_flags_t; -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Mon Mar 2 21:21:25 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Mon, 2 Mar 2009 21:21:25 -0800 (PST) Subject: [launchd-changes] [23852] trunk Message-ID: <20090303052125.73F891116C34@beta.macosforge.org> Revision: 23852 http://trac.macosforge.org/projects/launchd/changeset/23852 Author: dsorresso at apple.com Date: 2009-03-02 21:21:24 -0800 (Mon, 02 Mar 2009) Log Message: ----------- Merged in latest changes from trunk. Modified Paths: -------------- trunk/launchd/src/launch_internal.h trunk/launchd/src/launchctl.c trunk/launchd/src/launchd.c trunk/launchd/src/launchd.h trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/libvproc.c trunk/launchd/src/vproc_priv.h Property Changed: ---------------- trunk/ trunk/launchd/src/bootstrap.h trunk/launchd/src/bootstrap_priv.h trunk/launchd/src/launch.h trunk/launchd/src/launch_internal.h trunk/launchd/src/launch_priv.h trunk/launchd/src/protocol_vproc.defs trunk/launchd/src/vproc.h trunk/launchd/src/vproc_internal.h trunk/launchd/src/vproc_priv.h Property changes on: trunk ___________________________________________________________________ Modified: svn:mergeinfo - /branches/PR-5092682:23731-23742 /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 /branches/PR-6132016:23719-23738 /branches/PR-6271234:23818-23822 /branches/PR-6562592:23812-23822 /branches/PR-6589133:23810-23822 /branches/PR-6609410:23828 + /branches/PR-5092682:23731-23742 /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 /branches/PR-6132016:23719-23738 /branches/PR-6271234:23818-23822 /branches/PR-6562592:23812-23822 /branches/PR-6564965:23832-23851 /branches/PR-6589133:23810-23822 /branches/PR-6609410:23828 Property changes on: trunk/launchd/src/bootstrap.h ___________________________________________________________________ Modified: svn:mergeinfo - /branches/PR-5898404/launchd/src/libbootstrap_public.h:23681-23700 /branches/PR-5978442/launchd/src/libbootstrap_public.h:23651-23701 /branches/PR-6271234/launchd/src/bootstrap.h:23818-23822 /branches/PR-6562592/launchd/src/bootstrap.h:23812-23822 /branches/PR-6589133/launchd/src/bootstrap.h:23810-23822 /branches/PR-6609410/launchd/src/bootstrap.h:23828 + /branches/PR-5898404/launchd/src/libbootstrap_public.h:23681-23700 /branches/PR-5978442/launchd/src/libbootstrap_public.h:23651-23701 /branches/PR-6271234/launchd/src/bootstrap.h:23818-23822 /branches/PR-6562592/launchd/src/bootstrap.h:23812-23822 /branches/PR-6564965/launchd/src/bootstrap.h:23832-23851 /branches/PR-6589133/launchd/src/bootstrap.h:23810-23822 /branches/PR-6609410/launchd/src/bootstrap.h:23828 Property changes on: trunk/launchd/src/bootstrap_priv.h ___________________________________________________________________ Modified: svn:mergeinfo - /branches/PR-5898404/launchd/src/libbootstrap_private.h:23681-23700 /branches/PR-5978442/launchd/src/libbootstrap_private.h:23651-23701 /branches/PR-6271234/launchd/src/bootstrap_priv.h:23818-23822 /branches/PR-6562592/launchd/src/bootstrap_priv.h:23812-23822 /branches/PR-6589133/launchd/src/bootstrap_priv.h:23810-23822 /branches/PR-6609410/launchd/src/bootstrap_priv.h:23828 + /branches/PR-5898404/launchd/src/libbootstrap_private.h:23681-23700 /branches/PR-5978442/launchd/src/libbootstrap_private.h:23651-23701 /branches/PR-6271234/launchd/src/bootstrap_priv.h:23818-23822 /branches/PR-6562592/launchd/src/bootstrap_priv.h:23812-23822 /branches/PR-6564965/launchd/src/bootstrap_priv.h:23832-23851 /branches/PR-6589133/launchd/src/bootstrap_priv.h:23810-23822 /branches/PR-6609410/launchd/src/bootstrap_priv.h:23828 Property changes on: trunk/launchd/src/launch.h ___________________________________________________________________ Modified: svn:mergeinfo - /branches/PR-5898404/launchd/src/liblaunch_public.h:23681-23700 /branches/PR-5978442/launchd/src/liblaunch_public.h:23651-23701 /branches/PR-6271234/launchd/src/launch.h:23818-23822 /branches/PR-6562592/launchd/src/launch.h:23812-23822 /branches/PR-6589133/launchd/src/launch.h:23810-23822 /branches/PR-6609410/launchd/src/launch.h:23828 + /branches/PR-5898404/launchd/src/liblaunch_public.h:23681-23700 /branches/PR-5978442/launchd/src/liblaunch_public.h:23651-23701 /branches/PR-6271234/launchd/src/launch.h:23818-23822 /branches/PR-6562592/launchd/src/launch.h:23812-23822 /branches/PR-6564965/launchd/src/launch.h:23832-23851 /branches/PR-6589133/launchd/src/launch.h:23810-23822 /branches/PR-6609410/launchd/src/launch.h:23828 Modified: trunk/launchd/src/launch_internal.h =================================================================== --- trunk/launchd/src/launch_internal.h 2009-03-02 22:45:26 UTC (rev 23851) +++ trunk/launchd/src/launch_internal.h 2009-03-03 05:21:24 UTC (rev 23852) @@ -22,6 +22,8 @@ #pragma GCC visibility push(default) +#define LAUNCHD_DB_PREFIX "/var/db/launchd.db" + 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); Property changes on: trunk/launchd/src/launch_internal.h ___________________________________________________________________ Modified: svn:mergeinfo - /branches/PR-5898404/launchd/src/liblaunch_internal.h:23681-23700 /branches/PR-5978442/launchd/src/liblaunch_internal.h:23651-23701 /branches/PR-6271234/launchd/src/launch_internal.h:23818-23822 /branches/PR-6562592/launchd/src/launch_internal.h:23812-23822 /branches/PR-6589133/launchd/src/launch_internal.h:23810-23822 /branches/PR-6609410/launchd/src/launch_internal.h:23828 + /branches/PR-5898404/launchd/src/liblaunch_internal.h:23681-23700 /branches/PR-5978442/launchd/src/liblaunch_internal.h:23651-23701 /branches/PR-6271234/launchd/src/launch_internal.h:23818-23822 /branches/PR-6562592/launchd/src/launch_internal.h:23812-23822 /branches/PR-6564965/launchd/src/launch_internal.h:23832-23851 /branches/PR-6589133/launchd/src/launch_internal.h:23810-23822 /branches/PR-6609410/launchd/src/launch_internal.h:23828 Property changes on: trunk/launchd/src/launch_priv.h ___________________________________________________________________ Modified: svn:mergeinfo - /branches/PR-5898404/launchd/src/liblaunch_private.h:23681-23700 /branches/PR-5978442/launchd/src/liblaunch_private.h:23651-23701 /branches/PR-6271234/launchd/src/launch_priv.h:23818-23822 /branches/PR-6562592/launchd/src/launch_priv.h:23812-23822 /branches/PR-6589133/launchd/src/launch_priv.h:23810-23822 /branches/PR-6609410/launchd/src/launch_priv.h:23828 + /branches/PR-5898404/launchd/src/liblaunch_private.h:23681-23700 /branches/PR-5978442/launchd/src/liblaunch_private.h:23651-23701 /branches/PR-6271234/launchd/src/launch_priv.h:23818-23822 /branches/PR-6562592/launchd/src/launch_priv.h:23812-23822 /branches/PR-6564965/launchd/src/launch_priv.h:23832-23851 /branches/PR-6589133/launchd/src/launch_priv.h:23810-23822 /branches/PR-6609410/launchd/src/launch_priv.h:23828 Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2009-03-02 22:45:26 UTC (rev 23851) +++ trunk/launchd/src/launchctl.c 2009-03-03 05:21:24 UTC (rev 23852) @@ -28,9 +28,11 @@ #include "vproc_priv.h" #include "vproc_internal.h" #include "bootstrap_priv.h" +#include "launch_internal.h" #include #include +#include #include #if HAVE_SECURITY #include @@ -103,6 +105,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; @@ -113,6 +116,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); @@ -259,6 +263,16 @@ static bool bootstrapping_peruser; static bool g_shutdown_debugging = false; +static bool g_job_overrides_db_has_changed = false; +static CFMutableDictionaryRef g_job_overrides_db = NULL; +static char g_job_overrides_db_path[PATH_MAX]; + +#if 0 +static bool g_job_cache_db_has_changed = false; +static launch_data_t g_job_cache_db = NULL; +#endif +static char g_job_cache_db_path[PATH_MAX]; + int main(int argc, char *const argv[]) { @@ -336,6 +350,32 @@ } } + char *db = NULL; + vproc_err_t verr = vproc_swap_string(NULL, VPROC_GSK_JOB_OVERRIDES_DB, NULL, &db); + if( verr ) { + fprintf(stderr, "Could not get location of job overrides database.\n"); + g_job_overrides_db_path[0] = 0; + } else { + strncpy(g_job_overrides_db_path, db, strlen(db)); + free(db); + + g_job_overrides_db = (CFMutableDictionaryRef)CreateMyPropertyListFromFile(g_job_overrides_db_path); + if( !g_job_overrides_db ) { + g_job_overrides_db = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + } + } + + verr = vproc_swap_string(NULL, VPROC_GSK_JOB_CACHE_DB, NULL, &db); + if( verr ) { + fprintf(stderr, "Could not get location of job cache database.\n"); + g_job_cache_db_path[0] = 0; + } else { + strncpy(g_job_cache_db_path, db, strlen(db)); + free(db); + + /* Create our launch_data_t from the file... */ + } + if (NULL == readline) { fprintf(stderr, "missing library: readline\n"); exit(EXIT_FAILURE); @@ -692,24 +732,58 @@ } } +void +job_override(CFTypeRef key, CFTypeRef val, CFMutableDictionaryRef job) +{ + if( !CFTypeCheck(key, CFString) ) { + return; + } + if( CFStringCompare(key, CFSTR(LAUNCH_JOBKEY_LABEL), kCFCompareCaseInsensitive) == 0 ) { + return; + } + + CFDictionarySetValue(job, key, val); +} + launch_data_t read_plist_file(const char *file, bool editondisk, bool load) { CFPropertyListRef plist = CreateMyPropertyListFromFile(file); launch_data_t r = NULL; - if (NULL == plist) { + if( NULL == plist ) { fprintf(stderr, "%s: no plist was returned for: %s\n", getprogname(), file); return NULL; } - if (editondisk) { - if (load) { - CFDictionaryRemoveValue((CFMutableDictionaryRef)plist, CFSTR(LAUNCH_JOBKEY_DISABLED)); + CFStringRef label = CFDictionaryGetValue(plist, CFSTR(LAUNCH_JOBKEY_LABEL)); + if( g_job_overrides_db && label && CFTypeCheck(label, CFString) ) { + CFDictionaryRef overrides = CFDictionaryGetValue(g_job_overrides_db, label); + if( overrides && CFTypeCheck(overrides, CFDictionary) ) { + CFDictionaryApplyFunction(overrides, (CFDictionaryApplierFunction)job_override, (void *)plist); + } + } + + if( editondisk ) { + if( g_job_overrides_db ) { + CFMutableDictionaryRef job = (CFMutableDictionaryRef)CFDictionaryGetValue(g_job_overrides_db, label); + if( !job || !CFTypeCheck(job, CFDictionary) ) { + job = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + CFDictionarySetValue(g_job_overrides_db, label, job); + CFRelease(job); + } + + CFDictionarySetValue(job, CFSTR(LAUNCH_JOBKEY_DISABLED), load ? kCFBooleanFalse : kCFBooleanTrue); + CFDictionarySetValue((CFMutableDictionaryRef)plist, 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); @@ -929,18 +1003,18 @@ job_disabled_logic(launch_data_t obj) { bool r = false; - + switch (launch_data_get_type(obj)) { - case LAUNCH_DATA_DICTIONARY: - launch_data_dict_iterate(obj, job_disabled_dict_logic, &r); - break; - case LAUNCH_DATA_BOOL: - r = launch_data_get_bool(obj); - break; - default: - break; + case LAUNCH_DATA_DICTIONARY: + launch_data_dict_iterate(obj, job_disabled_dict_logic, &r); + break; + case LAUNCH_DATA_BOOL: + r = launch_data_get_bool(obj); + break; + default: + break; } - + return r; } @@ -1399,7 +1473,7 @@ fprintf(stderr, "%s: CFURLCreateDataAndPropertiesFromResource(%s) failed: %d\n", getprogname(), posixfile, (int)errorCode); } - propertyList = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resourceData, kCFPropertyListMutableContainers, &errorString); + propertyList = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resourceData, kCFPropertyListMutableContainersAndLeaves, &errorString); if (!propertyList) { fprintf(stderr, "%s: propertyList is NULL\n", getprogname()); } @@ -2268,6 +2342,10 @@ } } + if( g_job_overrides_db_has_changed ) { + WriteMyPropertyListToFile(g_job_overrides_db, g_job_overrides_db_path); + } + return 0; } @@ -2951,7 +3029,7 @@ CFTypeRef value = NULL; do { io_registry_entry_t entry = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/options"); - if( assumes(entry == IO_OBJECT_NULL) ) { + if( assumes(entry != IO_OBJECT_NULL) ) { break; } @@ -3553,6 +3631,8 @@ { _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_DB_PREFIX, 0, 0, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH, S_IWGRP | S_IWOTH, true }, + { LAUNCHD_DB_PREFIX "/com.apple.launchd", 0, 0, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH, S_IWGRP | S_IWOTH, true } }; struct stat sb; size_t i; Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2009-03-02 22:45:26 UTC (rev 23851) +++ trunk/launchd/src/launchd.c 2009-03-03 05:21:24 UTC (rev 23852) @@ -81,6 +81,7 @@ #include "vproc_priv.h" #include "vproc_internal.h" #include "launch.h" +#include "launch_internal.h" #include "launchd_runtime.h" #include "launchd_core_logic.h" @@ -118,6 +119,7 @@ bool network_up; char g_username[128] = "__Uninitialized__"; char g_my_label[128] = "__Uninitialized__"; +char g_launchd_database_dir[PATH_MAX]; FILE *g_console = NULL; int @@ -188,7 +190,7 @@ if( pwent ) { strlcpy(g_username, pwent->pw_name, sizeof(g_username) - 1); } - + snprintf(g_my_label, sizeof(g_my_label), "com.apple.launchd.peruser.%u", getuid()); auditinfo_addr_t auinfo; @@ -198,6 +200,7 @@ } g_audit_session_port = _audit_session_self(); + snprintf(g_launchd_database_dir, sizeof(g_launchd_database_dir), LAUNCHD_DB_PREFIX "/com.apple.launchd.peruser.%u", getuid()); runtime_syslog(LOG_DEBUG, "Per-user launchd for UID %u (%s) has begun.", getuid(), g_username); } @@ -206,12 +209,8 @@ if( g_use_gmalloc ) { runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "*** Using libgmalloc ***"); } - - struct stat sb; - if( stat("/var/db/.launchd_flat_per_user_namespace", &sb) == 0 ) { - runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "Flat per-user Mach namespaces enabled."); - } - /* We just wanted to print status about the per-user namespace. PID 1 doesn't have a flat namespace. */ + + /* PID 1 doesn't have a flat namespace. */ g_flat_mach_namespace = false; } @@ -437,8 +436,36 @@ g_audit_session_port = _audit_session_self(); #endif + + strcpy(g_launchd_database_dir, LAUNCHD_DB_PREFIX "/com.apple.launchd"); } +char * +launchd_data_base_path(int db_type) +{ + static char result[PATH_MAX]; + static int last_db_type = -1; + + if( db_type == last_db_type ) { + return result; + } + + switch( db_type ) { + case LAUNCHD_DB_TYPE_OVERRIDES : + snprintf(result, sizeof(result), "%s/%s", g_launchd_database_dir, "overrides.plist"); + last_db_type = db_type; + break; + case LAUNCHD_DB_TYPE_JOBCACHE : + snprintf(result, sizeof(result), "%s/%s", g_launchd_database_dir, "jobcache.launchdata"); + last_db_type = db_type; + break; + default : + break; + } + + return result; +} + int _fd(int fd) { Modified: trunk/launchd/src/launchd.h =================================================================== --- trunk/launchd/src/launchd.h 2009-03-02 22:45:26 UTC (rev 23851) +++ trunk/launchd/src/launchd.h 2009-03-03 05:21:24 UTC (rev 23852) @@ -35,6 +35,7 @@ extern bool g_force_old_kill_path; extern bool g_simulate_pid1_crash; extern FILE *g_console; +extern char g_launchd_database_dir[PATH_MAX]; bool init_check_pid(pid_t); @@ -44,6 +45,13 @@ void launchd_single_user(void); boolean_t launchd_mach_ipc_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply); +enum { + LAUNCHD_DB_TYPE_OVERRIDES, + LAUNCHD_DB_TYPE_JOBCACHE, + LAUNCHD_DB_TYPE_LAST, +}; +char *launchd_data_base_path(int db_type); + void mach_start_shutdown(void); int _fd(int fd); Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-03-02 22:45:26 UTC (rev 23851) +++ trunk/launchd/src/launchd_core_logic.c 2009-03-03 05:21:24 UTC (rev 23852) @@ -3255,7 +3255,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; @@ -3280,7 +3280,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)) ) { @@ -5434,7 +5434,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); @@ -5494,7 +5494,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); @@ -5556,7 +5556,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); @@ -5601,6 +5601,12 @@ jobmgr_do_garbage_collection(jmi); } + if( SLIST_EMPTY(&jm->submgrs) ) { + jobmgr_log(jm, LOG_DEBUG, "No submanagers left."); + } else { + jobmgr_log(jm, LOG_DEBUG, "Still have submanagers."); + } + jobmgr_t _jm = jobmgr_do_hopefully_first_shutdown_phase(jm); if( !_jm ) { _jm = jobmgr_do_normal_shutdown_phase(jm) ? : jobmgr_do_hopefully_last_shutdown_phase(jm); @@ -6890,6 +6896,28 @@ launch_data_free(output_obj); break; + case VPROC_GSK_JOB_OVERRIDES_DB: + if( !job_assumes(j, (output_obj = launch_data_new_string(launchd_data_base_path(LAUNCHD_DB_TYPE_OVERRIDES))) != NULL) ) { + goto out_bad; + } + packed_size = launch_data_pack(output_obj, (void *)*outval, *outvalCnt, NULL, NULL); + if (!job_assumes(j, packed_size != 0)) { + goto out_bad; + } + + launch_data_free(output_obj); + break; + case VPROC_GSK_JOB_CACHE_DB: + if( !job_assumes(j, (output_obj = launch_data_new_string(launchd_data_base_path(LAUNCHD_DB_TYPE_JOBCACHE))) != NULL) ) { + goto out_bad; + } + packed_size = launch_data_pack(output_obj, (void *)*outval, *outvalCnt, NULL, NULL); + if (!job_assumes(j, packed_size != 0)) { + goto out_bad; + } + + launch_data_free(output_obj); + break; case 0: mig_deallocate(*outval, *outvalCnt); *outval = 0; @@ -7098,45 +7126,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: @@ -7309,6 +7337,28 @@ ji->per_user = true; ji->kill_via_shmem = true; + struct stat sb; + char pu_db[PATH_MAX]; + snprintf(pu_db, sizeof(pu_db), LAUNCHD_DB_PREFIX "/%s", lbuf); + + int err = -1; + if( (err = stat(pu_db, &sb)) == -1 && job_assumes(ji, errno == ENOENT) ) { + job_assumes(ji, mkdir(pu_db, S_IRWXU) != -1); + job_assumes(ji, (err = stat(pu_db, &sb)) != -1); + } + + if( err != -1 ) { + if( !job_assumes(ji, sb.st_uid == which_user) ) { + job_assumes(ji, chown(pu_db, which_user, 0) != -1); + } + if( !job_assumes(ji, sb.st_gid == 0) ) { + job_assumes(ji, chown(pu_db, which_user, 0) != -1); + } + if( !job_assumes(ji, sb.st_mode == S_IRWXU) ) { + job_assumes(ji, chmod(pu_db, S_IRWXU) != -1); + } + } + if ((ms = machservice_new(ji, lbuf, mp, false)) == NULL) { job_remove(ji); ji = NULL; Modified: trunk/launchd/src/libvproc.c =================================================================== --- trunk/launchd/src/libvproc.c 2009-03-02 22:45:26 UTC (rev 23851) +++ trunk/launchd/src/libvproc.c 2009-03-03 05:21:24 UTC (rev 23852) @@ -855,21 +855,20 @@ /* Once you're in the transaction model, you're in for good. Like the Mafia. */ s_cached_transactions_enabled = 1; break; - case VPROC_GSK_PERUSER_SUSPEND: - { - char peruser_label[NAME_MAX]; - snprintf(peruser_label, NAME_MAX - 1, "com.apple.launchd.peruser.%u", (uid_t)*inval); + case VPROC_GSK_PERUSER_SUSPEND: { + char peruser_label[NAME_MAX]; + snprintf(peruser_label, NAME_MAX - 1, "com.apple.launchd.peruser.%u", (uid_t)*inval); + + vproc_t pu_vp = vprocmgr_lookup_vproc(peruser_label); + if( pu_vp ) { + int status = 0; + kern_return_t kr = vproc_mig_wait2(bootstrap_port, pu_vp->j_port, &status); + vproc_release(pu_vp); - vproc_t pu_vp = vprocmgr_lookup_vproc(peruser_label); - if( pu_vp ) { - int status = 0; - kern_return_t kr = vproc_mig_wait2(bootstrap_port, pu_vp->j_port, &status); - vproc_release(pu_vp); - - syslog(LOG_DEBUG, "%u's suspended launchd exited with status %i (kr = 0x%x).", (uid_t)*inval, status, kr); - } + syslog(LOG_DEBUG, "%u's suspended launchd exited with status %i (kr = 0x%x).", (uid_t)*inval, status, kr); } break; + } default: break; } Property changes on: trunk/launchd/src/protocol_vproc.defs ___________________________________________________________________ Modified: svn:mergeinfo - /branches/PR-5092682/launchd/src/protocol_job.defs:23731-23742 /branches/PR-5898404/launchd/src/protocol_job.defs:23681-23700 /branches/PR-5978442/launchd/src/protocol_job.defs:23651-23701 /branches/PR-6132016/launchd/src/protocol_job.defs:23719-23738 /branches/PR-6271234/launchd/src/protocol_vproc.defs:23818-23822 /branches/PR-6562592/launchd/src/protocol_vproc.defs:23812-23822 /branches/PR-6589133/launchd/src/protocol_vproc.defs:23810-23822 /branches/PR-6609410/launchd/src/protocol_vproc.defs:23828 + /branches/PR-5092682/launchd/src/protocol_job.defs:23731-23742 /branches/PR-5898404/launchd/src/protocol_job.defs:23681-23700 /branches/PR-5978442/launchd/src/protocol_job.defs:23651-23701 /branches/PR-6132016/launchd/src/protocol_job.defs:23719-23738 /branches/PR-6271234/launchd/src/protocol_vproc.defs:23818-23822 /branches/PR-6562592/launchd/src/protocol_vproc.defs:23812-23822 /branches/PR-6564965/launchd/src/protocol_vproc.defs:23832-23851 /branches/PR-6589133/launchd/src/protocol_vproc.defs:23810-23822 /branches/PR-6609410/launchd/src/protocol_vproc.defs:23828 Property changes on: trunk/launchd/src/vproc.h ___________________________________________________________________ Modified: svn:mergeinfo - /branches/PR-5092682/launchd/src/libvproc_public.h:23731-23742 /branches/PR-5898404/launchd/src/libvproc_public.h:23681-23700 /branches/PR-5978442/launchd/src/libvproc_public.h:23651-23701 /branches/PR-6132016/launchd/src/libvproc_public.h:23719-23738 /branches/PR-6271234/launchd/src/vproc.h:23818-23822 /branches/PR-6562592/launchd/src/vproc.h:23812-23822 /branches/PR-6589133/launchd/src/vproc.h:23810-23822 /branches/PR-6609410/launchd/src/vproc.h:23828 + /branches/PR-5092682/launchd/src/libvproc_public.h:23731-23742 /branches/PR-5898404/launchd/src/libvproc_public.h:23681-23700 /branches/PR-5978442/launchd/src/libvproc_public.h:23651-23701 /branches/PR-6132016/launchd/src/libvproc_public.h:23719-23738 /branches/PR-6271234/launchd/src/vproc.h:23818-23822 /branches/PR-6562592/launchd/src/vproc.h:23812-23822 /branches/PR-6564965/launchd/src/vproc.h:23832-23851 /branches/PR-6589133/launchd/src/vproc.h:23810-23822 /branches/PR-6609410/launchd/src/vproc.h:23828 Property changes on: trunk/launchd/src/vproc_internal.h ___________________________________________________________________ Modified: svn:mergeinfo - /branches/PR-5898404/launchd/src/libvproc_internal.h:23681-23700 /branches/PR-5978442/launchd/src/libvproc_internal.h:23651-23701 /branches/PR-6271234/launchd/src/vproc_internal.h:23818-23822 /branches/PR-6562592/launchd/src/vproc_internal.h:23812-23822 /branches/PR-6589133/launchd/src/vproc_internal.h:23810-23822 /branches/PR-6609410/launchd/src/vproc_internal.h:23828 + /branches/PR-5898404/launchd/src/libvproc_internal.h:23681-23700 /branches/PR-5978442/launchd/src/libvproc_internal.h:23651-23701 /branches/PR-6271234/launchd/src/vproc_internal.h:23818-23822 /branches/PR-6562592/launchd/src/vproc_internal.h:23812-23822 /branches/PR-6564965/launchd/src/vproc_internal.h:23832-23851 /branches/PR-6589133/launchd/src/vproc_internal.h:23810-23822 /branches/PR-6609410/launchd/src/vproc_internal.h:23828 Modified: trunk/launchd/src/vproc_priv.h =================================================================== --- trunk/launchd/src/vproc_priv.h 2009-03-02 22:45:26 UTC (rev 23851) +++ trunk/launchd/src/vproc_priv.h 2009-03-03 05:21:24 UTC (rev 23852) @@ -66,6 +66,8 @@ VPROC_GSK_SHUTDOWN_DEBUGGING, VPROC_GSK_PERUSER_SUSPEND, VPROC_GSK_PERUSER_RESUME, + VPROC_GSK_JOB_OVERRIDES_DB, + VPROC_GSK_JOB_CACHE_DB, } vproc_gsk_t; typedef unsigned int vproc_flags_t; Property changes on: trunk/launchd/src/vproc_priv.h ___________________________________________________________________ Modified: svn:mergeinfo - /branches/PR-5092682/launchd/src/libvproc_private.h:23731-23742 /branches/PR-5898404/launchd/src/libvproc_private.h:23681-23700 /branches/PR-5978442/launchd/src/libvproc_private.h:23651-23701 /branches/PR-6132016/launchd/src/libvproc_private.h:23719-23738 /branches/PR-6271234/launchd/src/vproc_priv.h:23818-23822 /branches/PR-6562592/launchd/src/vproc_priv.h:23812-23822 /branches/PR-6589133/launchd/src/vproc_priv.h:23810-23822 /branches/PR-6609410/launchd/src/vproc_priv.h:23828 + /branches/PR-5092682/launchd/src/libvproc_private.h:23731-23742 /branches/PR-5898404/launchd/src/libvproc_private.h:23681-23700 /branches/PR-5978442/launchd/src/libvproc_private.h:23651-23701 /branches/PR-6132016/launchd/src/libvproc_private.h:23719-23738 /branches/PR-6271234/launchd/src/vproc_priv.h:23818-23822 /branches/PR-6562592/launchd/src/vproc_priv.h:23812-23822 /branches/PR-6564965/launchd/src/vproc_priv.h:23832-23851 /branches/PR-6589133/launchd/src/vproc_priv.h:23810-23822 /branches/PR-6609410/launchd/src/vproc_priv.h:23828 -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Mon Mar 9 17:16:40 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Mon, 9 Mar 2009 17:16:40 -0700 (PDT) Subject: [launchd-changes] [23853] trunk/launchd/src Message-ID: <20090310001641.090AA1186FD4@beta.macosforge.org> Revision: 23853 http://trac.macosforge.org/projects/launchd/changeset/23853 Author: dsorresso at apple.com Date: 2009-03-09 17:16:39 -0700 (Mon, 09 Mar 2009) Log Message: ----------- MNT: Attempting to unmount volumes one by one fails without an error Modified Paths: -------------- trunk/launchd/src/launch_priv.h trunk/launchd/src/launchctl.c trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/libbootstrap.c Modified: trunk/launchd/src/launch_priv.h =================================================================== --- trunk/launchd/src/launch_priv.h 2009-03-03 05:21:24 UTC (rev 23852) +++ trunk/launchd/src/launch_priv.h 2009-03-10 00:16:39 UTC (rev 23853) @@ -61,6 +61,8 @@ #define LAUNCH_JOBKEY_JETSAMPRIORITY "JetsamPriority" #define LAUNCH_JOBKEY_SECURITYSESSIONUUID "SecuritySessionUUID" +#define LAUNCH_JOBKEY_EMBEDDEDSHUTDOWNAUTHORITY "EmbeddedShutdownAuthority" + #define LAUNCH_JOBKEY_ENTERKERNELDEBUGGERBEFOREKILL "EnterKernelDebuggerBeforeKill" #define LAUNCH_JOBKEY_PERJOBMACHSERVICES "PerJobMachServices" #define LAUNCH_JOBKEY_SERVICEIPC "ServiceIPC" Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2009-03-03 05:21:24 UTC (rev 23852) +++ trunk/launchd/src/launchctl.c 2009-03-10 00:16:39 UTC (rev 23853) @@ -270,8 +270,8 @@ #if 0 static bool g_job_cache_db_has_changed = false; static launch_data_t g_job_cache_db = NULL; -#endif static char g_job_cache_db_path[PATH_MAX]; +#endif int main(int argc, char *const argv[]) @@ -325,7 +325,7 @@ int64_t manager_uid = -1, manager_pid = -1; if( vproc_swap_integer(NULL, VPROC_GSK_MGR_UID, NULL, &manager_uid) == NULL ) { if( vproc_swap_integer(NULL, VPROC_GSK_MGR_PID, NULL, &manager_pid) == NULL ) { - if( manager_uid || manager_uid == 1 ) { + if( manager_uid || manager_pid == 1 ) { fprintf(stderr, "Running in the root user's per-user context is not supported outside of the root user's bootstrap.\n"); exit(EXIT_FAILURE); } @@ -350,32 +350,6 @@ } } - char *db = NULL; - vproc_err_t verr = vproc_swap_string(NULL, VPROC_GSK_JOB_OVERRIDES_DB, NULL, &db); - if( verr ) { - fprintf(stderr, "Could not get location of job overrides database.\n"); - g_job_overrides_db_path[0] = 0; - } else { - strncpy(g_job_overrides_db_path, db, strlen(db)); - free(db); - - g_job_overrides_db = (CFMutableDictionaryRef)CreateMyPropertyListFromFile(g_job_overrides_db_path); - if( !g_job_overrides_db ) { - g_job_overrides_db = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - } - } - - verr = vproc_swap_string(NULL, VPROC_GSK_JOB_CACHE_DB, NULL, &db); - if( verr ) { - fprintf(stderr, "Could not get location of job cache database.\n"); - g_job_cache_db_path[0] = 0; - } else { - strncpy(g_job_cache_db_path, db, strlen(db)); - free(db); - - /* Create our launch_data_t from the file... */ - } - if (NULL == readline) { fprintf(stderr, "missing library: readline\n"); exit(EXIT_FAILURE); @@ -2120,7 +2094,7 @@ char *load_launchd_items[] = { "load", "-S", session_type, "-D", "all", NULL, NULL, NULL, NULL, NULL, NULL }; int the_argc = 5; - char *load_launchd_items_user[] = { "load", "-S", session_type, "-D", "user", NULL }; + char *load_launchd_items_user[] = { "load", "-S", VPROCMGR_SESSION_BACKGROUND, "-D", "user", NULL }; int the_argc_user = 0; if (is_safeboot()) { @@ -2137,35 +2111,17 @@ if (strcasecmp(session_type, VPROCMGR_SESSION_LOGINWINDOW) == 0) { load_launchd_items[the_argc] = "/etc/mach_init_per_login_session.d"; the_argc += 1; - } else { - #if 0 - /* If we're a per-user launchd initializing our Background session, - * don't forget about the user's launchd jobs that may be specified as - * LimitLoadToSessionType = Background. We also - * must keep in mind that we need to load the user jobs last, since the - * jobs in the local sessions may be responsible for mounting the home - * directory. - */ - if( getppid() != 1 ) { - the_argc_user = 5; - } - #else - /* This deadlocks against mount_url when logging in with a network home - * directory. For now, we'll just load user Background agents when - * bootstrapping the Aqua or StandardIO sessions. This way, we can - * safely assume that the home directory is present. Yes it's a hack, - * but it satisfies the user expectation in 99% of cases. - */ - if( 0 ) { - the_argc_user = 5; - } - #endif } } else if (strcasecmp(session_type, VPROCMGR_SESSION_AQUA) == 0) { load_launchd_items[5] = "/etc/mach_init_per_user.d"; the_argc += 1; - /* If we're bootstrapping the Aqua session, bootstrap the user's Background - * agents. + /* For now, we'll just load user Background agents when + * bootstrapping the Aqua session. This way, we can + * safely assume that the home directory is present. If + * we try reading the user's Background agents when we're + * actually bootstrapping the Background session, we run the + * risk of deadlocking against mount_url. But this fix should + * satisfy . */ the_argc_user = 5; @@ -2180,11 +2136,6 @@ * problem. */ read_environment_dot_plist(); - } else if (strcasecmp(session_type, VPROCMGR_SESSION_AQUA) == 0) { - /* If we're bootstrapping the StandardIO session, bootstrap the user's Background - * agents. - */ - the_argc_user = 5; } if (strcasecmp(session_type, VPROCMGR_SESSION_BACKGROUND) == 0) { @@ -2198,13 +2149,10 @@ int retval = load_and_unload_cmd(the_argc, load_launchd_items); if( retval == 0 && the_argc_user != 0 ) { optind = 1; - pid_t p = getpid(); - if( sysctlbyname("vfs.generic.noremotehang", NULL, NULL, &p, sizeof(p)) == 0 ) { - int64_t junk = 0; - vproc_err_t err = vproc_swap_integer(NULL, VPROC_GSK_WEIRD_BOOTSTRAP, &junk, NULL); - if( !err ) { - retval = load_and_unload_cmd(the_argc_user, load_launchd_items_user); - } + int64_t junk = 0; + vproc_err_t err = vproc_swap_integer(NULL, VPROC_GSK_WEIRD_BOOTSTRAP, &junk, NULL); + if( !err ) { + retval = load_and_unload_cmd(the_argc_user, load_launchd_items_user); } } @@ -2278,6 +2226,28 @@ return 1; } + int dbfd = -1; + char *db = NULL; + vproc_err_t verr = vproc_swap_string(NULL, VPROC_GSK_JOB_OVERRIDES_DB, NULL, &db); + if( verr ) { + fprintf(stderr, "Could not get location of job overrides database.\n"); + g_job_overrides_db_path[0] = 0; + } else { + strncpy(g_job_overrides_db_path, db, strlen(db)); + free(db); + + /* If we can't create or lock the overrides database, we'll fall back to writing to the + * plist file directly. + */ + assumes((dbfd = open(db, O_RDONLY | O_EXLOCK | O_CREAT, S_IRUSR | S_IWUSR)) != -1); + if( dbfd != -1 ) { + g_job_overrides_db = (CFMutableDictionaryRef)CreateMyPropertyListFromFile(g_job_overrides_db_path); + if( !g_job_overrides_db ) { + g_job_overrides_db = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + } + } + } + /* I wish I didn't need to do three passes, but I need to load mDNSResponder and use it too. * And loading legacy mach init jobs is extra fun. * @@ -2345,7 +2315,9 @@ if( g_job_overrides_db_has_changed ) { WriteMyPropertyListToFile(g_job_overrides_db, g_job_overrides_db_path); } - + + flock(dbfd, LOCK_UN); + close(dbfd); return 0; } @@ -3029,7 +3001,7 @@ CFTypeRef value = NULL; do { io_registry_entry_t entry = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/options"); - if( assumes(entry != IO_OBJECT_NULL) ) { + if( !assumes(entry != IO_OBJECT_NULL) ) { break; } Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-03-03 05:21:24 UTC (rev 23852) +++ trunk/launchd/src/launchd_core_logic.c 2009-03-10 00:16:39 UTC (rev 23853) @@ -527,6 +527,7 @@ is_bootstrapper :1, /* The job is a bootstrapper. */ has_console :1, /* The job owns the console. */ clean_exit_timer_expired :1, /* The job was clean, received SIGKILL and failed to exit after LAUNCHD_CLEAN_KILL_TIMER seconds. */ + embedded_shutdown_auth :1, /* The job is allowed to call reboot2() on embedded. */ migratory :1; /* The (anonymous) job called vprocmgr_switch_to_session(). */ mode_t mask; pid_t tracing_pid; @@ -642,6 +643,7 @@ #else pid_t g_audit_session = 0; #endif +static bool s_embedded_shutdown_right_claimed = false; static pid_t s_update_pid = 0; static int s_no_hang_fd = -1; @@ -1686,6 +1688,9 @@ } else if (strcasecmp(key, LAUNCH_JOBKEY_ENTERKERNELDEBUGGERBEFOREKILL) == 0) { j->debug_before_kill = value; found_key = true; + } else if( !s_embedded_shutdown_right_claimed && strcasecmp(key, LAUNCH_JOBKEY_EMBEDDEDSHUTDOWNAUTHORITY) == 0 ) { + j->embedded_shutdown_auth = true; + s_embedded_shutdown_right_claimed = true; } break; case 'w': @@ -3512,6 +3517,8 @@ switch (c = runtime_fork(j->weird_bootstrap ? j->j_port : j->mgr->jm_port)) { case -1: job_log_error(j, LOG_ERR, "fork() failed, will try again in one second"); + job_assumes(j, kevent_mod((uintptr_t)j, EVFILT_TIMER, EV_ADD|EV_ONESHOT, NOTE_SECONDS, 1, j) != -1); + job_assumes(j, runtime_close(execspair[0]) == 0); job_assumes(j, runtime_close(execspair[1]) == 0); if (sipc) { @@ -7242,7 +7249,11 @@ return BOOTSTRAP_NOT_PRIVILEGED; } - if (unlikely(ldc->euid)) { +#if !TARGET_OS_EMBEDDED + if( unlikely(ldc->euid) ) { +#else + if( unlikely(ldc->euid) && !j->embedded_shutdown_auth ) { +#endif return BOOTSTRAP_NOT_PRIVILEGED; } Modified: trunk/launchd/src/libbootstrap.c =================================================================== --- trunk/launchd/src/libbootstrap.c 2009-03-03 05:21:24 UTC (rev 23852) +++ trunk/launchd/src/libbootstrap.c 2009-03-10 00:16:39 UTC (rev 23853) @@ -179,21 +179,21 @@ static mach_port_t prev_bp; static mach_port_t prev_sp; static name_t prev_name; - static bool privileged_server_okay; audit_token_t au_tok; bool per_pid_lookup = flags & BOOTSTRAP_PER_PID_SERVICE; + bool privileged_server_lookup = flags & BOOTSTRAP_PRIVILEGED_SERVER; kern_return_t kr = 0; mach_port_t puc; - + pthread_mutex_lock(&bslu2_lock); - - if (per_pid_lookup) { + + if (per_pid_lookup || privileged_server_lookup) { goto skip_cache; } - + if (prev_sp) { if ((bp == prev_bp) && (strncmp(prev_name, service_name, sizeof(name_t)) == 0) - && (mach_port_mod_refs(mach_task_self(), prev_sp, MACH_PORT_RIGHT_SEND, 1) == 0)) { + && (mach_port_mod_refs(mach_task_self(), prev_sp, MACH_PORT_RIGHT_SEND, 1) == 0)) { *sp = prev_sp; goto out; } else { @@ -201,49 +201,45 @@ prev_sp = 0; } } - + skip_cache: - privileged_server_okay = false; if ((kr = vproc_mig_look_up2(bp, (char *)service_name, sp, &au_tok, target_pid, flags)) != VPROC_ERR_TRY_PER_USER) { goto out; } - + if ((kr = vproc_mig_lookup_per_user_context(bp, 0, &puc)) != 0) { goto out; } - + kr = vproc_mig_look_up2(puc, (char *)service_name, sp, &au_tok, target_pid, flags); mach_port_deallocate(mach_task_self(), puc); - + out: - if (!per_pid_lookup && kr == 0 && prev_sp == 0 && mach_port_mod_refs(mach_task_self(), *sp, MACH_PORT_RIGHT_SEND, 1) == 0) { + if (!(per_pid_lookup || privileged_server_lookup) && kr == 0 && prev_sp == 0 && mach_port_mod_refs(mach_task_self(), *sp, MACH_PORT_RIGHT_SEND, 1) == 0) { /* We're going to hold on to a send right as a MRU cache */ prev_bp = bp; prev_sp = *sp; strlcpy(prev_name, service_name, sizeof(name_t)); } - - if ((kr == 0) && (flags & BOOTSTRAP_PRIVILEGED_SERVER) && !privileged_server_okay) { + + if ((kr == 0) && privileged_server_lookup) { uid_t server_euid; - + /* * The audit token magic is dependent on the per-user launchd * forwarding MIG requests to the root launchd when it cannot * find the answer locally. */ - + /* This API should be in Libsystem, but is not */ //audit_token_to_au32(au_tok, NULL, &server_euid, NULL, NULL, NULL, NULL, NULL, NULL); server_euid = au_tok.val[1]; - + if (server_euid) { mach_port_deallocate(mach_task_self(), *sp); kr = BOOTSTRAP_NOT_PRIVILEGED; - } else { - privileged_server_okay = true; } - } /* If performance becomes a problem, we should restructure this. */ pthread_mutex_unlock(&bslu2_lock); -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Mon Mar 9 17:16:52 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Mon, 9 Mar 2009 17:16:52 -0700 (PDT) Subject: [launchd-changes] [23854] tags/launchd-303/ Message-ID: <20090310001652.1875F1186FED@beta.macosforge.org> Revision: 23854 http://trac.macosforge.org/projects/launchd/changeset/23854 Author: dsorresso at apple.com Date: 2009-03-09 17:16:51 -0700 (Mon, 09 Mar 2009) Log Message: ----------- "Tagging launchd-303 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-303/ Property changes on: tags/launchd-303 ___________________________________________________________________ Added: svn:ignore + build Added: svn:mergeinfo + /branches/PR-5092682:23731-23742 /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 /branches/PR-6132016:23719-23738 /branches/PR-6271234:23818-23822 /branches/PR-6562592:23812-23822 /branches/PR-6564965:23832-23851 /branches/PR-6589133:23810-23822 /branches/PR-6609410:23828 -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Mon Mar 9 18:21:53 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Mon, 9 Mar 2009 18:21:53 -0700 (PDT) Subject: [launchd-changes] [23855] trunk/launchd/src/launchctl.c Message-ID: <20090310012153.7C46111879D5@beta.macosforge.org> Revision: 23855 http://trac.macosforge.org/projects/launchd/changeset/23855 Author: dsorresso at apple.com Date: 2009-03-09 18:21:52 -0700 (Mon, 09 Mar 2009) Log Message: ----------- Fixed a premature free(). Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2009-03-10 00:16:51 UTC (rev 23854) +++ trunk/launchd/src/launchctl.c 2009-03-10 01:21:52 UTC (rev 23855) @@ -2234,7 +2234,6 @@ g_job_overrides_db_path[0] = 0; } else { strncpy(g_job_overrides_db_path, db, strlen(db)); - free(db); /* If we can't create or lock the overrides database, we'll fall back to writing to the * plist file directly. @@ -2246,6 +2245,7 @@ g_job_overrides_db = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } } + free(db); } /* I wish I didn't need to do three passes, but I need to load mDNSResponder and use it too. -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Mon Mar 9 18:22:02 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Mon, 9 Mar 2009 18:22:02 -0700 (PDT) Subject: [launchd-changes] [23856] tags/launchd-303.1/ Message-ID: <20090310012202.B89C711879EE@beta.macosforge.org> Revision: 23856 http://trac.macosforge.org/projects/launchd/changeset/23856 Author: dsorresso at apple.com Date: 2009-03-09 18:22:02 -0700 (Mon, 09 Mar 2009) Log Message: ----------- "Tagging launchd-303.1 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-303.1/ Property changes on: tags/launchd-303.1 ___________________________________________________________________ Added: svn:ignore + build Added: svn:mergeinfo + /branches/PR-5092682:23731-23742 /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 /branches/PR-6132016:23719-23738 /branches/PR-6271234:23818-23822 /branches/PR-6562592:23812-23822 /branches/PR-6564965:23832-23851 /branches/PR-6589133:23810-23822 /branches/PR-6609410:23828 -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Tue Mar 10 20:13:06 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 10 Mar 2009 20:13:06 -0700 (PDT) Subject: [launchd-changes] [23857] trunk Message-ID: <20090311031308.3983A119B601@beta.macosforge.org> Revision: 23857 http://trac.macosforge.org/projects/launchd/changeset/23857 Author: dsorresso at apple.com Date: 2009-03-10 20:13:03 -0700 (Tue, 10 Mar 2009) Log Message: ----------- File-based enabling/disabling mechanism for launchd jobs 10A278 - Hang at shutdown with 7 processes still running Modified Paths: -------------- trunk/launchd/src/launchctl.c trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c trunk/launchd.xcodeproj/project.pbxproj Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2009-03-10 01:22:02 UTC (rev 23856) +++ trunk/launchd/src/launchctl.c 2009-03-11 03:13:03 UTC (rev 23857) @@ -349,7 +349,7 @@ exit(EXIT_FAILURE); } } - + if (NULL == readline) { fprintf(stderr, "missing library: readline\n"); exit(EXIT_FAILURE); @@ -1448,9 +1448,6 @@ } propertyList = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, resourceData, kCFPropertyListMutableContainersAndLeaves, &errorString); - if (!propertyList) { - fprintf(stderr, "%s: propertyList is NULL\n", getprogname()); - } if( fileURL ) { CFRelease(fileURL); } @@ -2238,7 +2235,7 @@ /* If we can't create or lock the overrides database, we'll fall back to writing to the * plist file directly. */ - assumes((dbfd = open(db, O_RDONLY | O_EXLOCK | O_CREAT, S_IRUSR | S_IWUSR)) != -1); + assumes((dbfd = open(g_job_overrides_db_path, O_RDONLY | O_EXLOCK | O_CREAT, S_IRUSR | S_IWUSR)) != -1); if( dbfd != -1 ) { g_job_overrides_db = (CFMutableDictionaryRef)CreateMyPropertyListFromFile(g_job_overrides_db_path); if( !g_job_overrides_db ) { Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-03-10 01:22:02 UTC (rev 23856) +++ trunk/launchd/src/launchd_core_logic.c 2009-03-11 03:13:03 UTC (rev 23857) @@ -77,6 +77,7 @@ #include #include #include +#include #if HAVE_SANDBOX #define __APPLE_API_PRIVATE #include @@ -329,6 +330,20 @@ #define MACHSERVICE_HASH_SIZE 37 +enum { + JOBMGR_PHASE_HOPEFULLY_EXITS_FIRST, + JOBMGR_PHASE_NORMAL, + JOBMGR_PHASE_HOPEFULLY_EXITS_LAST, + JOBMGR_PHASE_LAST, +}; + +static char *s_phases[JOBMGR_PHASE_LAST + 1] = { + "HopefullyExitsFirst", + "Normal", + "HopefullyExitsLast", + "Finalized", +}; + struct jobmgr_s { kq_callback kqjobmgr_callback; SLIST_ENTRY(jobmgr_s) sle; @@ -344,6 +359,7 @@ mach_port_t init_audit_session; jobmgr_t parentmgr; int reboot_flags; + int shutdown_phase; unsigned int global_on_demand_cnt; unsigned int hopefully_first_cnt; unsigned int normal_active_cnt; @@ -353,6 +369,7 @@ killed_hopefully_first_jobs :1, killed_normal_jobs :1, killed_hopefully_last_jobs :1, + killed_stray_jobs :1, created_via_subset :1; char sample_log_file[PATH_MAX]; union { @@ -367,9 +384,6 @@ static jobmgr_t jobmgr_new(jobmgr_t jm, mach_port_t requestorport, mach_port_t transfer_port, bool sflag, const char *name, mach_port_t session_port); static job_t jobmgr_import2(jobmgr_t jm, launch_data_t pload); static jobmgr_t jobmgr_parent(jobmgr_t jm); -static jobmgr_t jobmgr_do_hopefully_first_shutdown_phase(jobmgr_t jm); -static jobmgr_t jobmgr_do_normal_shutdown_phase(jobmgr_t jm); -static jobmgr_t jobmgr_do_hopefully_last_shutdown_phase(jobmgr_t jm); static jobmgr_t jobmgr_do_garbage_collection(jobmgr_t jm); static bool jobmgr_label_test(jobmgr_t jm, const char *str); static void jobmgr_reap_bulk(jobmgr_t jm, struct kevent *kev); @@ -935,7 +949,7 @@ static void jobmgr_still_alive_with_check(jobmgr_t jm) { - jobmgr_log(jm, LOG_NOTICE | LOG_CONSOLE, "Still alive with %lu/%lu (normal/anonymous) children", total_children, total_anon_children); + jobmgr_log(jm, LOG_DEBUG | LOG_CONSOLE, "Still alive with %lu/%lu (normal/anonymous) children. In %s phase of shutdown.", total_children, total_anon_children, s_phases[jm->shutdown_phase]); jobmgr_log_active_jobs(jm); } @@ -1162,7 +1176,6 @@ } kevent_mod((uintptr_t)j, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); - kevent_mod((uintptr_t)j, EVFILT_PROC, EV_DELETE, 0, 0, NULL); LIST_REMOVE(j, sle); LIST_REMOVE(j, label_hash_sle); @@ -2568,7 +2581,7 @@ if (j->exit_timeout) { kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); } - + LIST_REMOVE(j, pid_hash_sle); if (j->wait_reply_port) { @@ -2700,10 +2713,6 @@ j->lastlookup_gennum = 0; j->p = 0; - if( !j->anonymous ) { - jobmgr_do_garbage_collection(j->mgr); - } - /* * We need to someday evaluate other jobs and find those who wish to track the * active/inactive state of this job. The current job_dispatch() logic makes @@ -2915,17 +2924,23 @@ void job_dispatch_curious_jobs(job_t j) { - job_t ji = NULL; - SLIST_FOREACH( ji, &s_curious_jobs, curious_jobs_sle ) { + job_t ji = NULL, jt = NULL; + SLIST_FOREACH_SAFE( ji, &s_curious_jobs, curious_jobs_sle, jt ) { struct semaphoreitem *si = NULL; SLIST_FOREACH( si, &ji->semaphores, sle ) { - if( si->why == OTHER_JOB_ENABLED || si->why == OTHER_JOB_DISABLED ) { - if( strncmp(si->what, j->label, strlen(j->label)) == 0 ) { - job_log(ji, LOG_NOTICE | LOG_CONSOLE, "Dispatching out of interest in \"%s\".", j->label); - job_assumes(ji, job_dispatch(ji, false) != NULL); - break; - } + if( !(si->why == OTHER_JOB_ENABLED || si->why == OTHER_JOB_DISABLED) ) { + continue; } + + if( strncmp(si->what, j->label, strlen(j->label)) == 0 ) { + job_log(ji, LOG_NOTICE | LOG_CONSOLE, "Dispatching out of interest in \"%s\".", j->label); + + job_dispatch(ji, false); + /* ji could be removed here, so don't do anything with it or its semaphores + * after this point. + */ + break; + } } } } @@ -2973,7 +2988,7 @@ } } } else { - job_log(j, LOG_DEBUG, "Tried to dispatch an already active job (%s), kickstart = %s.", job_active(j), kickstart ? "true" : "false"); + job_log(j, LOG_DEBUG, "Tried to dispatch an already active job (%s).", job_active(j)); } return j; @@ -3126,6 +3141,13 @@ /* Fake a kevent to keep our logic consistent. */ job_callback_proc(j, &kev); + + /* Normally, after getting a EVFILT_PROC event, we do garbage collection + * on the root job manager. To make our fakery complete, we will do garbage + * collection at the beginning of the next run loop cycle (after we're done + * draining the current queue of kevents). + */ + job_assumes(j, kevent_mod((uintptr_t)&root_jobmgr->reboot_flags, EVFILT_TIMER, EV_ADD | EV_ONESHOT, NOTE_NSECONDS, 1, root_jobmgr) != -1); } if( jm ) { @@ -3139,6 +3161,9 @@ bool program_changed = false; int fflags = kev->fflags; + job_log(j, LOG_DEBUG, "EVFILT_PROC event for job:"); + log_kevent_struct(LOG_DEBUG, kev, 0); + if( fflags & NOTE_EXIT ) { if( s_update_pid == (pid_t)kev->ident ) { int status = 0; @@ -3222,11 +3247,11 @@ if (fflags & NOTE_EXIT) { job_reap(j); - if (j->anonymous) { + if( !j->anonymous ) { + j = job_dispatch(j, false); + } else { job_remove(j); j = NULL; - } else { - j = job_dispatch(j, false); } } @@ -3354,7 +3379,7 @@ jobmgr_reap_bulk(jmi, kev); } - if ((j = jobmgr_find_by_pid(jm, (pid_t) kev->ident, false))) { + if ((j = jobmgr_find_by_pid(jm, (pid_t)kev->ident, false))) { kev->udata = j; job_callback(j, kev); } @@ -3414,6 +3439,8 @@ } else if( kev->ident == (uintptr_t)jm ) { jobmgr_log(jm, LOG_DEBUG, "Shutdown timer firing."); jobmgr_still_alive_with_check(jm); + } else if( kev->ident == (uintptr_t)&jm->reboot_flags ) { + jobmgr_do_garbage_collection(jm); } break; case EVFILT_VNODE: @@ -3425,6 +3452,20 @@ jobmgr_assumes(root_jobmgr, runtime_close(s_no_hang_fd) != -1); s_no_hang_fd = _fd(_no_hang_fd); } + } else if( kev->ident == (uintptr_t)fileno(g_console) ) { + int cfd = -1; + if( low_level_debug ) { + if( jobmgr_assumes(jm, (stdout = freopen(_PATH_CONSOLE, "w", stdout)) != NULL) ) { + cfd = fileno(stdout); + } + g_console = stdout; + } else { + if( jobmgr_assumes(jm, (g_console = freopen(_PATH_CONSOLE, "w", g_console)) != NULL) ) { + cfd = fileno(g_console); + } + } + jobmgr_assumes(jm, kevent_mod((uintptr_t)cfd, EVFILT_VNODE, EV_ADD | EV_ONESHOT, NOTE_REVOKE, 0, jm) != -1); + _fd(cfd); } break; default: @@ -5422,212 +5463,104 @@ } jobmgr_t -jobmgr_do_hopefully_first_shutdown_phase(jobmgr_t jm) +jobmgr_do_garbage_collection(jobmgr_t jm) { if( !jm->shutting_down ) { return jm; } - - if( jm->killed_hopefully_first_jobs ) { - return NULL; - } - - jobmgr_log(jm, LOG_DEBUG, "Doing first phase of garbage collection."); - uint32_t unkilled_cnt = 0; - job_t ji = NULL, jn = NULL; - LIST_FOREACH_SAFE( ji, &jm->jobs, sle, jn ) { - if( !ji->hopefully_exits_first ) { - continue; - } - - 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); - - /* We may have sent SIGKILL to the job in job_stop(). Clean jobs - * get 1 second to exit. - */ - if( !ji->clean_kill ) { - unkilled_cnt += !ji->sent_sigkill ? 1 : 0; - } else { - unkilled_cnt += ji->clean_exit_timer_expired ? 1 : 0; - } - } else if( ji->stopped ) { - /* If the job is active and has been told to stop, disregard it - * after we've sent SIGKILL. - */ - unkilled_cnt += !ji->sent_sigkill ? 1 : 0; - } else if( !active ) { - /* If the job was not active when shutdown began, remove it. */ - job_remove(ji); - } + jobmgr_t jmi = NULL, jmn = NULL; + SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { + jobmgr_do_garbage_collection(jmi); } - /* If we've killed everyone, move on. */ - if( unkilled_cnt == 0 ) { - jm->killed_hopefully_first_jobs = true; - jm = NULL; + if( SLIST_EMPTY(&jm->submgrs) ) { + jobmgr_log(jm, LOG_DEBUG, "No submanagers left."); + } else { + jobmgr_log(jm, LOG_DEBUG, "Still have submanagers."); } - return jm; -} - -jobmgr_t -jobmgr_do_normal_shutdown_phase(jobmgr_t jm) -{ - if( !jm->shutting_down ) { - return jm; - } - - if( jm->killed_normal_jobs ) { - return NULL; - } - - jobmgr_log(jm, LOG_DEBUG, "Doing second phase of garbage collection."); - - uint32_t unkilled_cnt = 0; - job_t ji = NULL, jn = NULL; - LIST_FOREACH_SAFE( ji, &jm->jobs, sle, jn ) { - if( ji->migratory ) { - /* If we're shutting down, release the hold migratory jobs - * have on us. - */ - job_remove(ji); - } - - if( ji->anonymous || ji->hopefully_exits_first || ji->hopefully_exits_last ) { - continue; - } - - 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); + int phase = -1; + for( phase = jm->shutdown_phase; phase < JOBMGR_PHASE_LAST; phase++ ) { + if( phase == JOBMGR_PHASE_HOPEFULLY_EXITS_LAST ) { + if( jm == root_jobmgr ) { + simulate_pid1_crash(); + } - /* We may have sent SIGKILL to the job in job_stop(). Clean jobs - * get 1 second to exit. - */ - if( !ji->clean_kill ) { - unkilled_cnt += !ji->sent_sigkill ? 1 : 0; - } else { - unkilled_cnt += ji->clean_exit_timer_expired ? 1 : 0; + if( jm == root_jobmgr && pid1_magic && !jm->killed_stray_jobs ) { + jobmgr_log_stray_children(jm, true); + jm->killed_stray_jobs = true; } - } else if( ji->stopped ) { - /* If the job is active and has been told to stop, disregard it - * after we've sent SIGKILL. - */ - unkilled_cnt += !ji->sent_sigkill ? 1 : 0; - } else if( !active ) { - /* If the job was not active when shutdown began, remove it. */ - job_remove(ji); } - } - - /* If we've killed everyone, move on. */ - if( unkilled_cnt == 0 ) { - jm->killed_normal_jobs = true; - jm = NULL; - } - - return jm; -} -jobmgr_t -jobmgr_do_hopefully_last_shutdown_phase(jobmgr_t jm) -{ - if( !jm->shutting_down ) { - return jm; - } - - if( jm == root_jobmgr ) { - simulate_pid1_crash(); - } - - static bool killed_stray_jobs = false; - if( !killed_stray_jobs && pid1_magic && jm == root_jobmgr ) { - jobmgr_log_stray_children(jm, true); - killed_stray_jobs = true; - } - - if( jm->killed_hopefully_last_jobs || total_children == 0 ) { - return NULL; - } - - uint32_t unkilled_cnt = 0; - job_t ji = NULL, jn = NULL; - jobmgr_log(jm, LOG_DEBUG, "Doing third phase of garbage collection."); - LIST_FOREACH_SAFE( ji, &jm->jobs, sle, jn ) { - if( !ji->hopefully_exits_last ) { - continue; - } - - 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); + uint32_t unkilled_cnt = 0; + job_t ji = NULL, jn = NULL; + LIST_FOREACH_SAFE( ji, &jm->jobs, sle, jn ) { + if( phase == JOBMGR_PHASE_HOPEFULLY_EXITS_FIRST && !ji->hopefully_exits_first ) { + continue; + } else if( phase == JOBMGR_PHASE_NORMAL ) { + if( ji->migratory ) { + /* If we're shutting down, release the hold migratory jobs + * have on us. + */ + job_remove(ji); + } + + if( ji->hopefully_exits_first || ji->hopefully_exits_last ) { + continue; + } + } else if( phase == JOBMGR_PHASE_HOPEFULLY_EXITS_LAST && !ji->hopefully_exits_last ) { + continue; + } - /* We may have sent SIGKILL to the job in job_stop(). Clean jobs - * get 1 second to exit. - */ - if( !ji->clean_kill ) { - unkilled_cnt += !ji->sent_sigkill ? 1 : 0; + if( ji->anonymous ) { + continue; + } + + const char *active = job_active(ji); + if( !active ) { + job_log(ji, LOG_DEBUG, "Job is inactive. Removing."); + job_remove(ji); } else { - unkilled_cnt += ji->clean_exit_timer_expired ? 1 : 0; + if( ji->p ) { + if( !ji->stopped ) { + job_log(ji, LOG_DEBUG, "Stopping job."); + job_stop(ji); + if( !ji->clean_kill ) { + unkilled_cnt++; + } + } else { + if( ji->clean_kill ) { + job_log(ji, LOG_DEBUG, "Job was clean and sent SIGKILL."); + } else { + job_log(ji, LOG_DEBUG, "Job was sent SIGTERM%s.", ji->sent_sigkill ? " and SIGKILL" : ""); + } + unkilled_cnt += !ji->sent_sigkill; + } + } else { + job_log(ji, LOG_DEBUG, "Job is active: %s", active); + } } - } else if( ji->stopped ) { - /* If the job is active and has been told to stop, disregard it - * after we've sent SIGKILL. - */ - unkilled_cnt += !ji->sent_sigkill ? 1 : 0; - } else if( !active ) { - /* If the job was not active when shutdown began, remove it. */ - job_remove(ji); + } /* LIST_FOREACH_SAFE */ + + if( unkilled_cnt == 0 ) { + jobmgr_log(jm, LOG_DEBUG, "Done with the %s bucket, advancing.", s_phases[jm->shutdown_phase]); + jm->shutdown_phase++; + } else { + jobmgr_log(jm, LOG_DEBUG, "Still %u unkilled job%s in %s bucket.", unkilled_cnt, unkilled_cnt > 1 ? "s" : "", s_phases[jm->shutdown_phase]); + phase = JOBMGR_PHASE_LAST; } - } + } /* for */ - /* If we've killed everyone, move on. */ - if( unkilled_cnt == 0 ) { - jm->killed_hopefully_last_jobs = true; - jm = NULL; - } - - return jm; -} - -jobmgr_t -jobmgr_do_garbage_collection(jobmgr_t jm) -{ - if( !jm->shutting_down ) { - return jm; - } - - jobmgr_t jmi = NULL, jmn = NULL; - SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { - jobmgr_do_garbage_collection(jmi); - } - - if( SLIST_EMPTY(&jm->submgrs) ) { - jobmgr_log(jm, LOG_DEBUG, "No submanagers left."); - } else { - jobmgr_log(jm, LOG_DEBUG, "Still have submanagers."); - } - - jobmgr_t _jm = jobmgr_do_hopefully_first_shutdown_phase(jm); - if( !_jm ) { - _jm = jobmgr_do_normal_shutdown_phase(jm) ? : jobmgr_do_hopefully_last_shutdown_phase(jm); - } - - if( !_jm && SLIST_EMPTY(&jm->submgrs) ) { + jobmgr_t r = jm; + if( jm->shutdown_phase > JOBMGR_PHASE_HOPEFULLY_EXITS_LAST && SLIST_EMPTY(&jm->submgrs) ) { jobmgr_log(jm, LOG_DEBUG | LOG_CONSOLE, "Removing."); jobmgr_log_stray_children(jm, false); jobmgr_remove(jm); - } else { - _jm = jm; + r = NULL; } - return _jm; + return r; } void @@ -5950,6 +5883,8 @@ /* Start the update job. */ jobmgr_assumes(jm, kevent_mod((uintptr_t)do_sync, EVFILT_TIMER, EV_ADD, NOTE_SECONDS, 30, bootstrapper) != -1); #endif + + jobmgr_assumes(jm, kevent_mod((uintptr_t)fileno(g_console), EVFILT_VNODE, EV_ADD | EV_ONESHOT, NOTE_REVOKE, 0, jm) != -1); } } @@ -7048,7 +6983,7 @@ j->abandon_pg = (bool)inval; break; case VPROC_GSK_GLOBAL_ON_DEMAND: - job_log(j, LOG_NOTICE, "Job is setting global on-demand mode to %s (j->forced_peers_to_demand_mode = %s)", (bool)inval ? "true" : "false", j->forced_peers_to_demand_mode ? "true" : "false"); + job_log(j, LOG_DEBUG, "Job is setting global on-demand mode to %s (j->forced_peers_to_demand_mode = %s)", (bool)inval ? "true" : "false", j->forced_peers_to_demand_mode ? "true" : "false"); kr = job_set_global_on_demand(j, (bool)inval) ? 0 : 1; break; case VPROC_GSK_BASIC_KEEPALIVE: @@ -7250,7 +7185,7 @@ } #if !TARGET_OS_EMBEDDED - if( unlikely(ldc->euid) ) { + if (unlikely(ldc->euid)) { #else if( unlikely(ldc->euid) && !j->embedded_shutdown_auth ) { #endif @@ -7365,7 +7300,7 @@ if( !job_assumes(ji, sb.st_gid == 0) ) { job_assumes(ji, chown(pu_db, which_user, 0) != -1); } - if( !job_assumes(ji, sb.st_mode == S_IRWXU) ) { + if( !job_assumes(ji, sb.st_mode == (S_IRWXU | S_IFDIR)) ) { job_assumes(ji, chmod(pu_db, S_IRWXU) != -1); } } Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2009-03-10 01:22:02 UTC (rev 23856) +++ trunk/launchd/src/launchd_runtime.c 2009-03-11 03:13:03 UTC (rev 23857) @@ -376,7 +376,7 @@ else FLAGIF(EV_ONESHOT) else FLAGIF(EV_ERROR) else { - flags_off += sprintf(flags_off, "0x%x", flags); + flags_off += sprintf(flags_off, "0x%hx", flags); flags = 0; } } @@ -503,7 +503,7 @@ } break; default: - snprintf(filter_buf, sizeof(filter_buf), "%d", kev->filter); + snprintf(filter_buf, sizeof(filter_buf), "%hd", kev->filter); filter_str = filter_buf; break; } @@ -597,11 +597,13 @@ kevi = &kev[i]; if (kevi->filter) { - Dl_info dli; - + runtime_syslog(LOG_DEBUG, "Dispatching kevent..."); + log_kevent_struct(LOG_DEBUG, kev, i); + #if 0 /* Check if kevi->udata was either malloc(3)ed or is a valid function pointer. * If neither, it's probably an invalid pointer and we should log it. */ + Dl_info dli; if (launchd_assumes(malloc_size(kevi->udata) || dladdr(kevi->udata, &dli))) { runtime_ktrace(RTKT_LAUNCHD_BSD_KEVENT|DBG_FUNC_START, kevi->ident, kevi->filter, kevi->fflags); (*((kq_callback *)kevi->udata))(kevi->udata, kevi); @@ -610,6 +612,11 @@ runtime_syslog(LOG_ERR, "The following kevent had invalid context data."); log_kevent_struct(LOG_EMERG, kevi, i); } + #else + runtime_ktrace(RTKT_LAUNCHD_BSD_KEVENT|DBG_FUNC_START, kevi->ident, kevi->filter, kevi->fflags); + (*((kq_callback *)kevi->udata))(kevi->udata, kevi); + runtime_ktrace0(RTKT_LAUNCHD_BSD_KEVENT|DBG_FUNC_END); + #endif } } } @@ -854,8 +861,9 @@ int i = 0; for( i = bulk_kev_i + 1; i < bulk_kev_cnt; i++ ) { if( bulk_kev[i].filter == filter && bulk_kev[i].ident == ident ) { - runtime_syslog(LOG_DEBUG, "Skipping PROC event for PID %lu", ident); - bulk_kev[i].filter = 0; + runtime_syslog(LOG_DEBUG, "Pruning the following kevent:"); + log_kevent_struct(LOG_DEBUG, &bulk_kev[i], i); + bulk_kev[i].filter = (short)0; } } } Modified: trunk/launchd.xcodeproj/project.pbxproj =================================================================== --- trunk/launchd.xcodeproj/project.pbxproj 2009-03-10 01:22:02 UTC (rev 23856) +++ trunk/launchd.xcodeproj/project.pbxproj 2009-03-11 03:13:03 UTC (rev 23857) @@ -529,8 +529,8 @@ FC59A0B50E8C8A1F00D41150 /* launchd_runtime.c */, FC59A0B60E8C8A1F00D41150 /* launchd_core_logic.h */, FC59A0B70E8C8A1F00D41150 /* launchd_core_logic.c */, + 72FDB15E0EA7D7B200B2AC84 /* launchd_ktrace.h */, 72FDB15D0EA7D7B200B2AC84 /* launchd_ktrace.c */, - 72FDB15E0EA7D7B200B2AC84 /* launchd_ktrace.h */, ); name = Source; sourceTree = ""; -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Wed Mar 11 16:10:12 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Wed, 11 Mar 2009 16:10:12 -0700 (PDT) Subject: [launchd-changes] [23858] tags/launchd-304/ Message-ID: <20090311231013.1A91111B05E5@beta.macosforge.org> Revision: 23858 http://trac.macosforge.org/projects/launchd/changeset/23858 Author: dsorresso at apple.com Date: 2009-03-11 16:10:12 -0700 (Wed, 11 Mar 2009) Log Message: ----------- "Tagging launchd-304 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-304/ Property changes on: tags/launchd-304 ___________________________________________________________________ Added: svn:ignore + build Added: svn:mergeinfo + /branches/PR-5092682:23731-23742 /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 /branches/PR-6132016:23719-23738 /branches/PR-6271234:23818-23822 /branches/PR-6562592:23812-23822 /branches/PR-6564965:23832-23851 /branches/PR-6589133:23810-23822 /branches/PR-6609410:23828 -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Sat Mar 14 20:33:49 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Sat, 14 Mar 2009 20:33:49 -0700 (PDT) Subject: [launchd-changes] [23859] trunk/launchd/src/rc.netboot Message-ID: <20090315033349.BA9D511FC93F@beta.macosforge.org> Revision: 23859 http://trac.macosforge.org/projects/launchd/changeset/23859 Author: dsorresso at apple.com Date: 2009-03-14 20:33:49 -0700 (Sat, 14 Mar 2009) Log Message: ----------- SnowLeopard: Sporadic Failure of XServe Netboot Modified Paths: -------------- trunk/launchd/src/rc.netboot Modified: trunk/launchd/src/rc.netboot =================================================================== --- trunk/launchd/src/rc.netboot 2009-03-11 23:10:12 UTC (rev 23858) +++ trunk/launchd/src/rc.netboot 2009-03-15 03:33:49 UTC (rev 23859) @@ -27,6 +27,8 @@ Failed() { echo rc.netboot: $1 + echo rc.netboot: $1 > /dev/console + sleep 5 exit 1 } @@ -74,11 +76,24 @@ local_mount() { - volinfo=`autodiskmount -F 2>/dev/null` - if [ $? -ne 0 ]; then - echo "autodiskmount -F found no local drives" - return 1 - fi + tries=0 + limit=11 + while [ $tries -lt $limit ]; do + tries=$(( tries + 1 )) + volinfo=`autodiskmount -F 2>/dev/null` + if [ $? -ne 0 ]; then + if [ $tries -lt $limit ]; then + echo "Waiting for local drives..." + echo "Waiting for local drives (retry ${tries}/$(( limit - 1 )))..." > /dev/console + sleep 5 + else + echo "autodiskmount -F found no local drives" + return 1 + fi + else + tries=$limit + fi + done set ${volinfo} devname=$1 fstype=$2 -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Sat Mar 14 20:34:30 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Sat, 14 Mar 2009 20:34:30 -0700 (PDT) Subject: [launchd-changes] [23860] tags/launchd-305/ Message-ID: <20090315033430.AE9C511FC967@beta.macosforge.org> Revision: 23860 http://trac.macosforge.org/projects/launchd/changeset/23860 Author: dsorresso at apple.com Date: 2009-03-14 20:34:30 -0700 (Sat, 14 Mar 2009) Log Message: ----------- "Tagging launchd-305 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-305/ Property changes on: tags/launchd-305 ___________________________________________________________________ Added: svn:ignore + build Added: svn:mergeinfo + /branches/PR-5092682:23731-23742 /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 /branches/PR-6132016:23719-23738 /branches/PR-6271234:23818-23822 /branches/PR-6562592:23812-23822 /branches/PR-6564965:23832-23851 /branches/PR-6589133:23810-23822 /branches/PR-6609410:23828 -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Tue Mar 17 15:23:19 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 17 Mar 2009 15:23:19 -0700 (PDT) Subject: [launchd-changes] [23861] trunk/launchd.xcodeproj/project.pbxproj Message-ID: <20090317222319.5B853123E438@beta.macosforge.org> Revision: 23861 http://trac.macosforge.org/projects/launchd/changeset/23861 Author: dsorresso at apple.com Date: 2009-03-17 15:23:18 -0700 (Tue, 17 Mar 2009) Log Message: ----------- 10A299: launchd creating /var/db/launchd.db and ../com.apple.launchd at first launch Modified Paths: -------------- trunk/launchd.xcodeproj/project.pbxproj Modified: trunk/launchd.xcodeproj/project.pbxproj =================================================================== --- trunk/launchd.xcodeproj/project.pbxproj 2009-03-15 03:34:30 UTC (rev 23860) +++ trunk/launchd.xcodeproj/project.pbxproj 2009-03-17 22:23:18 UTC (rev 23861) @@ -887,7 +887,7 @@ ); runOnlyForDeploymentPostprocessing = 1; shellPath = /bin/sh; - shellScript = "/Developer/Makefiles/bin/compress-man-pages.pl -d \"$DSTROOT\" /usr/share/man"; + shellScript = "/Developer/Makefiles/bin/compress-man-pages.pl -d \"$DSTROOT\" /usr/share/man\n/bin/mkdir -p \"$DSTROOT/private/var/db/launchd.db/com.apple.launchd\"\n/usr/sbin/chown root:wheel \"$DSTROOT/private/var/db/launchd.db\"\n/usr/sbin/chown root:wheel \"$DSTROOT/private/var/db/launchd.db/com.apple.launchd\"\n\n"; showEnvVarsInLog = 0; }; 4B10F1F00F43BF5C00875782 /* ShellScript */ = { @@ -915,7 +915,7 @@ ); runOnlyForDeploymentPostprocessing = 1; shellPath = /bin/sh; - shellScript = "/Developer/Makefiles/bin/compress-man-pages.pl -d \"$DSTROOT\" /usr/share/man"; + shellScript = "/Developer/Makefiles/bin/compress-man-pages.pl -d \"$DSTROOT\" /usr/share/man\n/bin/mkdir -p \"$DSTROOT/private/var/db/launchd.db/com.apple.launchd\"\n/usr/sbin/chown root:wheel \"$DSTROOT/private/var/db/launchd.db\"\n/usr/sbin/chown root:wheel \"$DSTROOT/private/var/db/launchd.db/com.apple.launchd\"\n"; showEnvVarsInLog = 0; }; FC7B87EE0EA71A4900542082 /* ShellScript */ = { -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Tue Mar 17 15:24:19 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 17 Mar 2009 15:24:19 -0700 (PDT) Subject: [launchd-changes] [23862] tags/launchd-306/ Message-ID: <20090317222419.9914B123E4E6@beta.macosforge.org> Revision: 23862 http://trac.macosforge.org/projects/launchd/changeset/23862 Author: dsorresso at apple.com Date: 2009-03-17 15:24:19 -0700 (Tue, 17 Mar 2009) Log Message: ----------- "Tagging launchd-306 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-306/ Property changes on: tags/launchd-306 ___________________________________________________________________ Added: svn:ignore + build Added: svn:mergeinfo + /branches/PR-5092682:23731-23742 /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 /branches/PR-6132016:23719-23738 /branches/PR-6271234:23818-23822 /branches/PR-6562592:23812-23822 /branches/PR-6564965:23832-23851 /branches/PR-6589133:23810-23822 /branches/PR-6609410:23828 -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Tue Mar 17 18:41:55 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 17 Mar 2009 18:41:55 -0700 (PDT) Subject: [launchd-changes] [23863] trunk/launchd/src Message-ID: <20090318014156.35A181243212@beta.macosforge.org> Revision: 23863 http://trac.macosforge.org/projects/launchd/changeset/23863 Author: dsorresso at apple.com Date: 2009-03-17 18:41:53 -0700 (Tue, 17 Mar 2009) Log Message: ----------- Embedded security fixes. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/liblaunch.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-03-17 22:24:19 UTC (rev 23862) +++ trunk/launchd/src/launchd_core_logic.c 2009-03-18 01:41:53 UTC (rev 23863) @@ -3507,16 +3507,16 @@ pid_t c; bool sipc = false; u_int proc_fflags = NOTE_EXIT|NOTE_FORK|NOTE_EXEC|NOTE_REAP; - + if (!job_assumes(j, j->mgr != NULL)) { return; } - + if (unlikely(job_active(j))) { job_log(j, LOG_DEBUG, "Already started"); return; } - + /* * Some users adjust the wall-clock and then expect software to not notice. * Therefore, launchd must use an absolute clock instead of the wall clock @@ -3524,31 +3524,31 @@ */ td = runtime_get_nanoseconds_since(j->start_time); td /= NSEC_PER_SEC; - + if (j->start_time && (td < j->min_run_time) && !j->legacy_mach_job && !j->inetcompat) { time_t respawn_delta = j->min_run_time - (uint32_t)td; - + /* * We technically should ref-count throttled jobs to prevent idle exit, * but we're not directly tracking the 'throttled' state at the moment. */ - + job_log(j, LOG_WARNING, "Throttling respawn: Will start in %ld seconds", respawn_delta); job_assumes(j, kevent_mod((uintptr_t)j, EVFILT_TIMER, EV_ADD|EV_ONESHOT, NOTE_SECONDS, respawn_delta, j) != -1); job_ignore(j); return; } - + if (likely(!j->legacy_mach_job)) { - sipc = (!SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices)); + sipc = ( !SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices) ) && !j->deny_job_creation; } if (sipc) { job_assumes(j, socketpair(AF_UNIX, SOCK_STREAM, 0, spair) != -1); } - + job_assumes(j, socketpair(AF_UNIX, SOCK_STREAM, 0, execspair) != -1); - + if (likely(!j->legacy_mach_job) && job_assumes(j, pipe(oepair) != -1)) { j->log_redirect_fd = _fd(oepair[0]); job_assumes(j, fcntl(j->log_redirect_fd, F_SETFL, O_NONBLOCK) != -1); @@ -3584,7 +3584,7 @@ job_assumes(j, runtime_close(execspair[0]) == 0); /* wait for our parent to say they've attached a kevent to us */ read(_fd(execspair[1]), &c, sizeof(c)); - + if (sipc) { job_assumes(j, runtime_close(spair[0]) == 0); snprintf(nbuf, sizeof(nbuf), "%d", spair[1]); @@ -3594,9 +3594,9 @@ break; default: j->start_time = runtime_get_opaque_time(); - + job_log(j, LOG_DEBUG, "Started as PID: %u", c); - + j->checkedin = false; j->start_pending = false; j->reaped = false; @@ -3617,7 +3617,7 @@ runtime_add_ref(); total_children++; LIST_INSERT_HEAD(&j->mgr->active_jobs[ACTIVE_JOB_HASH(c)], j, pid_hash_sle); - + if (likely(!j->legacy_mach_job)) { job_assumes(j, runtime_close(oepair[1]) != -1); } @@ -3638,7 +3638,7 @@ } else { job_reap(j); } - + if (likely(!j->stall_before_exec)) { job_uncork_fork(j); } @@ -6676,7 +6676,7 @@ return BOOTSTRAP_NO_MEMORY; } - if (unlikely(ldc->euid != 0 && ldc->euid != getuid())) { + if( unlikely(ldc->euid != 0 && ldc->euid != getuid()) || j->deny_job_creation ) { return BOOTSTRAP_NOT_PRIVILEGED; } @@ -7221,6 +7221,10 @@ return BOOTSTRAP_NO_MEMORY; } + if( j->deny_job_creation ) { + return BOOTSTRAP_NOT_PRIVILEGED; + } + ipc_server_init(); if (unlikely(!sockpath)) { @@ -7329,6 +7333,11 @@ struct ldcred *ldc = runtime_get_caller_creds(); job_t jpu; +#if TARGET_OS_EMBEDDED + /* There is no need for per-user launchd's on embedded. */ + return BOOTSTRAP_NOT_PRIVILEGED; +#endif + if (!launchd_assumes(j != NULL)) { return BOOTSTRAP_NO_MEMORY; } @@ -7839,7 +7848,7 @@ kern_return_t kr = BOOTSTRAP_NOT_PRIVILEGED; mach_port_t _mp = MACH_PORT_NULL; - if( ldc->euid == 0 || ldc->euid == geteuid() ) { + if( !j->deny_job_creation && (ldc->euid == 0 || ldc->euid == geteuid()) ) { job_t target_j = job_find(label); if( jobmgr_assumes(root_jobmgr, target_j != NULL) ) { if( target_j->j_port == MACH_PORT_NULL ) { Modified: trunk/launchd/src/liblaunch.c =================================================================== --- trunk/launchd/src/liblaunch.c 2009-03-17 22:24:19 UTC (rev 23862) +++ trunk/launchd/src/liblaunch.c 2009-03-18 01:41:53 UTC (rev 23863) @@ -190,12 +190,12 @@ name_t spath; _lc = calloc(1, sizeof(struct _launch_client)); - + if (!_lc) return; - + pthread_mutex_init(&_lc->mtx, NULL); - + if (_launchd_fd) { lfd = strtol(_launchd_fd, NULL, 10); if ((dfd = dup(lfd)) >= 0) { @@ -248,7 +248,7 @@ if (!(_lc->async_resp = launch_data_alloc(LAUNCH_DATA_ARRAY))) { goto out_bad; } - + return; out_bad: if (_lc->l) -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Tue Mar 24 10:50:42 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 24 Mar 2009 10:50:42 -0700 (PDT) Subject: [launchd-changes] [23864] trunk/launchd/src Message-ID: <20090324175042.669B112D87AE@beta.macosforge.org> Revision: 23864 http://trac.macosforge.org/projects/launchd/changeset/23864 Author: dsorresso at apple.com Date: 2009-03-24 10:50:41 -0700 (Tue, 24 Mar 2009) Log Message: ----------- 10A295: rpc.statd launchd job submission succeeds but returns EACCES? Modified Paths: -------------- trunk/launchd/src/launchctl.c trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/liblaunch.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2009-03-18 01:41:53 UTC (rev 23863) +++ trunk/launchd/src/launchctl.c 2009-03-24 17:50:41 UTC (rev 23864) @@ -2410,6 +2410,8 @@ case ESRCH: fprintf(stderr, "%s: %s\n", lab4job, "Not loaded"); break; + case ENEEDAUTH: + fprintf(stderr, "%s: %s\n", lab4job, "Could not set security session"); default: fprintf(stderr, "%s: %s\n", lab4job, strerror(e)); case 0: Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-03-18 01:41:53 UTC (rev 23863) +++ trunk/launchd/src/launchd_core_logic.c 2009-03-24 17:50:41 UTC (rev 23864) @@ -1562,6 +1562,10 @@ return NULL; } + /* Since jobs are effectively stalled until they get security sessions assigned + * to them, we may wish to reconsider this behavior of calling the job "enabled" + * as far as other jobs with the OtherJobEnabled KeepAlive criterion set. + */ job_dispatch_curious_jobs(j); return job_dispatch(j, false); } @@ -1576,7 +1580,7 @@ ja = alloca(c * sizeof(job_t)); for (i = 0; i < c; i++) { - if (likely(ja[i] = jobmgr_import2(root_jobmgr, launch_data_array_get_index(pload, i)))) { + if( (likely(ja[i] = jobmgr_import2(root_jobmgr, launch_data_array_get_index(pload, i)))) && errno != ENEEDAUTH ) { errno = 0; } launch_data_array_set_index(resp, launch_data_new_errno(errno), i); @@ -2251,6 +2255,7 @@ uuid_unparse(j->expected_audit_uuid, uuid_str); job_log(j, LOG_DEBUG, "Imported job. Waiting for session for UUID %s.", uuid_str); LIST_INSERT_HEAD(&s_needing_sessions, j, needing_session_sle); + errno = ENEEDAUTH; } else { job_log(j, LOG_DEBUG, "No security session specified."); j->audit_session = MACH_PORT_NULL; Modified: trunk/launchd/src/liblaunch.c =================================================================== --- trunk/launchd/src/liblaunch.c 2009-03-18 01:41:53 UTC (rev 23863) +++ trunk/launchd/src/liblaunch.c 2009-03-24 17:50:41 UTC (rev 23864) @@ -982,6 +982,10 @@ } pthread_once(&_lc_once, launch_client_init); + if (!_lc) { + errno = ENOTCONN; + return NULL; + } #if !TARGET_OS_EMBEDDED uuid_t uuid; @@ -1023,11 +1027,6 @@ } #endif - if (!_lc) { - errno = ENOTCONN; - return NULL; - } - pthread_mutex_lock(&_lc->mtx); if (d && launchd_msg_send(_lc->l, d) == -1) { @@ -1061,22 +1060,38 @@ out: #if !TARGET_OS_EMBEDDED if( !uuid_is_null(uuid) && resp && jobs_that_need_sessions > 0 ) { - mach_port_t session = MACH_PORT_NULL; - if( (launch_data_get_type(resp) == LAUNCH_DATA_ERRNO && launch_data_get_errno(resp) == 0) || launch_data_get_type(resp) == LAUNCH_DATA_ARRAY ) { - session = _audit_session_self(); + mach_port_t session_port = _audit_session_self(); + launch_data_type_t resp_type = launch_data_get_type(resp); + + bool set_session = false; + if( resp_type == LAUNCH_DATA_ERRNO ) { + set_session = ( launch_data_get_errno(resp) == ENEEDAUTH ); + } else if( resp_type == LAUNCH_DATA_ARRAY ) { + set_session = true; } - + kern_return_t kr = KERN_FAILURE; + if( set_session ) { + kr = vproc_mig_set_security_session(bootstrap_port, uuid, session_port); + } - /* If we can't get our own session, set the sessions for our recently-submitted jobs - * to MACH_PORT_NULL. - */ - kr = vproc_mig_set_security_session(bootstrap_port, uuid, session); - - if( kr != KERN_SUCCESS || session == MACH_PORT_NULL ) { - launch_data_set_errno(resp, EACCES); - _vproc_log_error(LOG_WARNING, "Could not set security session for recently submitted jobs!"); + if( kr == KERN_SUCCESS ) { + if( resp_type == LAUNCH_DATA_ERRNO ) { + launch_data_set_errno(resp, 0); + } else { + size_t i = 0; + for( i = 0; i < launch_data_array_get_count(resp); i++ ) { + launch_data_t ri = launch_data_array_get_index(resp, i); + + int recvd_err = 0; + if( launch_data_get_type(ri) == LAUNCH_DATA_ERRNO && (recvd_err = launch_data_get_errno(ri)) ) { + launch_data_set_errno(ri, recvd_err == ENEEDAUTH ? 0 : recvd_err); + } + } + } } + + mach_port_deallocate(mach_task_self(), session_port); } #endif -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Tue Mar 24 10:52:01 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 24 Mar 2009 10:52:01 -0700 (PDT) Subject: [launchd-changes] [23865] tags/launchd-307/ Message-ID: <20090324175201.F338C12D87E0@beta.macosforge.org> Revision: 23865 http://trac.macosforge.org/projects/launchd/changeset/23865 Author: dsorresso at apple.com Date: 2009-03-24 10:52:00 -0700 (Tue, 24 Mar 2009) Log Message: ----------- "Tagging launchd-307 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-307/ Property changes on: tags/launchd-307 ___________________________________________________________________ Added: svn:ignore + build Added: svn:mergeinfo + /branches/PR-5092682:23731-23742 /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 /branches/PR-6132016:23719-23738 /branches/PR-6271234:23818-23822 /branches/PR-6562592:23812-23822 /branches/PR-6564965:23832-23851 /branches/PR-6589133:23810-23822 /branches/PR-6609410:23828 -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Tue Mar 24 13:59:08 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 24 Mar 2009 13:59:08 -0700 (PDT) Subject: [launchd-changes] [23866] trunk/launchd/src/launchd_core_logic.c Message-ID: <20090324205908.75CCA12DAE6E@beta.macosforge.org> Revision: 23866 http://trac.macosforge.org/projects/launchd/changeset/23866 Author: dsorresso at apple.com Date: 2009-03-24 13:59:07 -0700 (Tue, 24 Mar 2009) Log Message: ----------- launchd's logging about what look like a bugs in it. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-03-24 17:52:00 UTC (rev 23865) +++ trunk/launchd/src/launchd_core_logic.c 2009-03-24 20:59:07 UTC (rev 23866) @@ -5559,7 +5559,7 @@ jobmgr_t r = jm; if( jm->shutdown_phase > JOBMGR_PHASE_HOPEFULLY_EXITS_LAST && SLIST_EMPTY(&jm->submgrs) ) { - jobmgr_log(jm, LOG_DEBUG | LOG_CONSOLE, "Removing."); + jobmgr_log(jm, LOG_DEBUG, "Removing."); jobmgr_log_stray_children(jm, false); jobmgr_remove(jm); r = NULL; @@ -7296,13 +7296,22 @@ char pu_db[PATH_MAX]; snprintf(pu_db, sizeof(pu_db), LAUNCHD_DB_PREFIX "/%s", lbuf); - int err = -1; - if( (err = stat(pu_db, &sb)) == -1 && job_assumes(ji, errno == ENOENT) ) { + bool created = false; + int err = stat(pu_db, &sb); + if( (err == -1 && errno == ENOENT) || (err == 0 && !S_ISDIR(sb.st_mode)) ) { + if( err == 0 ) { + char move_aside[PATH_MAX]; + snprintf(move_aside, sizeof(move_aside), LAUNCHD_DB_PREFIX "/%s.movedaside", lbuf); + + job_assumes(ji, rename(pu_db, move_aside) != -1); + } + job_assumes(ji, mkdir(pu_db, S_IRWXU) != -1); - job_assumes(ji, (err = stat(pu_db, &sb)) != -1); + job_assumes(ji, chown(pu_db, which_user, 0) != -1); + created = true; } - if( err != -1 ) { + if( !created ) { if( !job_assumes(ji, sb.st_uid == which_user) ) { job_assumes(ji, chown(pu_db, which_user, 0) != -1); } -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Tue Mar 24 15:27:19 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 24 Mar 2009 15:27:19 -0700 (PDT) Subject: [launchd-changes] [23867] trunk/launchd/src Message-ID: <20090324222720.3429012DBA18@beta.macosforge.org> Revision: 23867 http://trac.macosforge.org/projects/launchd/changeset/23867 Author: dsorresso at apple.com Date: 2009-03-24 15:27:19 -0700 (Tue, 24 Mar 2009) Log Message: ----------- Added code for debugging system bootstrapper crashes. Modified Paths: -------------- trunk/launchd/src/launchctl.c trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2009-03-24 20:59:07 UTC (rev 23866) +++ trunk/launchd/src/launchctl.c 2009-03-24 22:27:19 UTC (rev 23867) @@ -170,6 +170,8 @@ static void do_bootroot_magic(void); static void do_single_user_mode(bool); static bool do_single_user_mode2(void); +static void do_crash_debug_mode(void); +static bool do_crash_debug_mode2(void); static void read_launchd_conf(void); static void read_environment_dot_plist(void); static bool job_disabled_logic(launch_data_t obj); @@ -177,6 +179,8 @@ static void do_file_init(void) __attribute__((constructor)); static void setup_system_context(void); static void tell_launchd_about_boot_args(void); +static void handle_system_bootstrapper_crashes_separately(void); +static void fatal_signal_handler(int sig, siginfo_t *si, void *uap); typedef enum { BOOTCACHE_START = 1, @@ -262,6 +266,7 @@ static bool bootstrapping_system; static bool bootstrapping_peruser; static bool g_shutdown_debugging = false; +static bool g_booting_verbose = false; static bool g_job_overrides_db_has_changed = false; static CFMutableDictionaryRef g_job_overrides_db = NULL; @@ -1789,6 +1794,10 @@ if (!assumes(login_tty(fd) != -1)) { _exit(EXIT_FAILURE); } + + mach_timespec_t wt = { 5, 0 }; + IOKitWaitQuiet(kIOMasterPortDefault, &wt); /* This will hopefully return after all the kexts have shut up. */ + setenv("TERM", "vt100", 1); if (runcom_fsck) { fprintf(stdout, "Singleuser boot -- fsck not done\n"); @@ -1805,6 +1814,64 @@ _exit(EXIT_FAILURE); } +void +do_crash_debug_mode(void) +{ + while (!do_crash_debug_mode2()) { + sleep(1); + } +} + +bool +do_crash_debug_mode2(void) +{ + int wstatus; + int fd; + pid_t p; + + switch ((p = fork())) { + case -1: + syslog(LOG_ERR, "can't fork crash debug shell, trying again: %m"); + return false; + case 0: + break; + default: + assumes(waitpid(p, &wstatus, 0) != -1); + if (WIFEXITED(wstatus)) { + if (WEXITSTATUS(wstatus) == EXIT_SUCCESS) { + return true; + } else { + fprintf(stdout, "crash debug mode: exit status: %d\n", WEXITSTATUS(wstatus)); + } + } else { + fprintf(stdout, "crash debug mode shell: %s\n", strsignal(WTERMSIG(wstatus))); + } + return false; + } + + revoke(_PATH_CONSOLE); + if (!assumes((fd = open(_PATH_CONSOLE, O_RDWR)) != -1)) { + _exit(EXIT_FAILURE); + } + if (!assumes(login_tty(fd) != -1)) { + _exit(EXIT_FAILURE); + } + + mach_timespec_t wt = { 5, 0 }; + IOKitWaitQuiet(kIOMasterPortDefault, &wt); /* This will hopefully return after all the kexts have shut up. */ + + setenv("TERM", "vt100", 1); + fprintf(stdout, "Entering boot-time debugging mode...\n"); + fprintf(stdout, "The system bootstrapper process has crashed. To debug:\n"); + fprintf(stdout, "\tgdb attach %i\n", getppid()); + fprintf(stdout, "You can try booting the system with:\n"); + fprintf(stdout, "\tlaunchctl load -S System -D All\n\n"); + + execl(_PATH_BSHELL, "-sh", NULL); + syslog(LOG_ERR, "can't exec %s for crash debug: %m", _PATH_BSHELL); + _exit(EXIT_FAILURE); +} + static void exit_at_sigterm(int sig) { @@ -1813,6 +1880,33 @@ } } +void +fatal_signal_handler(int sig __attribute__((unused)), siginfo_t *si __attribute__((unused)), void *uap __attribute__((unused))) +{ + do_crash_debug_mode(); +} + +void +handle_system_bootstrapper_crashes_separately(void) +{ + if( !g_booting_verbose ) { + return; + } + + struct sigaction fsa; + + fsa.sa_sigaction = fatal_signal_handler; + fsa.sa_flags = SA_SIGINFO; + sigemptyset(&fsa.sa_mask); + + assumes(sigaction(SIGILL, &fsa, NULL) != -1); + assumes(sigaction(SIGFPE, &fsa, NULL) != -1); + assumes(sigaction(SIGBUS, &fsa, NULL) != -1); + assumes(sigaction(SIGSEGV, &fsa, NULL) != -1); + assumes(sigaction(SIGTRAP, &fsa, NULL) != -1); + assumes(sigaction(SIGABRT, &fsa, NULL) != -1); +} + static void system_specific_bootstrap(bool sflag) { @@ -1879,6 +1973,7 @@ tell_launchd_about_boot_args(); read_launchd_conf(); + handle_system_bootstrapper_crashes_separately(); if (path_check("/var/account/acct")) { assumes(acct("/var/account/acct") != -1); @@ -3012,7 +3107,6 @@ IOObjectRelease(entry); } while( 0 ); - Boolean is_verbose = false; if( value ) { /* Normally I'd just use CFStringFind(), but the compiler whines about it returning a * struct with -Wall. @@ -3020,10 +3114,10 @@ CFRange range = { 0, CFStringGetLength(value) }; CFRange found_range = { 0, 0 }; - is_verbose = CFStringFindWithOptions(value, CFSTR("-v"), range, 0, &found_range); + g_booting_verbose = CFStringFindWithOptions(value, CFSTR("-v"), range, 0, &found_range); CFRelease(value); - assumes(vproc_swap_integer(NULL, VPROC_GSK_SHUTDOWN_DEBUGGING, (int64_t *)&is_verbose, NULL) == KERN_SUCCESS); + assumes(vproc_swap_integer(NULL, VPROC_GSK_SHUTDOWN_DEBUGGING, (int64_t *)&g_booting_verbose, NULL) == KERN_SUCCESS); } } Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-03-24 20:59:07 UTC (rev 23866) +++ trunk/launchd/src/launchd_core_logic.c 2009-03-24 22:27:19 UTC (rev 23867) @@ -2515,6 +2515,8 @@ struct rusage ru; int status; + bool is_system_bootstrapper = j->is_bootstrapper && pid1_magic && !j->mgr->parentmgr; + job_log(j, LOG_DEBUG, "Reaping"); if (j->shmem) { @@ -2561,7 +2563,7 @@ #endif } } - + /* * 5020256 * @@ -2655,6 +2657,10 @@ job_log(j, LOG_WARNING, "Exited abnormally: %s", strsignal(s)); break; } + + if( is_system_bootstrapper && j->crashed ) { + job_log(j, LOG_ERR | LOG_CONSOLE, "The %s bootstrapper has crashed: %s", j->mgr->name, strsignal(s)); + } } } @@ -2804,9 +2810,6 @@ switch( (p = fork()) ) { case 0 : job_assumes(j, runtime_close(execpair[0]) != -1); - /* Handle exceptions directly. */ - task_set_exception_ports(mach_task_self(), EXC_MASK_CRASH, runtime_get_kernel_port(), EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f); - /* Wait for the parent to attach a kevent. */ read(_fd(execpair[1]), &p, sizeof(p)); what_to_do(j); @@ -6863,6 +6866,8 @@ goto out_bad; } + job_log(j, LOG_DEBUG | LOG_CONSOLE, "Location of job cache database: %s", launch_data_get_string(output_obj)); + launch_data_free(output_obj); break; case 0: -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Tue Mar 24 15:54:23 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 24 Mar 2009 15:54:23 -0700 (PDT) Subject: [launchd-changes] [23868] trunk/launchd/src/launchd_core_logic.c Message-ID: <20090324225423.DA26E12DBE3B@beta.macosforge.org> Revision: 23868 http://trac.macosforge.org/projects/launchd/changeset/23868 Author: dsorresso at apple.com Date: 2009-03-24 15:54:23 -0700 (Tue, 24 Mar 2009) Log Message: ----------- System unable to fork. launchd chewing up resources Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-03-24 22:27:19 UTC (rev 23867) +++ trunk/launchd/src/launchd_core_logic.c 2009-03-24 22:54:23 UTC (rev 23868) @@ -3567,6 +3567,7 @@ case -1: job_log_error(j, LOG_ERR, "fork() failed, will try again in one second"); job_assumes(j, kevent_mod((uintptr_t)j, EVFILT_TIMER, EV_ADD|EV_ONESHOT, NOTE_SECONDS, 1, j) != -1); + job_ignore(j); job_assumes(j, runtime_close(execspair[0]) == 0); job_assumes(j, runtime_close(execspair[1]) == 0); -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Wed Mar 25 14:52:29 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Wed, 25 Mar 2009 14:52:29 -0700 (PDT) Subject: [launchd-changes] [23869] tags/launchd-308/ Message-ID: <20090325215229.EB79C12F16B5@beta.macosforge.org> Revision: 23869 http://trac.macosforge.org/projects/launchd/changeset/23869 Author: dsorresso at apple.com Date: 2009-03-25 14:52:29 -0700 (Wed, 25 Mar 2009) Log Message: ----------- "Tagging launchd-308 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-308/ Property changes on: tags/launchd-308 ___________________________________________________________________ Added: svn:ignore + build Added: svn:mergeinfo + /branches/PR-5092682:23731-23742 /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 /branches/PR-6132016:23719-23738 /branches/PR-6271234:23818-23822 /branches/PR-6562592:23812-23822 /branches/PR-6564965:23832-23851 /branches/PR-6589133:23810-23822 /branches/PR-6609410:23828 -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Thu Mar 26 00:22:22 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Thu, 26 Mar 2009 00:22:22 -0700 (PDT) Subject: [launchd-changes] [23870] trunk Message-ID: <20090326072222.D142312F687F@beta.macosforge.org> Revision: 23870 http://trac.macosforge.org/projects/launchd/changeset/23870 Author: dsorresso at apple.com Date: 2009-03-26 00:22:22 -0700 (Thu, 26 Mar 2009) Log Message: ----------- Modified Paths: -------------- trunk/launchd/src/launch_priv.h trunk/launchd/src/launchd.c trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c trunk/launchd/src/launchd_unix_ipc.c trunk/launchd/src/liblaunch.c trunk/launchd.xcodeproj/project.pbxproj Modified: trunk/launchd/src/launch_priv.h =================================================================== --- trunk/launchd/src/launch_priv.h 2009-03-25 21:52:29 UTC (rev 23869) +++ trunk/launchd/src/launch_priv.h 2009-03-26 07:22:22 UTC (rev 23870) @@ -78,7 +78,7 @@ typedef struct _launch *launch_t; -launch_t launchd_fdopen(int); +launch_t launchd_fdopen(int, int); int launchd_getfd(launch_t); void launchd_close(launch_t, __typeof__(close) closefunc); Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2009-03-25 21:52:29 UTC (rev 23869) +++ trunk/launchd/src/launchd.c 2009-03-26 07:22:22 UTC (rev 23870) @@ -231,6 +231,7 @@ pthread_t t = NULL; int err = pthread_create(&t, NULL, update_thread, NULL); launchd_assumes(err == 0); + launchd_assumes(pthread_detach(t) == 0); } jobmgr_init(sflag); Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-03-25 21:52:29 UTC (rev 23869) +++ trunk/launchd/src/launchd_core_logic.c 2009-03-26 07:22:22 UTC (rev 23870) @@ -4327,7 +4327,9 @@ bool log_to_console = pri & LOG_CONSOLE; int _pri = pri & ~LOG_CONSOLE; - struct runtime_syslog_attr attr = { g_my_label, j->label, j->mgr->name, _pri, getuid(), getpid(), j->p }; + const char *label2use = j ? j->label : "com.apple.launchd.NULL"; + const char *mgr2use = j ? j->mgr->name : "NULL"; + struct runtime_syslog_attr attr = { g_my_label, label2use, mgr2use, _pri, getuid(), getpid(), j ? j->p : 0 }; char *newmsg; int oldmask = 0; size_t newmsgsz; @@ -4348,23 +4350,23 @@ #if !TARGET_OS_EMBEDDED snprintf(newmsg, newmsgsz, "%s: %s", msg, strerror(err)); #else - snprintf(newmsg, newmsgsz, "(%s) %s: %s", j->label, msg, strerror(err)); + snprintf(newmsg, newmsgsz, "(%s) %s: %s", label2use, msg, strerror(err)); #endif } else { #if !TARGET_OS_EMBEDDED snprintf(newmsg, newmsgsz, "%s", msg); #else - snprintf(newmsg, newmsgsz, "(%s) %s", j->label, msg); + snprintf(newmsg, newmsgsz, "(%s) %s", label2use, msg); #endif } - if (unlikely(j->debug)) { + if( j && unlikely(j->debug) ) { oldmask = setlogmask(LOG_UPTO(LOG_DEBUG)); } runtime_vsyslog(&attr, log_to_console, newmsg, ap); - if (unlikely(j->debug)) { + if( j && unlikely(j->debug) ) { setlogmask(oldmask); } } @@ -6689,6 +6691,12 @@ return BOOTSTRAP_NOT_PRIVILEGED; } +#if HAVE_SANDBOX + if (unlikely(sandbox_check(ldc->pid, "job-creation", SANDBOX_FILTER_NONE) > 0)) { + return BOOTSTRAP_NOT_PRIVILEGED; + } +#endif + if (unlikely(!(otherj = job_find(targetlabel)))) { return BOOTSTRAP_UNKNOWN_SERVICE; } @@ -7358,6 +7366,12 @@ return BOOTSTRAP_NOT_PRIVILEGED; #endif +#if HAVE_SANDBOX + if (unlikely(sandbox_check(ldc->pid, "job-creation", SANDBOX_FILTER_NONE) > 0)) { + return BOOTSTRAP_NOT_PRIVILEGED; + } +#endif + if (!launchd_assumes(j != NULL)) { return BOOTSTRAP_NO_MEMORY; } Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2009-03-25 21:52:29 UTC (rev 23869) +++ trunk/launchd/src/launchd_runtime.c 2009-03-26 07:22:22 UTC (rev 23870) @@ -151,7 +151,6 @@ launchd_runtime_init(void) { mach_msg_size_t mxmsgsz; - pthread_attr_t attr; pid_t p = getpid(); launchd_assert((mainkq = kqueue()) != -1); @@ -171,13 +170,9 @@ } launchd_assert(runtime_add_mport(launchd_internal_port, launchd_internal_demux, mxmsgsz) == KERN_SUCCESS); + launchd_assert(pthread_create(&kqueue_demand_thread, NULL, kqueue_demand_loop, NULL) == 0); + launchd_assert(pthread_detach(kqueue_demand_thread) == 0); - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN); - launchd_assert(pthread_create(&kqueue_demand_thread, &attr, kqueue_demand_loop, NULL) == 0); - pthread_attr_destroy(&attr); - launchd_assumes(sysctlbyname("vfs.generic.noremotehang", NULL, NULL, &p, sizeof(p)) != -1); } Modified: trunk/launchd/src/launchd_unix_ipc.c =================================================================== --- trunk/launchd/src/launchd_unix_ipc.c 2009-03-25 21:52:29 UTC (rev 23869) +++ trunk/launchd/src/launchd_unix_ipc.c 2009-03-26 07:22:22 UTC (rev 23870) @@ -186,7 +186,12 @@ fcntl(fd, F_SETFL, O_NONBLOCK); c->kqconn_callback = ipc_callback; - c->conn = launchd_fdopen(fd); + if( j ) { + c->conn = launchd_fdopen(-1, fd); + } else { + c->conn = launchd_fdopen(fd, -1); + } + c->j = j; LIST_INSERT_HEAD(&connections, c, sle); kevent_mod(fd, EVFILT_READ, EV_ADD, 0, 0, &c->kqconn_callback); @@ -337,7 +342,6 @@ launch_data_free(rmc.resp); } - void ipc_readmsg2(launch_data_t data, const char *cmd, void *context) { @@ -349,80 +353,85 @@ return; } - //job_log(rmc->c->j, LOG_DEBUG, "Unix IPC request: %s", cmd); - - if (data == NULL) { - if (!strcmp(cmd, LAUNCH_KEY_CHECKIN)) { - if (rmc->c->j) { - resp = job_export(rmc->c->j); - job_checkin(rmc->c->j); - } else { - resp = launch_data_new_errno(EACCES); +// job_log(rmc->c->j, LOG_NOTICE, "Socket IPC request: %s.", cmd); + + /* Do not allow commands other than check-in to come over the trusted socket. */ + if( data == NULL && rmc->c->j ) { + if( strcmp(cmd, LAUNCH_KEY_CHECKIN) == 0 ) { + resp = job_export(rmc->c->j); + job_checkin(rmc->c->j); + } else { + resp = launch_data_new_errno(EACCES); + } + } else { + if( data == NULL ) { + if (!strcmp(cmd, LAUNCH_KEY_SHUTDOWN)) { + launchd_shutdown(); + resp = launch_data_new_errno(0); + } else if (!strcmp(cmd, LAUNCH_KEY_SINGLEUSER)) { + launchd_single_user(); + resp = launch_data_new_errno(0); + } else if (!strcmp(cmd, LAUNCH_KEY_GETJOBS)) { + resp = job_export_all(); + ipc_revoke_fds(resp); + } else if (!strcmp(cmd, LAUNCH_KEY_GETRESOURCELIMITS)) { + resp = adjust_rlimits(NULL); + } else if (!strcmp(cmd, LAUNCH_KEY_GETRUSAGESELF)) { + struct rusage rusage; + getrusage(RUSAGE_SELF, &rusage); + resp = launch_data_new_opaque(&rusage, sizeof(rusage)); + } else if (!strcmp(cmd, LAUNCH_KEY_GETRUSAGECHILDREN)) { + struct rusage rusage; + getrusage(RUSAGE_CHILDREN, &rusage); + resp = launch_data_new_opaque(&rusage, sizeof(rusage)); } - } else if (!strcmp(cmd, LAUNCH_KEY_SHUTDOWN)) { - launchd_shutdown(); - resp = launch_data_new_errno(0); - } else if (!strcmp(cmd, LAUNCH_KEY_SINGLEUSER)) { - launchd_single_user(); - resp = launch_data_new_errno(0); - } else if (!strcmp(cmd, LAUNCH_KEY_GETJOBS)) { - resp = job_export_all(); - ipc_revoke_fds(resp); - } else if (!strcmp(cmd, LAUNCH_KEY_GETRESOURCELIMITS)) { - resp = adjust_rlimits(NULL); - } else if (!strcmp(cmd, LAUNCH_KEY_GETRUSAGESELF)) { - struct rusage rusage; - getrusage(RUSAGE_SELF, &rusage); - resp = launch_data_new_opaque(&rusage, sizeof(rusage)); - } else if (!strcmp(cmd, LAUNCH_KEY_GETRUSAGECHILDREN)) { - struct rusage rusage; - getrusage(RUSAGE_CHILDREN, &rusage); - resp = launch_data_new_opaque(&rusage, sizeof(rusage)); - } - } else if (!strcmp(cmd, LAUNCH_KEY_STARTJOB)) { - if ((j = job_find(launch_data_get_string(data))) != NULL) { - job_dispatch(j, true); - errno = 0; - } - resp = launch_data_new_errno(errno); - } else if (!strcmp(cmd, LAUNCH_KEY_STOPJOB)) { - if ((j = job_find(launch_data_get_string(data))) != NULL) { - job_stop(j); - errno = 0; - } - resp = launch_data_new_errno(errno); - } else if (!strcmp(cmd, LAUNCH_KEY_REMOVEJOB)) { - if ((j = job_find(launch_data_get_string(data))) != NULL) { - job_remove(j); - errno = 0; - } - resp = launch_data_new_errno(errno); - } else if (!strcmp(cmd, LAUNCH_KEY_SUBMITJOB)) { - if (launch_data_get_type(data) == LAUNCH_DATA_ARRAY) { - resp = job_import_bulk(data); } else { - if (job_import(data)) { - errno = 0; + if (!strcmp(cmd, LAUNCH_KEY_STARTJOB)) { + if ((j = job_find(launch_data_get_string(data))) != NULL) { + job_dispatch(j, true); + errno = 0; + } + resp = launch_data_new_errno(errno); + } else if (!strcmp(cmd, LAUNCH_KEY_STOPJOB)) { + if ((j = job_find(launch_data_get_string(data))) != NULL) { + job_stop(j); + errno = 0; + } + resp = launch_data_new_errno(errno); + } else if (!strcmp(cmd, LAUNCH_KEY_REMOVEJOB)) { + if ((j = job_find(launch_data_get_string(data))) != NULL) { + job_remove(j); + errno = 0; + } + resp = launch_data_new_errno(errno); + } else if (!strcmp(cmd, LAUNCH_KEY_SUBMITJOB)) { + if (launch_data_get_type(data) == LAUNCH_DATA_ARRAY) { + resp = job_import_bulk(data); + } else { + if (job_import(data)) { + errno = 0; + } + resp = launch_data_new_errno(errno); + } + } else if (!strcmp(cmd, LAUNCH_KEY_UNSETUSERENVIRONMENT)) { + unsetenv(launch_data_get_string(data)); + resp = launch_data_new_errno(0); + } else if (!strcmp(cmd, LAUNCH_KEY_SETUSERENVIRONMENT)) { + launch_data_dict_iterate(data, set_user_env, NULL); + resp = launch_data_new_errno(0); + } else if (!strcmp(cmd, LAUNCH_KEY_SETRESOURCELIMITS)) { + resp = adjust_rlimits(data); + } else if (!strcmp(cmd, LAUNCH_KEY_GETJOB)) { + if ((j = job_find(launch_data_get_string(data))) == NULL) { + resp = launch_data_new_errno(errno); + } else { + resp = job_export(j); + ipc_revoke_fds(resp); + } + } else if( !strcmp(cmd, LAUNCH_KEY_SETPRIORITYLIST) ) { + resp = launch_data_new_errno(launchd_set_jetsam_priorities(data)); } - resp = launch_data_new_errno(errno); } - } else if (!strcmp(cmd, LAUNCH_KEY_UNSETUSERENVIRONMENT)) { - unsetenv(launch_data_get_string(data)); - resp = launch_data_new_errno(0); - } else if (!strcmp(cmd, LAUNCH_KEY_SETUSERENVIRONMENT)) { - launch_data_dict_iterate(data, set_user_env, NULL); - resp = launch_data_new_errno(0); - } else if (!strcmp(cmd, LAUNCH_KEY_SETRESOURCELIMITS)) { - resp = adjust_rlimits(data); - } else if (!strcmp(cmd, LAUNCH_KEY_GETJOB)) { - if ((j = job_find(launch_data_get_string(data))) == NULL) { - resp = launch_data_new_errno(errno); - } else { - resp = job_export(j); - ipc_revoke_fds(resp); - } - } else if( !strcmp(cmd, LAUNCH_KEY_SETPRIORITYLIST) ) { - resp = launch_data_new_errno(launchd_set_jetsam_priorities(data)); } rmc->resp = resp; Modified: trunk/launchd/src/liblaunch.c =================================================================== --- trunk/launchd/src/liblaunch.c 2009-03-25 21:52:29 UTC (rev 23869) +++ trunk/launchd/src/liblaunch.c 2009-03-26 07:22:22 UTC (rev 23870) @@ -147,6 +147,10 @@ }; }; +enum { + LAUNCHD_USE_CHECKIN_FD, + LAUNCHD_USE_OTHER_FD, +}; struct _launch { void *sendbuf; int *sendfds; @@ -156,10 +160,9 @@ size_t sendfdcnt; size_t recvlen; size_t recvfdcnt; + int which; + int cifd; int fd; -#if __LP64__ - int __pad; -#endif }; static launch_data_t launch_data_array_pop_first(launch_data_t where); @@ -186,7 +189,7 @@ struct sockaddr_un sun; char *where = getenv(LAUNCHD_SOCKET_ENV); char *_launchd_fd = getenv(LAUNCHD_TRUSTED_FD_ENV); - int dfd, lfd = -1; + int dfd, lfd = -1, cifd = -1; name_t spath; _lc = calloc(1, sizeof(struct _launch_client)); @@ -197,64 +200,78 @@ pthread_mutex_init(&_lc->mtx, NULL); if (_launchd_fd) { - lfd = strtol(_launchd_fd, NULL, 10); - if ((dfd = dup(lfd)) >= 0) { + cifd = strtol(_launchd_fd, NULL, 10); + if ((dfd = dup(cifd)) >= 0) { close(dfd); - _fd(lfd); + _fd(cifd); } else { - lfd = -1; + cifd = -1; } unsetenv(LAUNCHD_TRUSTED_FD_ENV); } - if (lfd == -1) { - memset(&sun, 0, sizeof(sun)); - sun.sun_family = AF_UNIX; - - /* The rules are as follows. - * - All users (including root) talk to their per-user launchd's by default. - * - If we have been invoked under sudo, talk to the system launchd. - * - If we're the root user and the __USE_SYSTEM_LAUNCHD environment variable is set, then - * talk to the system launchd. - */ - if (where && where[0] != '\0') { - strncpy(sun.sun_path, where, sizeof(sun.sun_path)); - } else { - if( _vprocmgr_getsocket(spath) == 0 ) { - if( (getenv("SUDO_COMMAND") || getenv("__USE_SYSTEM_LAUNCHD")) && geteuid() == 0 ) { - /* Talk to the system launchd. */ - strncpy(sun.sun_path, LAUNCHD_SOCK_PREFIX "/sock", sizeof(sun.sun_path)); - } else { - /* Talk to our per-user launchd. */ - size_t min_len; - - min_len = sizeof(sun.sun_path) < sizeof(spath) ? sizeof(sun.sun_path) : sizeof(spath); - - strncpy(sun.sun_path, spath, min_len); - } + + memset(&sun, 0, sizeof(sun)); + sun.sun_family = AF_UNIX; + + /* The rules are as follows. + * - All users (including root) talk to their per-user launchd's by default. + * - If we have been invoked under sudo, talk to the system launchd. + * - If we're the root user and the __USE_SYSTEM_LAUNCHD environment variable is set, then + * talk to the system launchd. + */ + if (where && where[0] != '\0') { + strncpy(sun.sun_path, where, sizeof(sun.sun_path)); + } else { + if( _vprocmgr_getsocket(spath) == 0 ) { + if( (getenv("SUDO_COMMAND") || getenv("__USE_SYSTEM_LAUNCHD")) && geteuid() == 0 ) { + /* Talk to the system launchd. */ + strncpy(sun.sun_path, LAUNCHD_SOCK_PREFIX "/sock", sizeof(sun.sun_path)); + } else { + /* Talk to our per-user launchd. */ + size_t min_len; + + min_len = sizeof(sun.sun_path) < sizeof(spath) ? sizeof(sun.sun_path) : sizeof(spath); + + strncpy(sun.sun_path, spath, min_len); } } + } - if ((lfd = _fd(socket(AF_UNIX, SOCK_STREAM, 0))) == -1) { + if ((lfd = _fd(socket(AF_UNIX, SOCK_STREAM, 0))) == -1) { + goto out_bad; + } + + if (-1 == connect(lfd, (struct sockaddr *)&sun, sizeof(sun))) { + if( cifd != -1 ) { + /* There is NO security enforced by this check. This is just a hint to our + * library that we shouldn't error out due to failing to open this socket. If + * we inherited a trusted file descriptor, we shouldn't fail. This should be + * adequate for clients' expectations. + */ + close(lfd); + lfd = -1; + } else { goto out_bad; } - if (-1 == connect(lfd, (struct sockaddr *)&sun, sizeof(sun))) { - goto out_bad; - } } - if (!(_lc->l = launchd_fdopen(lfd))) { + if (!(_lc->l = launchd_fdopen(lfd, cifd))) { goto out_bad; } + if (!(_lc->async_resp = launch_data_alloc(LAUNCH_DATA_ARRAY))) { goto out_bad; } - + return; out_bad: if (_lc->l) launchd_close(_lc->l, close); else if (lfd != -1) close(lfd); + if( cifd != -1 ) { + close(cifd); + } if (_lc) free(_lc); _lc = NULL; @@ -318,7 +335,6 @@ return dict->_array_cnt / 2; } - bool launch_data_dict_insert(launch_data_t dict, launch_data_t what, const char *key) { @@ -565,11 +581,11 @@ int launchd_getfd(launch_t l) { - return l->fd; + return ( l->which == LAUNCHD_USE_CHECKIN_FD ) ? l->cifd : l->fd; } launch_t -launchd_fdopen(int fd) +launchd_fdopen(int fd, int cifd) { launch_t c; @@ -578,8 +594,16 @@ return NULL; c->fd = fd; + c->cifd = cifd; + if( c->fd == -1 || (c->fd != -1 && c->cifd != -1) ) { + c->which = LAUNCHD_USE_CHECKIN_FD; + } else if( c->cifd == -1 ) { + c->which = LAUNCHD_USE_OTHER_FD; + } + fcntl(fd, F_SETFL, O_NONBLOCK); + fcntl(cifd, F_SETFL, O_NONBLOCK); if ((c->sendbuf = malloc(0)) == NULL) goto out_bad; @@ -621,6 +645,7 @@ if (lh->recvfds) free(lh->recvfds); closefunc(lh->fd); + closefunc(lh->cifd); free(lh); } @@ -801,6 +826,12 @@ size_t sentctrllen = 0; int r; + int fd2use = launchd_getfd(lh); + if( fd2use == -1 ) { + errno = EPERM; + return -1; + } + memset(&mh, 0, sizeof(mh)); /* confirm that the next hack works */ @@ -857,7 +888,7 @@ memcpy(CMSG_DATA(cm), lh->sendfds, lh->sendfdcnt * sizeof(int)); } - if ((r = sendmsg(lh->fd, &mh, 0)) == -1) { + if ((r = sendmsg(fd2use, &mh, 0)) == -1) { return -1; } else if (r == 0) { errno = ECONNRESET; @@ -891,7 +922,6 @@ return 0; } - int launch_get_fd(void) { @@ -987,6 +1017,20 @@ return NULL; } + int fd2use = -1; + if( launch_data_get_type(d) == LAUNCH_DATA_STRING && strcmp(launch_data_get_string(d), LAUNCH_KEY_CHECKIN) == 0 ) { + _lc->l->which = LAUNCHD_USE_CHECKIN_FD; + } else { + _lc->l->which = LAUNCHD_USE_OTHER_FD; + } + + fd2use = launchd_getfd(_lc->l); + + if( fd2use == -1 ) { + errno = EPERM; + return NULL; + } + #if !TARGET_OS_EMBEDDED uuid_t uuid; launch_data_t uuid_d = NULL; @@ -1035,7 +1079,7 @@ goto out; } while (launchd_msg_send(_lc->l, NULL) == -1); } - + while (resp == NULL) { if (d == NULL && launch_data_array_get_count(_lc->async_resp) > 0) { resp = launch_data_array_pop_first(_lc->async_resp); @@ -1051,12 +1095,13 @@ fd_set rfds; FD_ZERO(&rfds); - FD_SET(_lc->l->fd, &rfds); + FD_SET(fd2use, &rfds); - select(_lc->l->fd + 1, &rfds, NULL, NULL, NULL); + select(fd2use + 1, &rfds, NULL, NULL, NULL); } } } + out: #if !TARGET_OS_EMBEDDED if( !uuid_is_null(uuid) && resp && jobs_that_need_sessions > 0 ) { @@ -1110,6 +1155,12 @@ struct iovec iov; int r; + int fd2use = launchd_getfd(lh); + if( fd2use == -1 ) { + errno = EPERM; + return -1; + } + memset(&mh, 0, sizeof(mh)); mh.msg_iov = &iov; mh.msg_iovlen = 1; @@ -1121,7 +1172,7 @@ mh.msg_control = cm; mh.msg_controllen = 4096; - if ((r = recvmsg(lh->fd, &mh, 0)) == -1) + if ((r = recvmsg(fd2use, &mh, 0)) == -1) return -1; if (r == 0) { errno = ECONNRESET; Modified: trunk/launchd.xcodeproj/project.pbxproj =================================================================== --- trunk/launchd.xcodeproj/project.pbxproj 2009-03-25 21:52:29 UTC (rev 23869) +++ trunk/launchd.xcodeproj/project.pbxproj 2009-03-26 07:22:22 UTC (rev 23870) @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 45; objects = { /* Begin PBXAggregateTarget section */ -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Thu Mar 26 14:48:16 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Thu, 26 Mar 2009 14:48:16 -0700 (PDT) Subject: [launchd-changes] [23871] tags/launchd-309/ Message-ID: <20090326214816.6024412FD5D1@beta.macosforge.org> Revision: 23871 http://trac.macosforge.org/projects/launchd/changeset/23871 Author: dsorresso at apple.com Date: 2009-03-26 14:48:16 -0700 (Thu, 26 Mar 2009) Log Message: ----------- "Tagging launchd-309 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-309/ Property changes on: tags/launchd-309 ___________________________________________________________________ Added: svn:ignore + build Added: svn:mergeinfo + /branches/PR-5092682:23731-23742 /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 /branches/PR-6132016:23719-23738 /branches/PR-6271234:23818-23822 /branches/PR-6562592:23812-23822 /branches/PR-6564965:23832-23851 /branches/PR-6589133:23810-23822 /branches/PR-6609410:23828 -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Sat Mar 28 00:38:55 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Sat, 28 Mar 2009 00:38:55 -0700 (PDT) Subject: [launchd-changes] [23872] trunk/launchd/src Message-ID: <20090328073855.72DC813164FC@beta.macosforge.org> Revision: 23872 http://trac.macosforge.org/projects/launchd/changeset/23872 Author: dsorresso at apple.com Date: 2009-03-28 00:38:54 -0700 (Sat, 28 Mar 2009) Log Message: ----------- launchd complains too much Modified Paths: -------------- trunk/launchd/src/launchctl.c trunk/launchd/src/launchd.c trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c trunk/launchd/src/launchd_runtime.h trunk/launchd/src/libbootstrap.c trunk/launchd/src/vproc_priv.h Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2009-03-26 21:48:16 UTC (rev 23871) +++ trunk/launchd/src/launchctl.c 2009-03-28 07:38:54 UTC (rev 23872) @@ -2049,13 +2049,8 @@ _vproc_set_global_on_demand(true); -#if !TARGET_OS_EMBEDDED char *load_launchd_items[] = { "load", "-D", "all", "/etc/mach_init.d", NULL }; int load_launchd_items_cnt = 4; -#else - char *load_launchd_items[] = { "load", "-D", "all", "/etc/mach_init.d", "/var/mobile/Library/LaunchAgents", NULL }; - int load_launchd_items_cnt = 5; -#endif if (is_safeboot()) { load_launchd_items[2] = "system"; @@ -3088,10 +3083,6 @@ static void tell_launchd_about_boot_args(void) { - if( !g_shutdown_debugging ) { - return; - } - CFTypeRef value = NULL; do { io_registry_entry_t entry = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/options"); @@ -3116,8 +3107,14 @@ g_booting_verbose = CFStringFindWithOptions(value, CFSTR("-v"), range, 0, &found_range); CFRelease(value); - - assumes(vproc_swap_integer(NULL, VPROC_GSK_SHUTDOWN_DEBUGGING, (int64_t *)&g_booting_verbose, NULL) == KERN_SUCCESS); + + if( g_booting_verbose ) { + assumes(vproc_swap_integer(NULL, VPROC_GSK_VERBOSE_BOOT, (int64_t *)&g_booting_verbose, NULL) == KERN_SUCCESS); + + if( g_shutdown_debugging ) { + assumes(vproc_swap_integer(NULL, VPROC_GSK_SHUTDOWN_DEBUGGING, (int64_t *)&g_booting_verbose, NULL) == KERN_SUCCESS); + } + } } } Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2009-03-26 21:48:16 UTC (rev 23871) +++ trunk/launchd/src/launchd.c 2009-03-28 07:38:54 UTC (rev 23872) @@ -205,9 +205,9 @@ } if( pid1_magic ) { - runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "*** launchd[1] has started up. ***"); + runtime_syslog(LOG_NOTICE | LOG_CONSOLE_FORCE, "*** launchd[1] has started up. ***"); if( g_use_gmalloc ) { - runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "*** Using libgmalloc ***"); + runtime_syslog(LOG_NOTICE | LOG_CONSOLE_FORCE, "*** Using libgmalloc ***"); } /* PID 1 doesn't have a flat namespace. */ @@ -295,7 +295,7 @@ switch ((p = fork())) { case -1: - runtime_syslog(LOG_ERR | LOG_CONSOLE, "Can't fork PID 1 copy for crash debugging: %m"); + runtime_syslog(LOG_ERR | LOG_CONSOLE_FORCE, "Can't fork PID 1 copy for crash debugging: %m"); return p; case 0: return p; @@ -426,7 +426,7 @@ }; if( !launchd_assumes(setaudit_addr(&auinfo, sizeof(auinfo)) != -1) ) { - runtime_syslog(LOG_WARNING | LOG_CONSOLE, "Could not set audit session! (errno = %d)", errno); + runtime_syslog(LOG_WARNING | LOG_CONSOLE_FORCE, "Could not set audit session: %s.", strerror(errno)); _exit(EXIT_FAILURE); } @@ -502,7 +502,7 @@ now = runtime_get_wall_time(); char *term_who = pid1_magic ? "System shutdown" : "Per-user launchd termination for "; - runtime_syslog(LOG_NOTICE, "%s%s began", term_who, pid1_magic ? "" : g_username); + runtime_syslog(LOG_INFO, "%s%s began", term_who, pid1_magic ? "" : g_username); launchd_assert(jobmgr_shutdown(root_jobmgr) != NULL); Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-03-26 21:48:16 UTC (rev 23871) +++ trunk/launchd/src/launchd_core_logic.c 2009-03-28 07:38:54 UTC (rev 23872) @@ -160,18 +160,6 @@ static bool waiting4exit_new(job_t j, mach_port_t rp); static void waiting4exit_delete(job_t j, struct waiting_for_exit *w4e); -struct mspolicy { - SLIST_ENTRY(mspolicy) sle; - unsigned int allow:1, per_pid:1, __junk:30; - const char name[0]; -}; - -static bool mspolicy_new(job_t j, const char *name, bool allow, bool pid_local, bool skip_check); -static bool mspolicy_copy(job_t j_to, job_t j_from); -static void mspolicy_setup(launch_data_t obj, const char *key, void *context); -static bool mspolicy_check(job_t j, const char *name, bool pid_local); -static void mspolicy_delete(job_t j, struct mspolicy *msp); - struct machservice { SLIST_ENTRY(machservice) sle; SLIST_ENTRY(machservice) special_port_sle; @@ -429,7 +417,6 @@ SLIST_HEAD(, envitem) global_env; SLIST_HEAD(, envitem) env; SLIST_HEAD(, limititem) limits; - SLIST_HEAD(, mspolicy) mspolicies; SLIST_HEAD(, machservice) machservices; SLIST_HEAD(, semaphoreitem) semaphores; SLIST_HEAD(, waiting_for_removal) removal_watchers; @@ -633,10 +620,8 @@ static size_t our_strhash(const char *s) __attribute__((pure)); static void extract_rcsid_substr(const char *i, char *o, size_t osz); static void simulate_pid1_crash(void); -static pid_t spawn_sync(job_t j); static pid_t basic_spawn(job_t j, void (*what_to_do)(job_t)); static void take_sample(job_t j); -static void do_sync(job_t j); void eliminate_double_reboot(void); @@ -665,6 +650,7 @@ mach_port_t inherited_bootstrap_port; jobmgr_t root_jobmgr; bool g_shutdown_debugging = false; +bool g_verbose_boot = false; void job_ignore(job_t j) @@ -1028,7 +1014,6 @@ struct socketgroup *sg; struct machservice *ms; struct limititem *li; - struct mspolicy *msp; struct envitem *ei; if (unlikely(j->p)) { @@ -1082,9 +1067,6 @@ job_assumes(j, launchd_mport_deallocate(j->wait_reply_port) == KERN_SUCCESS); } - while ((msp = SLIST_FIRST(&j->mspolicies))) { - mspolicy_delete(j, msp); - } while ((sg = SLIST_FIRST(&j->sockets))) { socketgroup_delete(j, sg); } @@ -1420,12 +1402,8 @@ jr->unload_at_mig_return = true; } - if (jp) { - job_assumes(jr, mspolicy_copy(jr, jp)); - } - if (unlikely(shutdown_state && jm->hopefully_first_cnt == 0)) { - job_log(jr, LOG_APPLEONLY, "This process showed up to the party while all the guests were leaving. Odds are that it will have a miserable time."); + job_log(jr, LOG_SCOLDING, "This process showed up to the party while all the guests were leaving. Odds are that it will have a miserable time."); } job_log(jr, LOG_DEBUG, "Created PID %u anonymously by PPID %u%s%s", anonpid, kp.kp_eproc.e_ppid, jp ? ": " : "", jp ? jp->label : ""); @@ -2047,8 +2025,6 @@ case 'M': if (strcasecmp(key, LAUNCH_JOBKEY_MACHSERVICES) == 0) { launch_data_dict_iterate(value, machservice_setup, j); - } else if (strcasecmp(key, LAUNCH_JOBKEY_MACHSERVICELOOKUPPOLICIES) == 0) { - launch_data_dict_iterate(value, mspolicy_setup, j); } break; default: @@ -2686,8 +2662,10 @@ while( (ji = LIST_FIRST(&j->suspended_perusers)) ) { job_log(j, LOG_ERR, "Job exited before resuming per-user launchd for UID %u. Will forcibly resume.", ji->mach_uid); ji->peruser_suspend_count--; + if( ji->peruser_suspend_count == 0 ) { + LIST_REMOVE(ji, suspended_peruser_sle); + } job_dispatch(ji, false); - LIST_REMOVE(ji, suspended_peruser_sle); } struct waiting_for_exit *w4e = NULL; @@ -2754,42 +2732,7 @@ } } -/* Maybe someday... */ pid_t -spawn_sync(job_t j) -{ - pid_t p = 0; - char *sync_args[] = { "/bin/sync", NULL }; - switch( (p = vfork()) ) { - case 0 : - execve("/bin/sync", sync_args, environ); - _exit(EXIT_FAILURE); - case -1 : - job_log(j, LOG_NOTICE, "vfork(2) failed: %d", errno); - break; - default : - break; - } - - int r = -1; - if( p != -1 ) { - /* Let us know when the process is done. ONESHOT is implicit if we're just interested in NOTE_EXIT. */ - if( !job_assumes(j, (r = kevent_mod(p, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, j)) != -1) ) { - if( errno != ESRCH ) { - job_assumes(j, runtime_kill(p, SIGKILL) != -1); - } - } - - int status = 0; - if( r == -1 ) { - job_assumes(j, waitpid(p, &status, WNOHANG) != -1); - } - } - - return p; -} - -pid_t basic_spawn(job_t j, void (*what_to_do)(job_t)) { pid_t p = 0; @@ -2869,14 +2812,6 @@ _exit(EXIT_FAILURE); } -void -do_sync(job_t j __attribute__((unused))) -{ - char *sync_args[] = { "/bin/sync", NULL }; - execve(sync_args[0], sync_args, environ); - _exit(EXIT_FAILURE); -} - void jobmgr_dequeue_next_sample(jobmgr_t jm) { @@ -2941,7 +2876,7 @@ } if( strncmp(si->what, j->label, strlen(j->label)) == 0 ) { - job_log(ji, LOG_NOTICE | LOG_CONSOLE, "Dispatching out of interest in \"%s\".", j->label); + job_log(ji, LOG_DEBUG, "Dispatching out of interest in \"%s\".", j->label); job_dispatch(ji, false); /* ji could be removed here, so don't do anything with it or its semaphores @@ -3213,7 +3148,7 @@ return; } else if( j->tracing_pid && !j->reap_after_trace ) { /* The job exited before our sample completed. */ - job_log(j, LOG_NOTICE | LOG_CONSOLE, "Job has exited. Will reap after tracing PID %i exits.", j->tracing_pid); + job_log(j, LOG_DEBUG | LOG_CONSOLE, "Job has exited. Will reap after tracing PID %i exits.", j->tracing_pid); j->reap_after_trace = true; return; } @@ -3281,19 +3216,13 @@ job_log(j, LOG_DEBUG, "&j->start_interval == ident (%p)", ident); j->start_pending = true; job_dispatch(j, false); - } else if( do_sync == ident ) { - pid_t p = spawn_sync(j); - if( job_assumes(j, p != -1) ) { - job_log(j, LOG_NOTICE, "Starting update job (PID %i)", p); - s_update_pid = p; - } } else if (&j->exit_timeout == ident) { if( !job_assumes(j, j->p != 0) ) { return; } if( j->clean_kill ) { - job_log(j, LOG_DEBUG | LOG_CONSOLE, "Clean job failed to exit %u second after receiving SIGKILL.", LAUNCHD_CLEAN_KILL_TIMER); + job_log(j, LOG_ERR | 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; @@ -4087,7 +4016,7 @@ }; if( !launchd_assumes(setaudit_addr(&auinfo, sizeof(auinfo)) != -1) ) { - runtime_syslog(LOG_WARNING | LOG_CONSOLE, "Could not set audit session! (errno = %d)", errno); + runtime_syslog(LOG_WARNING, "Could not set audit session! (errno = %d)", errno); _exit(EXIT_FAILURE); } else { job_log(j, LOG_DEBUG, "Created new security session for per-user launchd."); @@ -4949,7 +4878,7 @@ if( strncmp(LAUNCHD_TRUSTED_FD_ENV, key, sizeof(LAUNCHD_TRUSTED_FD_ENV) - 1) != 0 ) { envitem_new(j, key, launch_data_get_string(obj), j->importing_global_env, true); } else { - job_log(j, LOG_WARNING, "Ignoring reserved environmental variable: %s", key); + job_log(j, LOG_DEBUG, "Ignoring reserved environmental variable: %s", key); } } @@ -5173,7 +5102,7 @@ wanted_state = true; case PATH_MISSING: if ((bool)(stat(si->what, &sb) == 0) == wanted_state) { - job_log(j, LOG_NOTICE, "KeepAlive: The following path %s: %s", wanted_state ? "exists" : "is missing", si->what); + job_log(j, LOG_DEBUG, "KeepAlive: The following path %s: %s", wanted_state ? "exists" : "is missing", si->what); return true; } else { if( wanted_state ) { /* File is not there but we wish it was. */ @@ -5700,12 +5629,12 @@ /* We might have some jobs hanging around that we've decided to shut down in spite of. */ job_t j = jobmgr_find_by_pid(jm, p_i, false); if( !j || (j && j->anonymous) ) { - jobmgr_log(jm, LOG_WARNING | LOG_CONSOLE, "Stray %s %s at shutdown: PID %u PPID %u PGID %u %s", z, j ? "anonymous job" : "process", p_i, pp_i, pg_i, n); + jobmgr_log(jm, LOG_INFO | LOG_CONSOLE, "Stray %s %s at shutdown: PID %u PPID %u PGID %u %s", z, j ? "anonymous job" : "process", p_i, pp_i, pg_i, n); int status = 0; if( pp_i == getpid() && !jobmgr_assumes(jm, kp[i].kp_proc.p_stat != SZOMB) ) { if( jobmgr_assumes(jm, waitpid(p_i, &status, WNOHANG) == 0) ) { - jobmgr_log(jm, LOG_NOTICE | LOG_CONSOLE, "Unreaped zombie stray exited with status %i.", WEXITSTATUS(status)); + jobmgr_log(jm, LOG_INFO | LOG_CONSOLE, "Unreaped zombie stray exited with status %i.", WEXITSTATUS(status)); } kp_skipped++; } else { @@ -5717,7 +5646,7 @@ } if( (kp_cnt - kp_skipped > 0) && kill_strays ) { - jobmgr_kill_stray_children(jm, ps, kp_cnt - kp_skipped); + jobmgr_kill_stray_children(jm, ps, kp_cnt); } free(ps); @@ -5940,7 +5869,7 @@ } if (jm->req_port == port) { - jobmgr_log(jm, LOG_DEBUG, "Request port died: 0x%x", port); + jobmgr_log(jm, LOG_INFO, "Request port died: 0x%x", port); return jobmgr_shutdown(jm); } @@ -6034,7 +5963,7 @@ return; } - job_log(ms->job, LOG_NOTICE, "Draining %s...", ms->name); + job_log(ms->job, LOG_INFO, "Draining %s...", ms->name); char req_buff[sizeof(union __RequestUnion__catch_mach_exc_subsystem) * 2]; char rep_buff[sizeof(union __ReplyUnion__catch_mach_exc_subsystem)]; @@ -6875,7 +6804,7 @@ goto out_bad; } - job_log(j, LOG_DEBUG | LOG_CONSOLE, "Location of job cache database: %s", launch_data_get_string(output_obj)); + job_log(j, LOG_DEBUG, "Location of job cache database: %s", launch_data_get_string(output_obj)); launch_data_free(output_obj); break; @@ -6892,7 +6821,7 @@ case VPROC_GSK_ENVIRONMENT: if( launch_data_get_type(input_obj) == LAUNCH_DATA_DICTIONARY ) { if( j->p ) { - job_log(j, LOG_NOTICE, "Setting environment for a currently active job. This environment will take effect on the next invocation of the job."); + job_log(j, LOG_INFO, "Setting environment for a currently active job. This environment will take effect on the next invocation of the job."); } launch_data_dict_iterate(input_obj, envitem_setup_one_shot, j); } @@ -7082,11 +7011,17 @@ j->wait4debugger_oneshot = inval; break; case VPROC_GSK_SHUTDOWN_DEBUGGING: - if( pid1_magic && j->is_bootstrapper ) { - runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "*** Shutdown debugging is enabled. ***"); - g_shutdown_debugging = true; + if( pid1_magic && j->is_bootstrapper && inval ) { + runtime_syslog(LOG_NOTICE | LOG_CONSOLE_FORCE, "*** Shutdown debugging is enabled. ***"); + g_shutdown_debugging = inval; } break; + case VPROC_GSK_VERBOSE_BOOT: + if( pid1_magic && j->is_bootstrapper && inval ) { + g_verbose_boot = inval; + runtime_syslog(LOG_NOTICE | LOG_CONSOLE, "*** Verbose boot, will log to /dev/console. ***"); + } + break; case VPROC_GSK_PERUSER_SUSPEND: if( pid1_magic && ldc->euid == 0 ) { mach_port_t junk = MACH_PORT_NULL; @@ -7363,6 +7298,7 @@ #if TARGET_OS_EMBEDDED /* There is no need for per-user launchd's on embedded. */ + job_log(j, LOG_ERR, "Per-user launchds are not supported on this platform."); return BOOTSTRAP_NOT_PRIVILEGED; #endif @@ -7376,7 +7312,7 @@ return BOOTSTRAP_NO_MEMORY; } - job_log(j, LOG_DEBUG, "Looking up per user launchd for UID: %u", which_user); + job_log(j, LOG_INFO, "Looking up per user launchd for UID: %u", which_user); if (unlikely(!pid1_magic)) { job_log(j, LOG_ERR, "Only PID 1 supports per user launchd lookups."); @@ -7422,14 +7358,14 @@ } if (!(j->anonymous || j->legacy_LS_job || j->legacy_mach_job)) { - job_log(j, LOG_APPLEONLY, "Please add the following service to the configuration file for this job: %s", servicename); + job_log(j, LOG_SCOLDING, "Please add the following service to the configuration file for this job: %s", servicename); } } else { if (unlikely((jo = machservice_job(ms)) != j)) { static pid_t last_warned_pid; if (last_warned_pid != ldc->pid) { - job_log(j, LOG_NOTICE, "Check-in of Mach service failed. The service \"%s\" is owned by: %s", servicename, jo->label); + job_log(jo, LOG_WARNING, "The following job tried to hijack the service \"%s\" from this job: %s", servicename, j->label); last_warned_pid = ldc->pid; } @@ -7461,7 +7397,7 @@ } if (!(flags & BOOTSTRAP_PER_PID_SERVICE) && !j->legacy_LS_job) { - job_log(j, LOG_APPLEONLY, "Performance: bootstrap_register() is deprecated. Service: %s", servicename); + job_log(j, LOG_SCOLDING, "Performance: bootstrap_register() is deprecated. Service: %s", servicename); } job_log(j, LOG_DEBUG, "%sMach service registration attempt: %s", flags & BOOTSTRAP_PER_PID_SERVICE ? "Per PID " : "", servicename); @@ -7530,11 +7466,6 @@ } #endif - if (unlikely(!mspolicy_check(j, servicename, per_pid_lookup))) { - job_log(j, LOG_NOTICE, "Policy denied Mach service lookup: %s", servicename); - return BOOTSTRAP_NOT_PRIVILEGED; - } - #if HAVE_SANDBOX if (unlikely(sandbox_check(ldc->pid, "mach-lookup", per_pid_lookup ? SANDBOX_FILTER_LOCAL_NAME : SANDBOX_FILTER_GLOBAL_NAME, servicename) > 0)) { return BOOTSTRAP_NOT_PRIVILEGED; @@ -7629,7 +7560,7 @@ return BOOTSTRAP_NO_MEMORY; } - jm = g_flat_mach_namespace ? root_jobmgr : j->mgr; + jm = (g_flat_mach_namespace && !j->mgr->created_via_subset) ? root_jobmgr : j->mgr; unsigned int i = 0; struct machservice *msi = NULL; @@ -8380,7 +8311,10 @@ return BOOTSTRAP_NO_MEMORY; } - if (!job_assumes(j, (jmr = jobmgr_new(j->mgr, requestorport, MACH_PORT_NULL, false, NULL, j->audit_session)) != NULL)) { + char name[NAME_MAX]; + snprintf(name, sizeof(name), "bootstrap_subset(%u)->%s[%i]", requestorport, j->anonymous ? j->prog : j->label, j->p); + + if (!job_assumes(j, (jmr = jobmgr_new(j->mgr, requestorport, MACH_PORT_NULL, false, name, j->audit_session)) != NULL)) { if (unlikely(requestorport == MACH_PORT_NULL)) { return BOOTSTRAP_NOT_PRIVILEGED; } @@ -8650,87 +8584,6 @@ } bool -mspolicy_copy(job_t j_to, job_t j_from) -{ - struct mspolicy *msp; - - SLIST_FOREACH(msp, &j_from->mspolicies, sle) { - if (!mspolicy_new(j_to, msp->name, msp->allow, msp->per_pid, true)) { - return false; - } - } - - return true; -} - -bool -mspolicy_new(job_t j, const char *name, bool allow, bool pid_local, bool skip_check) -{ - struct mspolicy *msp; - - if (!skip_check) SLIST_FOREACH(msp, &j->mspolicies, sle) { - if (msp->per_pid != pid_local) { - continue; - } else if (strcmp(msp->name, name) == 0) { - errno = EEXIST; - return false; - } - } - - msp = calloc(1, sizeof(struct mspolicy) + strlen(name) + 1); - - if (!job_assumes(j, msp != NULL)) { - return false; - } - - strcpy((char *)msp->name, name); - msp->per_pid = pid_local; - msp->allow = allow; - - SLIST_INSERT_HEAD(&j->mspolicies, msp, sle); - - return true; -} - -void -mspolicy_setup(launch_data_t obj, const char *key, void *context) -{ - job_t j = context; - - if (launch_data_get_type(obj) != LAUNCH_DATA_BOOL) { - job_log(j, LOG_WARNING, "Invalid object type for Mach service policy key: %s", key); - return; - } - - job_assumes(j, mspolicy_new(j, key, launch_data_get_bool(obj), false, false)); -} - -bool -mspolicy_check(job_t j, const char *name, bool pid_local) -{ - struct mspolicy *mspi; - - SLIST_FOREACH(mspi, &j->mspolicies, sle) { - if (mspi->per_pid != pid_local) { - continue; - } else if (strcmp(mspi->name, name) != 0) { - continue; - } - return mspi->allow; - } - - return !j->deny_unknown_mslookups; -} - -void -mspolicy_delete(job_t j, struct mspolicy *msp) -{ - SLIST_REMOVE(&j->mspolicies, msp, mspolicy, sle); - - free(msp); -} - -bool waiting4removal_new(job_t j, mach_port_t rp) { struct waiting_for_removal *w4r; Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2009-03-26 21:48:16 UTC (rev 23871) +++ trunk/launchd/src/launchd_runtime.c 2009-03-28 07:38:54 UTC (rev 23872) @@ -134,6 +134,7 @@ bool g_simulate_pid1_crash = false; bool g_use_gmalloc = false; bool g_log_per_user_shutdown = false; +bool g_log_strict_usage = false; pid_t g_wsp = 0; mach_port_t @@ -1009,10 +1010,10 @@ mr = mach_msg(&bufRequest->Head, rcv_options, 0, rcv_msg_size, port, to, MACH_PORT_NULL); switch( mr ) { case MACH_RCV_TIMED_OUT : - runtime_syslog(LOG_NOTICE, "Message queue is empty."); + runtime_syslog(LOG_DEBUG, "Message queue is empty."); break; case MACH_RCV_TOO_LARGE : - runtime_syslog(LOG_NOTICE, "Message is larger than %u bytes.", rcv_msg_size); + runtime_syslog(LOG_INFO, "Message is larger than %u bytes.", rcv_msg_size); break; default : launchd_assumes(mr == MACH_MSG_SUCCESS); @@ -1110,7 +1111,7 @@ case MACH_RCV_TIMED_OUT: if (to != MACH_MSG_TIMEOUT_NONE) { if (busy_cnt == 0) { - runtime_syslog(LOG_NOTICE, "Idle exiting. (This message will be removed before shipping.)"); + runtime_syslog(LOG_INFO, "Idle exiting."); launchd_shutdown(); } else if (runtime_idle_callback) { runtime_idle_callback(); @@ -1238,8 +1239,8 @@ void runtime_syslog(int pri, const char *message, ...) { - bool log_to_console = pri & LOG_CONSOLE; - int _pri = pri & ~LOG_CONSOLE; + bool log_to_console = (( pri & LOG_CONSOLE ) && g_verbose_boot) || ( pri & LOG_CONSOLE_FORCE ); + int _pri = pri & ~(LOG_CONSOLE | LOG_CONSOLE_FORCE); struct runtime_syslog_attr attr = { g_my_label, @@ -1270,6 +1271,8 @@ } else { return; } + } else if( attr->priority == LOG_SCOLDING ) { + attr->priority = g_log_strict_usage ? LOG_NOTICE : LOG_DEBUG; } if (!(LOG_MASK(attr->priority) & internal_mask_pri)) { @@ -1576,7 +1579,7 @@ if (!pid1_magic) { #if !TARGET_OS_EMBEDDED if( _vproc_transaction_count() == 0 ) { - runtime_syslog(LOG_NOTICE, "Exiting cleanly."); + runtime_syslog(LOG_INFO, "Exiting cleanly."); } runtime_closelog(); @@ -1815,4 +1818,8 @@ if( pid1_magic && stat("/var/db/.launchd_use_gmalloc", &sb) == 0 ) { g_use_gmalloc = true; } + + if( stat("/var/db/.launchd_log_strict_usage", &sb) == 0 ) { + g_log_strict_usage = true; + } } Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2009-03-26 21:48:16 UTC (rev 23871) +++ trunk/launchd/src/launchd_runtime.h 2009-03-28 07:38:54 UTC (rev 23872) @@ -103,8 +103,10 @@ extern char g_username[128]; extern char g_my_label[128]; extern bool g_shutdown_debugging; +extern bool g_verbose_boot; extern bool g_use_gmalloc; extern bool g_log_per_user_shutdown; +extern bool g_log_strict_usage; extern pid_t g_wsp; mach_port_t runtime_get_kernel_port(void); @@ -146,8 +148,10 @@ kern_return_t runtime_log_forward(uid_t forward_uid, gid_t forward_gid, vm_offset_t inval, mach_msg_type_number_t invalCnt); kern_return_t runtime_log_drain(mach_port_t srp, vm_offset_t *outval, mach_msg_type_number_t *outvalCnt); -#define LOG_APPLEONLY 0x4141504c /* AAPL in hex */ -#define LOG_CONSOLE (1 << 31) +#define LOG_APPLEONLY 0x4141504c /* AAPL in hex */ +#define LOG_SCOLDING 0x3030493b +#define LOG_CONSOLE (1 << 31) +#define LOG_CONSOLE_FORCE (1 << 30) struct runtime_syslog_attr { const char *from_name; Modified: trunk/launchd/src/libbootstrap.c =================================================================== --- trunk/launchd/src/libbootstrap.c 2009-03-26 21:48:16 UTC (rev 23871) +++ trunk/launchd/src/libbootstrap.c 2009-03-28 07:38:54 UTC (rev 23872) @@ -137,13 +137,10 @@ bootstrap_look_up_per_user(mach_port_t bp, const name_t service_name, uid_t target_user, mach_port_t *sp) { audit_token_t au_tok; - struct stat sb; kern_return_t kr; mach_port_t puc; - if (pthread_main_np() && (stat("/AppleInternal", &sb) != -1)) { - _vproc_log(LOG_WARNING, "Please review the comments in 4890134."); - } + /* See rdar://problem/4890134. */ if ((kr = vproc_mig_lookup_per_user_context(bp, target_user, &puc)) != 0) { return kr; Modified: trunk/launchd/src/vproc_priv.h =================================================================== --- trunk/launchd/src/vproc_priv.h 2009-03-26 21:48:16 UTC (rev 23871) +++ trunk/launchd/src/vproc_priv.h 2009-03-28 07:38:54 UTC (rev 23872) @@ -64,6 +64,7 @@ VPROC_GSK_WAITFORDEBUGGER, VPROC_GSK_SECURITYSESSION, VPROC_GSK_SHUTDOWN_DEBUGGING, + VPROC_GSK_VERBOSE_BOOT, VPROC_GSK_PERUSER_SUSPEND, VPROC_GSK_PERUSER_RESUME, VPROC_GSK_JOB_OVERRIDES_DB, -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Sat Mar 28 13:39:22 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Sat, 28 Mar 2009 13:39:22 -0700 (PDT) Subject: [launchd-changes] [23873] trunk/launchd/src/launchd_core_logic.c Message-ID: <20090328203922.E9F29131E580@beta.macosforge.org> Revision: 23873 http://trac.macosforge.org/projects/launchd/changeset/23873 Author: dsorresso at apple.com Date: 2009-03-28 13:39:22 -0700 (Sat, 28 Mar 2009) Log Message: ----------- Small change to naming of bootstrap subsets. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-03-28 07:38:54 UTC (rev 23872) +++ trunk/launchd/src/launchd_core_logic.c 2009-03-28 20:39:22 UTC (rev 23873) @@ -8312,7 +8312,7 @@ } char name[NAME_MAX]; - snprintf(name, sizeof(name), "bootstrap_subset(%u)->%s[%i]", requestorport, j->anonymous ? j->prog : j->label, j->p); + snprintf(name, sizeof(name), "bootstrap_subset(%u)->%s[%i]", MACH_PORT_INDEX(requestorport), j->anonymous ? j->prog : j->label, j->p); if (!job_assumes(j, (jmr = jobmgr_new(j->mgr, requestorport, MACH_PORT_NULL, false, name, j->audit_session)) != NULL)) { if (unlikely(requestorport == MACH_PORT_NULL)) { -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Sat Mar 28 14:14:04 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Sat, 28 Mar 2009 14:14:04 -0700 (PDT) Subject: [launchd-changes] [23874] tags/launchd-310/ Message-ID: <20090328211404.A65E8131EB6A@beta.macosforge.org> Revision: 23874 http://trac.macosforge.org/projects/launchd/changeset/23874 Author: dsorresso at apple.com Date: 2009-03-28 14:14:03 -0700 (Sat, 28 Mar 2009) Log Message: ----------- "Tagging launchd-310 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-310/ Property changes on: tags/launchd-310 ___________________________________________________________________ Added: svn:ignore + build Added: svn:mergeinfo + /branches/PR-5092682:23731-23742 /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 /branches/PR-6132016:23719-23738 /branches/PR-6271234:23818-23822 /branches/PR-6562592:23812-23822 /branches/PR-6564965:23832-23851 /branches/PR-6589133:23810-23822 /branches/PR-6609410:23828 -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Mon Mar 30 16:02:31 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Mon, 30 Mar 2009 16:02:31 -0700 (PDT) Subject: [launchd-changes] [23875] trunk/launchd/src Message-ID: <20090330230231.D96091352D25@beta.macosforge.org> Revision: 23875 http://trac.macosforge.org/projects/launchd/changeset/23875 Author: dsorresso at apple.com Date: 2009-03-30 16:02:31 -0700 (Mon, 30 Mar 2009) Log Message: ----------- launchd is writing out to /var/log and shouldn't Modified Paths: -------------- trunk/launchd/src/launchd_runtime.c trunk/launchd/src/launchd_runtime.h Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2009-03-28 21:14:03 UTC (rev 23874) +++ trunk/launchd/src/launchd_runtime.c 2009-03-30 23:02:31 UTC (rev 23875) @@ -134,6 +134,11 @@ bool g_simulate_pid1_crash = false; bool g_use_gmalloc = false; bool g_log_per_user_shutdown = false; +#if !TARGET_OS_EMBEDDED +bool g_log_pid1_shutdown = true; +#else +bool g_log_pid1_shutdown = false; +#endif bool g_log_strict_usage = false; pid_t g_wsp = 0; @@ -1456,10 +1461,9 @@ launchd_log_vm_stats(); } - pthread_mutex_lock(&ourlock); - if (unlikely(ourlogfile == NULL)) { + if( unlikely(ourlogfile == NULL) && g_log_pid1_shutdown ) { rename("/var/log/launchd-shutdown.log", "/var/log/launchd-shutdown.log.1"); ourlogfile = fopen("/var/log/launchd-shutdown.log", "a"); } @@ -1819,6 +1823,10 @@ g_use_gmalloc = true; } + if( pid1_magic && stat("/var/db/.launchd_log_pid1_shutdown", &sb) ) { + g_log_pid1_shutdown = true; + } + if( stat("/var/db/.launchd_log_strict_usage", &sb) == 0 ) { g_log_strict_usage = true; } Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2009-03-28 21:14:03 UTC (rev 23874) +++ trunk/launchd/src/launchd_runtime.h 2009-03-30 23:02:31 UTC (rev 23875) @@ -107,6 +107,7 @@ extern bool g_use_gmalloc; extern bool g_log_per_user_shutdown; extern bool g_log_strict_usage; +extern bool g_embedded_shutdown_log; extern pid_t g_wsp; mach_port_t runtime_get_kernel_port(void); -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Mon Mar 30 21:24:57 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Mon, 30 Mar 2009 21:24:57 -0700 (PDT) Subject: [launchd-changes] [23876] trunk/launchd/src/launchd_runtime.c Message-ID: <20090331042457.D97401354EA5@beta.macosforge.org> Revision: 23876 http://trac.macosforge.org/projects/launchd/changeset/23876 Author: dsorresso at apple.com Date: 2009-03-30 21:24:57 -0700 (Mon, 30 Mar 2009) Log Message: ----------- Let's check for 0 instead. Modified Paths: -------------- trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2009-03-30 23:02:31 UTC (rev 23875) +++ trunk/launchd/src/launchd_runtime.c 2009-03-31 04:24:57 UTC (rev 23876) @@ -1823,7 +1823,7 @@ g_use_gmalloc = true; } - if( pid1_magic && stat("/var/db/.launchd_log_pid1_shutdown", &sb) ) { + if( pid1_magic && stat("/var/db/.launchd_log_pid1_shutdown", &sb) == 0 ) { g_log_pid1_shutdown = true; } -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Tue Mar 31 15:38:05 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 31 Mar 2009 15:38:05 -0700 (PDT) Subject: [launchd-changes] [23877] tags/launchd-311/ Message-ID: <20090331223805.D8A761376F30@beta.macosforge.org> Revision: 23877 http://trac.macosforge.org/projects/launchd/changeset/23877 Author: dsorresso at apple.com Date: 2009-03-31 15:38:05 -0700 (Tue, 31 Mar 2009) Log Message: ----------- "Tagging launchd-311 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-311/ Property changes on: tags/launchd-311 ___________________________________________________________________ Added: svn:ignore + build Added: svn:mergeinfo + /branches/PR-5092682:23731-23742 /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 /branches/PR-6132016:23719-23738 /branches/PR-6271234:23818-23822 /branches/PR-6562592:23812-23822 /branches/PR-6564965:23832-23851 /branches/PR-6589133:23810-23822 /branches/PR-6609410:23828 -------------- next part -------------- An HTML attachment was scrubbed... URL: From source_changes at macosforge.org Tue Mar 31 17:24:58 2009 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 31 Mar 2009 17:24:58 -0700 (PDT) Subject: [launchd-changes] [23878] trunk/launchd/src/launchd_core_logic.c Message-ID: <20090401002459.8853E13B6594@beta.macosforge.org> Revision: 23878 http://trac.macosforge.org/projects/launchd/changeset/23878 Author: dsorresso at apple.com Date: 2009-03-31 17:24:58 -0700 (Tue, 31 Mar 2009) Log Message: ----------- launchd needs to reset one-shot environment variables right after fork(2), not during reap Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2009-03-31 22:38:05 UTC (rev 23877) +++ trunk/launchd/src/launchd_core_logic.c 2009-04-01 00:24:58 UTC (rev 23878) @@ -2505,8 +2505,6 @@ job_mig_swap_integer(j, VPROC_GSK_WEIRD_BOOTSTRAP, 0, 0, &junk); } - j->wait4debugger_oneshot = false; - if (j->log_redirect_fd && !j->legacy_LS_job) { job_log_stdouterr(j); /* one last chance */ @@ -2650,14 +2648,7 @@ } } } - - struct envitem *ei = NULL, *et = NULL; - SLIST_FOREACH_SAFE( ei, &j->env, sle, et ) { - if( ei->one_shot ) { - SLIST_REMOVE(&j->env, ei, envitem, sle); - } - } - + job_t ji = NULL; while( (ji = LIST_FIRST(&j->suspended_perusers)) ) { job_log(j, LOG_ERR, "Job exited before resuming per-user launchd for UID %u. Will forcibly resume.", ji->mach_uid); @@ -3577,6 +3568,15 @@ job_reap(j); } + j->wait4debugger_oneshot = false; + + struct envitem *ei = NULL, *et = NULL; + SLIST_FOREACH_SAFE( ei, &j->env, sle, et ) { + if( ei->one_shot ) { + SLIST_REMOVE(&j->env, ei, envitem, sle); + } + } + if (likely(!j->stall_before_exec)) { job_uncork_fork(j); } @@ -5818,11 +5818,6 @@ #if TARGET_OS_EMBEDDED bootstrapper->stderrpath = strdup(_PATH_CONSOLE); #endif - - #if 0 - /* Start the update job. */ - jobmgr_assumes(jm, kevent_mod((uintptr_t)do_sync, EVFILT_TIMER, EV_ADD, NOTE_SECONDS, 30, bootstrapper) != -1); - #endif jobmgr_assumes(jm, kevent_mod((uintptr_t)fileno(g_console), EVFILT_VNODE, EV_ADD | EV_ONESHOT, NOTE_REVOKE, 0, jm) != -1); } -------------- next part -------------- An HTML attachment was scrubbed... URL: