Modified: trunk/launchd/src/launchd_core_logic.c (23955 => 23956)
--- trunk/launchd/src/launchd_core_logic.c 2009-11-18 01:18:55 UTC (rev 23955)
+++ trunk/launchd/src/launchd_core_logic.c 2009-11-18 02:38:58 UTC (rev 23956)
@@ -8608,7 +8608,7 @@
job_handle_mpm_wait(NULL, MACH_PORT_NULL, NULL);
}
struct ldcred *ldc = runtime_get_caller_creds();
- job_t calling_j = job_mig_intran2(j->mgr, MACH_PORT_NULL, ldc->pid);
+ job_t calling_j = jobmgr_find_by_pid(j->mgr, ldc->pid, true);
return job_mig_wait2(calling_j, j, srp, waitstatus, true);
#endif
@@ -8627,7 +8627,17 @@
return BOOTSTRAP_NO_MEMORY;
}
- if( target_j->p == 0 ) {
+ /* See rdar://problem/7084138 for why we do the second part of this check.
+ * Basically, since Finder, Dock and SystemUIServer are now real launchd
+ * jobs, they don't get removed after exiting, like legacy LaunchServices
+ * jobs do. So there's a race. coreservicesd came in asking for the exit
+ * status after we'd relaunched Finder, so Finder's PID isn't 0.
+ *
+ * So we check to make sure the target job isn't a LaunchServices job and
+ * that the request is coming through the legacy path (mpm_wait()). If so,
+ * we return the last exit status, regardless of the current PID value.
+ */
+ if( target_j->p == 0 || (!target_j->legacy_LS_job && legacy) ) {
*status = target_j->last_exit_status;
return BOOTSTRAP_SUCCESS;
}