]> git.saurik.com Git - apple/launchd.git/commitdiff
launchd-392.35.tar.gz mac-os-x-1072 v392.35
authorApple <opensource@apple.com>
Wed, 12 Oct 2011 14:39:22 +0000 (14:39 +0000)
committerApple <opensource@apple.com>
Wed, 12 Oct 2011 14:39:22 +0000 (14:39 +0000)
13 files changed:
launchd.xcodeproj/project.pbxproj
launchd/src/IPC.h
launchd/src/StartupItems.h
launchd/src/SystemStarter.h
launchd/src/SystemStarterIPC.h
launchd/src/config.h
launchd/src/launchctl.c
launchd/src/launchd.c
launchd/src/launchd_core_logic.c
launchd/src/launchd_ktrace.h
launchd/src/launchd_runtime.c
launchd/src/launchproxy.c
launchd/src/libvproc.c

index 0218d29125552bb11b8cabd95fc56e9e72638813..d8c88e119934293577e2cd3c0e1e3d1138bd73a5 100644 (file)
@@ -78,6 +78,7 @@
                4B1D92010F8BDE7D00125940 /* launchd.ops in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B1D91ED0F8BDE1A00125940 /* launchd.ops */; };
                4B287733111A509400C07B35 /* launchd_helper.defs in Sources */ = {isa = PBXBuildFile; fileRef = 4B287732111A509400C07B35 /* launchd_helper.defs */; settings = {ATTRIBUTES = (Client, Server, ); }; };
                4B28781B111A61A400C07B35 /* launchd_helper.defs in Sources */ = {isa = PBXBuildFile; fileRef = 4B287732111A509400C07B35 /* launchd_helper.defs */; };
+               4B43EAF414101C5800E9E776 /* ServiceManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B43EAF314101C5800E9E776 /* ServiceManagement.framework */; };
                4B9A1C1F132759F700019C67 /* events.defs in Sources */ = {isa = PBXBuildFile; fileRef = 4B0A30FF131F24AC002DE2E5 /* events.defs */; settings = {ATTRIBUTES = (Server, ); }; };
                4B9EDCA20EAFC77E00A78496 /* DiskArbitration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B9EDCA10EAFC77E00A78496 /* DiskArbitration.framework */; };
                4BA2F5FD1243063D00C2AADD /* init.defs in Sources */ = {isa = PBXBuildFile; fileRef = 4BA2F5FC1243063D00C2AADD /* init.defs */; };
                4B10F1F30F43BF5C00875782 /* launchctl */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = launchctl; sourceTree = BUILT_PRODUCTS_DIR; };
                4B1D91ED0F8BDE1A00125940 /* launchd.ops */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = launchd.ops; path = launchd/src/launchd.ops; sourceTree = "<group>"; };
                4B287732111A509400C07B35 /* launchd_helper.defs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.mig; name = launchd_helper.defs; path = launchd/src/launchd_helper.defs; sourceTree = "<group>"; };
+               4B43EAF314101C5800E9E776 /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = /System/Library/Frameworks/ServiceManagement.framework; sourceTree = "<absolute>"; };
                4B9EDCA10EAFC77E00A78496 /* DiskArbitration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DiskArbitration.framework; path = /System/Library/Frameworks/DiskArbitration.framework; sourceTree = "<absolute>"; };
                4BA2F5FC1243063D00C2AADD /* init.defs */ = {isa = PBXFileReference; explicitFileType = sourcecode.mig; fileEncoding = 4; name = init.defs; path = /usr/local/include/xpc/init.defs; sourceTree = SDKROOT; };
                7215DE4B0EFAF2EC00ABD81E /* libauditd.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libauditd.dylib; path = /usr/lib/libauditd.dylib; sourceTree = "<absolute>"; };
                        isa = PBXFrameworksBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               4B43EAF414101C5800E9E776 /* ServiceManagement.framework in Frameworks */,
                                FCC841CC0EA7138700C01666 /* IOKit.framework in Frameworks */,
                                FC3628080E9345E10054F1A3 /* CoreFoundation.framework in Frameworks */,
                                FCD713740E95DE49001B0111 /* libedit.dylib in Frameworks */,
                FC36280C0E9345F60054F1A3 /* Frameworks */ = {
                        isa = PBXGroup;
                        children = (
+                               4B43EAF314101C5800E9E776 /* ServiceManagement.framework */,
                                4B9EDCA10EAFC77E00A78496 /* DiskArbitration.framework */,
                                FC36292C0E934AA40054F1A3 /* libbsm.dylib */,
                                7215DE4B0EFAF2EC00ABD81E /* libauditd.dylib */,
                        );
                        runOnlyForDeploymentPostprocessing = 1;
                        shellPath = /bin/sh;
-                       shellScript = "install -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/System/Library/LaunchAgents\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/System/Library/LaunchDaemons\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/Library/LaunchAgents\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/Library/LaunchDaemons\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/private/etc/mach_init.d\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/private/etc/mach_init_per_login_session.d\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/private/etc/mach_init_per_user.d\n/Developer/Makefiles/bin/compress-man-pages.pl -d \"$DSTROOT\" /usr/share/man";
+                       shellScript = "install -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/System/Library/LaunchAgents\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/System/Library/LaunchDaemons\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/Library/LaunchAgents\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/Library/LaunchDaemons\n/Developer/Makefiles/bin/compress-man-pages.pl -d \"$DSTROOT\" /usr/share/man";
                        showEnvVarsInLog = 0;
                };
                FC7B87B20EA7195F00542082 /* ShellScript */ = {
                        );
                        runOnlyForDeploymentPostprocessing = 1;
                        shellPath = /bin/sh;
-                       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";
+                       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/bin/mkdir -p \"$DSTROOT/private/etc/mach_init.d\"\n/bin/mkdir -p \"$DSTROOT/private/etc/mach_init_per_user.d\"\n/bin/mkdir -p \"$DSTROOT/private/etc/mach_init_per_login_session.d\"\n/usr/sbin/chown root:wheel \"$DSTROOT/private/etc/mach_init.d\"\n/usr/sbin/chown root:wheel \"$DSTROOT/private/etc/mach_init_per_user.d\"\n/usr/sbin/chown root:wheel \"$DSTROOT/private/etc/mach_init_per_login_session.d\"";
                        showEnvVarsInLog = 0;
                };
                FC7B87EE0EA71A4900542082 /* ShellScript */ = {
                        );
                        runOnlyForDeploymentPostprocessing = 1;
                        shellPath = /bin/sh;
-                       shellScript = "install -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/System/Library/LaunchAgents\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/System/Library/LaunchDaemons\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/Library/LaunchAgents\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/Library/LaunchDaemons\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/private/etc/mach_init.d\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/private/etc/mach_init_per_login_session.d\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/private/etc/mach_init_per_user.d\n/Developer/Makefiles/bin/compress-man-pages.pl -d \"$DSTROOT\" /usr/share/man";
+                       shellScript = "install -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/System/Library/LaunchAgents\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/System/Library/LaunchDaemons\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/Library/LaunchAgents\ninstall -o \"$INSTALL_OWNER\" -g \"$INSTALL_GROUP\" -m 0755 -d \"$DSTROOT\"/Library/LaunchDaemons\n/Developer/Makefiles/bin/compress-man-pages.pl -d \"$DSTROOT\" /usr/share/man";
                        showEnvVarsInLog = 0;
                };
 /* End PBXShellScriptBuildPhase section */
index b28226c4aaa2d2faad66d8f49cbdbc9c7521f375..d85a4828ce3864cf4cddb316969565b95afc1f9e 100644 (file)
@@ -35,4 +35,4 @@
  **/
 void MonitorStartupItem (StartupContext aStartupContext, CFMutableDictionaryRef anItem);
 
-#endif
+#endif /* _IPC_H_ */
index 5cf6c086a0846435f3249d5fe35ca4ab1cb131bc..f50b47c7f29b6303da1ec06f5f9b4ae815f80f0f 100644 (file)
@@ -112,4 +112,4 @@ void StartupItemSetStatus(CFMutableDictionaryRef aStatusDict, CFMutableDictionar
  */
 bool StartupItemSecurityCheck(const char *aPath);
 
-#endif
+#endif /* _StartupItems_H_ */
index 417d30767247a161becc43826f290ef04a02f7a2..6a6c0ab0997b36a224802b54616bc18c2e51934d 100644 (file)
@@ -48,4 +48,4 @@ typedef enum {
 void CF_syslog(int level, CFStringRef message, ...);
 extern bool gVerboseFlag;
 
-#endif
+#endif /* _SYSTEM_STARTER_H_ */
index 9dc00238b4034e07b88a0cea354a01c38e6eab6c..3a94095f205b3cb47f2740db721ed00516c0ac99 100644 (file)
@@ -85,4 +85,4 @@ typedef struct SystemStarterIPCMessage {
 #define kIPCConfigSettingVerboseFlag   CFSTR("VerboseFlag")
 #define kIPCConfigSettingNetworkUp     CFSTR("NetworkUp")
 
-#endif
+#endif /* _SYSTEM_STARTER_IPC_H */
index 9f46ab6f317cc85c2bbf9854b02cfa53f0e8bae8..4c126644d1c8631df5de66608c17fb8be6fe8a2d 100644 (file)
@@ -4,4 +4,4 @@
 #define HAVE_QUARANTINE TARGET_HAVE_QUARANTINE
 #define HAVE_SANDBOX TARGET_HAVE_SANDBOX
 #define HAVE_LIBAUDITD !TARGET_OS_EMBEDDED
-#endif
+#endif /* __CONFIG_H__ */
index 3b86dcc8893a2ece8bf8f8bd4af9a5c0760292cd..25b3b3f52298a0a86eee792357e1cd733b5a90bb 100644 (file)
@@ -18,7 +18,7 @@
  * @APPLE_APACHE_LICENSE_HEADER_END@
  */
 
-static const char *const __rcs_file_version__ = "$Revision: 24957 $";
+static const char *const __rcs_file_version__ = "$Revision: 25182 $";
 
 #include "config.h"
 #include "launch.h"
@@ -33,6 +33,7 @@ static const char *const __rcs_file_version__ = "$Revision: 24957 $";
 #include <CoreFoundation/CoreFoundation.h>
 #include <CoreFoundation/CFPriv.h>
 #include <CoreFoundation/CFLogUtilities.h>
+#include <ServiceManagement/ServiceManagement_Private.h>
 #include <TargetConditionals.h>
 #include <IOKit/IOKitLib.h>
 #include <NSSystemDirectories.h>
@@ -2275,13 +2276,7 @@ bootstrap_cmd(int argc, char *const argv[])
                                load_launchd_items[6] = "local";
                                the_argc += 2;
                        }
-                       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 (strcasecmp(session_type, VPROCMGR_SESSION_AQUA) == 0) {
-                       load_launchd_items[5] = "/etc/mach_init_per_user.d";
-                       the_argc += 1;
                        /* 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
@@ -2290,7 +2285,7 @@ bootstrap_cmd(int argc, char *const argv[])
                         * risk of deadlocking against mount_url. But this fix should
                         * satisfy <rdar://problem/5279345>.
                         */
-                       the_argc_user = 5;
+                       the_argc_user = 4;
                        
                        /* We want to read environment.plist, which is in the user's home directory.
                         * Since the dance to mount a network home directory is fairly complex, all we
@@ -2320,6 +2315,9 @@ bootstrap_cmd(int argc, char *const argv[])
                        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);
+#if TARGET_OS_MAC
+                               _SMLoginItemBootstrapItems();
+#endif
                        }
                }
                
@@ -3685,7 +3683,7 @@ do_potential_fsck(void)
        const char *remount_tool[] = { "mount", "-uw", "/", NULL };
 #if TARGET_OS_EMBEDDED
        const char *nvram_tool[] = { "/usr/sbin/nvram", "auto-boot=false", NULL };
-#endif
+#endif /* TARGET_OS_EMBEDDED */
        struct statfs sfs;
 
        if (!assumes(statfs("/", &sfs) != -1)) {
index 78e173826f94899d7dc40d1a2e22b8e26310ba81..56e5807d894b2b83596c67cbf01275fa7c999e6d 100644 (file)
@@ -447,7 +447,7 @@ pid1_magic_init(void)
        runtime_syslog(LOG_DEBUG, "Audit Session ID: %i", g_audit_session);
 
        g_audit_session_port = _audit_session_self();
-#endif
+#endif // !TARGET_OS_EMBEDDED
        
        strcpy(g_launchd_database_dir, LAUNCHD_DB_PREFIX "/com.apple.launchd");
 }
@@ -555,7 +555,7 @@ launchd_SessionCreate(void)
        } else {
                runtime_syslog(LOG_WARNING, "Could not set audit session: %s.", strerror(errno));
        }
-#endif
+#endif // !TARGET_OS_EMBEDDED
 }
 
 void
index c04a496df5b75fe113d39197718b73621aaf4181..9e50f96a606aa3506b29baea8c30e62b9a21ab88 100644 (file)
@@ -16,7 +16,7 @@
  * @APPLE_APACHE_LICENSE_HEADER_END@
  */
 
-static const char *const __rcs_file_version__ = "$Revision: 24984 $";
+static const char *const __rcs_file_version__ = "$Revision: 25247 $";
 
 #include "config.h"
 #include "launchd_core_logic.h"
@@ -80,6 +80,7 @@ static const char *const __rcs_file_version__ = "$Revision: 24984 $";
 #include <System/sys/spawn.h>
 #include <spawn.h>
 #include <time.h>
+#include <libinfo.h>
 
 #include <libproc.h>
 #include <malloc/malloc.h>
@@ -95,6 +96,7 @@ static const char *const __rcs_file_version__ = "$Revision: 24984 $";
 #if TARGET_OS_EMBEDDED
 #include <sys/kern_memorystatus.h>
 #else
+extern int gL1CacheEnabled;
 /* To make my life easier. */
 typedef struct jetsam_priority_entry {
        pid_t pid;
@@ -133,7 +135,7 @@ enum {
 #if !TARGET_OS_EMBEDDED
 #include "domainServer.h"
 #include "init.h"
-#endif
+#endif /* !TARGET_OS_EMBEDDED */
 #include "eventsServer.h"
 
 #ifndef POSIX_SPAWN_OSX_TALAPP_START
@@ -219,7 +221,7 @@ static void machservice_resetport(job_t j, struct machservice *ms);
 static struct machservice *machservice_new(job_t j, const char *name, mach_port_t *serviceport, bool pid_local);
 #ifndef __LAUNCH_DISABLE_XPC_SUPPORT__
 static struct machservice *machservice_new_alias(job_t aj, struct machservice *orig);
-#endif
+#endif /* __LAUNCH_DISABLE_XPC_SUPPORT__ */
 static void machservice_ignore(job_t j, struct machservice *ms);
 static void machservice_watch(job_t j, struct machservice *ms);
 static void machservice_delete(job_t j, struct machservice *, bool port_died);
@@ -447,7 +449,7 @@ struct jobmgr_s {
 static jobmgr_t _s_xpc_system_domain;
 static LIST_HEAD(, jobmgr_s) _s_xpc_user_domains;
 static LIST_HEAD(, jobmgr_s) _s_xpc_session_domains;
-#endif
+#endif /* __LAUNCH_DISABLE_XPC_SUPPORT__ */
 
 #define jobmgr_assumes(jm, e)  \
        (unlikely(!(e)) ? jobmgr_log_bug(jm, __LINE__), false : true)
@@ -458,7 +460,7 @@ static jobmgr_t jobmgr_new_xpc_singleton_domain(jobmgr_t jm, name_t name);
 static jobmgr_t jobmgr_find_xpc_per_user_domain(jobmgr_t jm, uid_t uid);
 static jobmgr_t jobmgr_find_xpc_per_session_domain(jobmgr_t jm, au_asid_t asid);
 static job_t xpc_domain_import_service(jobmgr_t jm, launch_data_t pload);
-#endif
+#endif /* __LAUNCH_DISABLE_XPC_SUPPORT__ */
 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_garbage_collection(jobmgr_t jm);
@@ -695,7 +697,7 @@ static job_t job_new_anonymous(jobmgr_t jm, pid_t anonpid) __attribute__((malloc
 static job_t job_new(jobmgr_t jm, const char *label, const char *prog, const char *const *argv) __attribute__((malloc, nonnull(1,2), warn_unused_result));
 #ifndef __LAUNCH_DISABLE_XPC_SUPPORT__
 static job_t job_new_alias(jobmgr_t jm, job_t src);
-#endif
+#endif /* __LAUNCH_DISABLE_XPC_SUPPORT__ */
 static job_t job_new_via_mach_init(job_t j, const char *cmd, uid_t uid, bool ond) __attribute__((malloc, nonnull, warn_unused_result));
 static job_t job_new_subjob(job_t j, uuid_t identifier);
 static void job_kill(job_t j);
@@ -1154,7 +1156,7 @@ jobmgr_remove(jobmgr_t jm)
                        (void)jobmgr_assumes(jm, kr == KERN_SUCCESS);
                }
        }
-#endif
+#endif /* !TARGET_OS_EMBEDDED */
        if (jm->req_ctx) {
                (void)jobmgr_assumes(jm, vm_deallocate(mach_task_self(), jm->req_ctx, jm->req_ctx_sz) == KERN_SUCCESS);
        }
@@ -1425,16 +1427,9 @@ job_remove(job_t j)
        if (j->shutdown_monitor) {
                _s_shutdown_monitor = NULL;
        }
-       if (j->workaround9359725) {
-               /* We may have forcibly removed this job by simulating an exit. If this
-                * is the case, we don't want to hear about these events anymore, lest
-                * we get a stale context pointer and crash trying to dereference it.
-                */
-               kevent_mod((uintptr_t)j->p, EVFILT_PROC, EV_DELETE, 0, 0, NULL);
-       }
-       
+
        kevent_mod((uintptr_t)j, EVFILT_TIMER, EV_DELETE, 0, 0, NULL);
-       
+
        LIST_REMOVE(j, sle);
        LIST_REMOVE(j, label_hash_sle);
 
@@ -1446,6 +1441,7 @@ job_remove(job_t j)
        
        job_log(j, LOG_DEBUG, "Removed");
 
+       j->kqjob_callback = (kq_callback)0x8badf00d;
        free(j);
 }
 
@@ -2046,7 +2042,7 @@ job_new_alias(jobmgr_t jm, job_t src)
 
        return j;
 }
-#endif
+#endif /* __LAUNCH_DISABLE_XPC_SUPPORT__ */
 
 job_t 
 job_import(launch_data_t pload)
@@ -2284,7 +2280,7 @@ job_import_string(job_t j, const char *key, const char *value)
                        else if (strcasecmp(value, LAUNCH_KEY_POSIXSPAWNTYPE_IOSAPP) == 0) {
                                j->pstype = POSIX_SPAWN_IOS_APP_START;
                        }
-#endif
+#endif /* TARGET_OS_EMBEDDED */
                        else {
                                job_log(j, LOG_ERR, "Unknown value for key %s: %s", key, value);
                        }
@@ -3898,6 +3894,28 @@ job_callback_timer(job_t j, void *ident)
                                (void)job_assumes(j, host_reboot(mach_host_self(), HOST_REBOOT_DEBUGGER) == KERN_SUCCESS);
                        }
 
+                       /* We've simulated the exit, so we have to cancel the kevent for
+                        * this job, otherwise we may get a kevent later down the road that
+                        * has a stale context pointer (if we've removed the job). Or worse,
+                        * it'll corrupt our data structures if the job still exists or the
+                        * allocation was recycled.
+                        *
+                        * If the failing process had a tracer attached to it, we need to
+                        * remove out NOTE_EXIT for that tracer too, otherwise the same
+                        * thing might happen.
+                        *
+                        * Note that, if we're not shutting down, this will result in a
+                        * zombie process just hanging around forever. But if the process
+                        * didn't exit after receiving SIGKILL, odds are it would've just
+                        * stuck around forever anyway.
+                        *
+                        * See <rdar://problem/9481630>.
+                        */
+                       kevent_mod((uintptr_t)j->p, EVFILT_PROC, EV_DELETE, 0, 0, NULL);
+                       if (j->tracing_pid) {
+                               kevent_mod((uintptr_t)j->tracing_pid, EVFILT_PROC, EV_DELETE, 0, 0, NULL);
+                       }
+
                        struct kevent bogus_exit;
                        EV_SET(&bogus_exit, j->p, EVFILT_PROC, 0, NOTE_EXIT, 0, 0);
                        jobmgr_callback(j->mgr, &bogus_exit);
@@ -4448,6 +4466,67 @@ out:
        free(pids);
 }
 
+static struct passwd *
+job_getpwnam(job_t j, const char *name)
+{
+    /*
+     * methodology for system daemons
+     *
+     * first lookup user record without any opendirectoryd interaction,
+     * we don't know what interprocess dependencies might be in flight.
+     * if that fails, we re-enable opendirectoryd interaction and 
+     * re-issue the lookup.  We have to disable the libinfo L1 cache
+     * otherwise libinfo will return the negative cache entry on the retry
+     */
+    
+#if !TARGET_OS_EMBEDDED
+    struct passwd *pw = NULL;
+    
+    if (pid1_magic && j->mgr == root_jobmgr) {
+        si_search_module_set_flags("ds", 1 /* SEARCH_MODULE_FLAG_DISABLED */);
+        gL1CacheEnabled = false;
+        
+        pw = getpwnam(name);
+
+        si_search_module_set_flags("ds", 0);
+    }
+    
+    if (pw == NULL) {
+        pw = getpwnam(name);
+    }
+    
+    return pw;
+#else
+    return getpwnam(name);
+#endif
+}
+
+static struct group *
+job_getgrnam(job_t j, const char *name)
+{
+#if !TARGET_OS_EMBEDDED
+    struct group *gr = NULL;
+
+    if (pid1_magic && j->mgr == root_jobmgr) {
+        si_search_module_set_flags("ds", 1 /* SEARCH_MODULE_FLAG_DISABLED */);
+        gL1CacheEnabled = false;
+
+        gr = getgrnam(name);
+
+        si_search_module_set_flags("ds", 0);
+    }
+
+    if (gr == NULL) {
+        gr = getgrnam(name);
+    }
+
+    return gr;
+#else
+#pragma unused (j)
+    return getgrnam(name);
+#endif
+}
+
 void
 job_postfork_test_user(job_t j)
 {
@@ -4469,7 +4548,7 @@ job_postfork_test_user(job_t j)
                goto out_bad;
        }
 
-       if ((pwe = getpwnam(user_env_var)) == NULL) {
+       if ((pwe = job_getpwnam(j, user_env_var)) == NULL) {
                job_log(j, LOG_ERR, "The account \"%s\" has been deleted out from under us!", user_env_var);
                goto out_bad;
        }
@@ -4543,7 +4622,7 @@ job_postfork_become_user(job_t j)
        }
 
        if (j->username) {
-               if ((pwe = getpwnam(j->username)) == NULL) {
+               if ((pwe = job_getpwnam(j, j->username)) == NULL) {
                        job_log(j, LOG_ERR, "getpwnam(\"%s\") failed", j->username);
                        _exit(EXIT_FAILURE);
                }
@@ -4587,7 +4666,7 @@ job_postfork_become_user(job_t j)
        if (j->groupname) {
                struct group *gre;
 
-               if (unlikely((gre = getgrnam(j->groupname)) == NULL)) {
+               if (unlikely((gre = job_getgrnam(j, j->groupname)) == NULL)) {
                        job_log(j, LOG_ERR, "getgrnam(\"%s\") failed", j->groupname);
                        _exit(EXIT_FAILURE);
                }
@@ -5958,7 +6037,7 @@ machservice_new_alias(job_t j, struct machservice *orig)
 
        return ms;
 }
-#endif
+#endif /* __LAUNCH_DISABLE_XPC_SUPPORT__ */
 
 bootstrap_status_t
 machservice_status(struct machservice *ms)
@@ -6138,6 +6217,9 @@ jobmgr_do_garbage_collection(jobmgr_t jm)
                jobmgr_log(jm, LOG_DEBUG, "No submanagers left.");
        } else {
                jobmgr_log(jm, LOG_DEBUG, "Still have submanagers.");
+               SLIST_FOREACH(jmi, &jm->submgrs, sle) {
+                       jobmgr_log(jm, LOG_DEBUG, "Submanager: %s", jmi->name);
+               }
        }
 
        size_t actives = 0;
@@ -6578,7 +6660,7 @@ jobmgr_find_xpc_per_session_domain(jobmgr_t jm, au_asid_t asid)
 
        return jmi;
 }
-#endif
+#endif /* __LAUNCH_DISABLE_XPC_SUPPORT__ */
 
 job_t
 jobmgr_init_session(jobmgr_t jm, const char *session_type, bool sflag)
@@ -8693,6 +8775,10 @@ job_mig_parent(job_t j, mach_port_t srp, mach_port_t *parentport)
 kern_return_t
 job_mig_get_root_bootstrap(job_t j, mach_port_t *rootbsp)
 {
+       if (!j) {
+               return BOOTSTRAP_NO_MEMORY;
+       }
+
        if (inherited_bootstrap_port == MACH_PORT_NULL) {
                *rootbsp = root_jobmgr->jm_port;
                (void)job_assumes(j, launchd_mport_make_send(root_jobmgr->jm_port) == KERN_SUCCESS);
@@ -8922,6 +9008,10 @@ out_bad:
 kern_return_t
 job_mig_transaction_count_for_pid(job_t j, pid_t p, int32_t *cnt, boolean_t *condemned)
 {
+       if (!j) {
+               return BOOTSTRAP_NO_MEMORY;
+       }
+
        kern_return_t kr = KERN_FAILURE;
        struct ldcred *ldc = runtime_get_caller_creds();
        if ((ldc->euid != geteuid()) && (ldc->euid != 0)) {
@@ -8973,6 +9063,10 @@ job_mig_pid_is_managed(job_t j __attribute__((unused)), pid_t p, boolean_t *mana
 kern_return_t
 job_mig_port_for_label(job_t j __attribute__((unused)), name_t label, mach_port_t *mp)
 {
+       if (!j) {
+               return BOOTSTRAP_NO_MEMORY;
+       }
+
        struct ldcred *ldc = runtime_get_caller_creds();
        kern_return_t kr = BOOTSTRAP_NOT_PRIVILEGED;
 
@@ -9005,6 +9099,10 @@ job_mig_port_for_label(job_t j __attribute__((unused)), name_t label, mach_port_
 kern_return_t
 job_mig_set_security_session(job_t j, uuid_t uuid, mach_port_t asport)
 {
+       if (!j) {
+               return BOOTSTRAP_NO_MEMORY;
+       }
+
        uuid_string_t uuid_str;
        uuid_unparse(uuid, uuid_str);
        job_log(j, LOG_DEBUG, "Setting session %u for UUID %s...", asport, uuid_str);
@@ -9210,6 +9308,10 @@ out:
 kern_return_t
 job_mig_init_session(job_t j, name_t session_type, mach_port_t asport)
 {
+       if (!j) {
+               return BOOTSTRAP_NO_MEMORY;
+       }
+
        job_t j2;
        
        kern_return_t kr = BOOTSTRAP_NO_MEMORY;
@@ -9264,6 +9366,10 @@ job_mig_switch_to_session(job_t j, mach_port_t requestor_port, name_t session_na
                return BOOTSTRAP_NO_MEMORY;
        }
 
+       if (j->mgr->shutting_down) {
+               return BOOTSTRAP_UNKNOWN_SERVICE;
+       }
+
        job_log(j, LOG_DEBUG, "Job wants to move to %s session.", session_name);
        
        if (!job_assumes(j, pid1_magic == false)) {
@@ -9492,6 +9598,9 @@ job_mig_subset(job_t j, mach_port_t requestorport, mach_port_t *subsetportp)
        if (!launchd_assumes(j != NULL)) {
                return BOOTSTRAP_NO_MEMORY;
        }
+       if (j->mgr->shutting_down) {
+               return BOOTSTRAP_UNKNOWN_SERVICE;
+       }
 
        jmr = j->mgr;
 
@@ -9612,9 +9721,13 @@ xpc_domain_import2(job_t j, mach_port_t reqport, mach_port_t dport)
                job_log(j, LOG_ERR, "XPC domains may only reside in PID 1.");
                return BOOTSTRAP_NOT_PRIVILEGED;
        }
-       if (!MACH_PORT_VALID(reqport)) {
+       if (!j || !MACH_PORT_VALID(reqport)) {
                return BOOTSTRAP_UNKNOWN_SERVICE;
        }
+       if (root_jobmgr->shutting_down) {
+               jobmgr_log(root_jobmgr, LOG_ERR, "Attempt to create new domain while shutting down.");
+               return BOOTSTRAP_NOT_PRIVILEGED;
+       }
 
        kern_return_t kr = BOOTSTRAP_NO_MEMORY;
        /* All XPC domains are children of the root job manager. What we're creating
@@ -9816,7 +9929,7 @@ xpc_domain_get_service_name(job_t j, event_name_t name)
        (void)strlcpy(name, ms->name, sizeof(event_name_t));
        return BOOTSTRAP_SUCCESS;
 }
-#endif
+#endif /* __LAUNCH_DISABLE_XPC_SUPPORT__ */
 
 kern_return_t
 xpc_events_get_channel_name(job_t j __attribute__((unused)), event_name_t stream __attribute__((unused)), uint64_t token __attribute__((unused)), event_name_t name __attribute__((unused)))
@@ -9919,7 +10032,7 @@ xpc_events_find_channel(job_t j, event_name_t stream, mach_port_t *p)
                        msi->event_channel = true;
                        *p = sp;
 
-                       machservice_watch(j, msi);
+                       (void)job_dispatch(j, false);
                } else {
                        errno = BOOTSTRAP_NO_MEMORY;
                }
@@ -10239,7 +10352,7 @@ job_mig_event_source_check_in(job_t j, name_t name, mach_port_t ping_port, vm_of
 kern_return_t
 job_mig_event_set_state(job_t j, name_t name, uint64_t token, boolean_t state)
 {
-       if (!j->event_monitor) {
+       if (!j || !j->event_monitor) {
                return BOOTSTRAP_NOT_PRIVILEGED;
        }
        
@@ -10272,7 +10385,7 @@ jobmgr_init(bool sflag)
        _s_xpc_system_domain->req_asid = g_audit_session;
        _s_xpc_system_domain->req_asport = g_audit_session_port;
        _s_xpc_system_domain->shortdesc = "system";
-#endif
+#endif /* __LAUNCH_DISABLE_XPC_SUPPORT__ */
        if (pid1_magic) {
                root_jobmgr->monitor_shutdown = true;
        }
index a8eab4f6d11adc9079504e7a71055b3a7238a308..5e21c5a23520236ed0cf5e1170b685e5a9292577 100644 (file)
@@ -34,4 +34,4 @@ void runtime_ktrace1(runtime_ktrace_code_t code);
 void runtime_ktrace0(runtime_ktrace_code_t code);
 void runtime_ktrace(runtime_ktrace_code_t code, long a, long b, long c);
 
-#endif
+#endif /* __LAUNCHD_KTRACE_H__ */
index ac0e712ca7e20b9ddf29416f67de80a7a9d3519a..9514078abee5a20d973ae6211256f16effa43729 100644 (file)
@@ -18,7 +18,7 @@
  * @APPLE_APACHE_LICENSE_HEADER_END@
  */
 
-static const char *const __rcs_file_version__ = "$Revision: 24912 $";
+static const char *const __rcs_file_version__ = "$Revision: 25122 $";
 
 #include "config.h"
 #include "launchd_runtime.h"
@@ -78,7 +78,7 @@ static const char *const __rcs_file_version__ = "$Revision: 24912 $";
 
 #if !TARGET_OS_EMBEDDED
 #include "domainServer.h"
-#endif
+#endif /* !TARGET_OS_EMBEDDED */
 #include "eventsServer.h"
 
 static mach_port_t ipc_port_set;
@@ -557,9 +557,19 @@ x_handle_kqueue(mach_port_t junk __attribute__((unused)), integer_t fd)
                                        log_kevent_struct(LOG_EMERG, &kev[0], 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);
+                               struct job_check_s {
+                                       kq_callback kqc;
+                               };
+
+                               struct job_check_s *check = kevi->udata;
+                               if (check && check->kqc) {
+                                       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);
+                               } else {
+                                       runtime_syslog(LOG_ERR, "The following kevent had invalid context data. Please file a bug with the following information:");
+                                       log_kevent_struct(LOG_EMERG, &kev[0], i);
+                               }
 #endif
                        }
                }
@@ -1119,7 +1129,7 @@ launchd_runtime2(mach_msg_size_t msg_size, mig_reply_error_t *bufRequest, mig_re
                                }
 #else
                                (void)xpc_events_server(&bufRequest->Head, &bufReply->Head);
-#endif
+#endif /* !TARGET_OS_EMBEDDED */
                        }
                }
 
index 693bc1bfae68298f4d1332ae50a6d80362e31332..d3290aac27ef1816dd7d7119e01b02455a5ce0b2 100644 (file)
@@ -39,7 +39,7 @@
 #if !TARGET_OS_EMBEDDED
 #include <bsm/audit.h>
 #include <bsm/audit_session.h>
-#endif
+#endif // !TARGET_OS_EMBEDDED
 
 #include "launch.h"
 
@@ -206,7 +206,7 @@ int main(int argc __attribute__((unused)), char *argv[])
                                        syslog(LOG_NOTICE, "%s: Setting Audit Session ID failed: %d", prog, errno);
                                }
                        }
-#endif
+#endif // !TARGET_OS_EMBEDDED
                        fcntl(r, F_SETFL, 0);
                        fcntl(r, F_SETFD, 1);
                        dup2(r, STDIN_FILENO);
index e6dcc34efa45d087486da09bd287a7829ed7273f..536d05f6272643a7fe3d301fccc1614a5bfdb227 100644 (file)
@@ -59,8 +59,6 @@
 
 static mach_port_t get_root_bootstrap_port(void);
 
- #define _vproc_set_crash_log_message(x)
-
 static int64_t cached_pid = -1;
 static struct vproc_shmem_s *vproc_shmem;
 static pthread_once_t shmem_inited = PTHREAD_ONCE_INIT;