From source_changes at macosforge.org Mon Apr 2 12:08:11 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:45 2007 Subject: [launchd-changes] [23195] tags/launchd-207/ Message-ID: <20070402190811.33F4550FB7B@cvs.opensource.apple.com> Revision: 23195 http://trac.macosforge.org/projects/launchd/changeset/23195 Author: zarzycki@apple.com Date: 2007-04-02 12:08:10 -0700 (Mon, 02 Apr 2007) Log Message: ----------- "Tagging launchd-207 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-207/ Copied: tags/launchd-207 (from rev 23194, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070402/25849282/attachment.html From source_changes at macosforge.org Mon Apr 2 13:28:29 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23196] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070402202829.050E450FD6E@cvs.opensource.apple.com> Revision: 23196 http://trac.macosforge.org/projects/launchd/changeset/23196 Author: zarzycki@apple.com Date: 2007-04-02 13:28:29 -0700 (Mon, 02 Apr 2007) Log Message: ----------- log what program(s) initiated a shutdown/reboot Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-02 19:08:10 UTC (rev 23195) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-02 20:28:29 UTC (rev 23196) @@ -576,7 +576,7 @@ jobmgr_t jmi, jmn; job_t ji, jn; - jobmgr_log(jm, LOG_DEBUG, "Beginning job manager shutdown"); + jobmgr_log(jm, LOG_DEBUG, "Beginning job manager shutdown with flags: %s", reboot_flags_to_C_names(jm->reboot_flags)); jm->shutting_down = true; @@ -4408,7 +4408,10 @@ kern_return_t job_mig_reboot2(job_t j, uint64_t flags) { + char who_started_the_reboot[2048] = ""; + struct kinfo_proc kp; struct ldcred ldc; + pid_t pid_to_log; if (getpid() != 1) { return BOOTSTRAP_NOT_PRIVILEGED; @@ -4420,10 +4423,25 @@ return BOOTSTRAP_NOT_PRIVILEGED; } + for (pid_to_log = ldc.pid; pid_to_log; pid_to_log = kp.kp_eproc.e_ppid) { + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid_to_log }; + size_t who_offset, len = sizeof(kp); + + if (!job_assumes(j, sysctl(mib, 4, &kp, &len, NULL, 0) != -1)) { + return 1; + } + + who_offset = strlen(who_started_the_reboot); + snprintf(who_started_the_reboot + who_offset, sizeof(who_started_the_reboot) - who_offset, + " %s[%u]%s", kp.kp_proc.p_comm, pid_to_log, kp.kp_eproc.e_ppid ? " ->" : ""); + } + root_jobmgr->reboot_flags = (int)flags; launchd_shutdown(); + job_log(j, LOG_DEBUG, "reboot2() initiated by:%s", who_started_the_reboot); + return 0; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070402/886db8bb/attachment.html From source_changes at macosforge.org Mon Apr 2 13:29:26 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23197] trunk/launchd/src/launchctl.c Message-ID: <20070402202926.B7C1750FD7A@cvs.opensource.apple.com> Revision: 23197 http://trac.macosforge.org/projects/launchd/changeset/23197 Author: zarzycki@apple.com Date: 2007-04-02 13:29:26 -0700 (Mon, 02 Apr 2007) Log Message: ----------- After 5093376 gets in, remove setting KERN_TFP_READ_GROUP and KERN_TFP_RW_GROUP Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-04-02 20:28:29 UTC (rev 23196) +++ trunk/launchd/src/launchctl.c 2007-04-02 20:29:26 UTC (rev 23197) @@ -1288,7 +1288,6 @@ system_specific_bootstrap(bool sflag) { int hnmib[] = { CTL_KERN, KERN_HOSTNAME }; - struct group *tfp_gr; struct kevent kev; int kq; @@ -1306,18 +1305,6 @@ assumes(kevent(kq, &kev, 1, NULL, 0, NULL) != -1); assumes(signal(SIGTERM, SIG_IGN) != SIG_ERR); - if (assumes((tfp_gr = getgrnam("procview")) != NULL)) { - int tfp_r_mib[3] = { CTL_KERN, KERN_TFP, KERN_TFP_READ_GROUP }; - gid_t tfp_r_gid = tfp_gr->gr_gid; - assumes(sysctl(tfp_r_mib, 3, NULL, NULL, &tfp_r_gid, sizeof(tfp_r_gid)) != -1); - } - - if (assumes((tfp_gr = getgrnam("procmod")) != NULL)) { - int tfp_rw_mib[3] = { CTL_KERN, KERN_TFP, KERN_TFP_RW_GROUP }; - gid_t tfp_rw_gid = tfp_gr->gr_gid; - assumes(sysctl(tfp_rw_mib, 3, NULL, NULL, &tfp_rw_gid, sizeof(tfp_rw_gid)) != -1); - } - assumes(sysctl(hnmib, 2, NULL, NULL, "localhost", sizeof("localhost")) != -1); loopback_setup_ipv4(); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070402/da54510c/attachment.html From source_changes at macosforge.org Mon Apr 2 13:43:42 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23198] trunk/launchd/src Message-ID: <20070402204342.6191F50FDBD@cvs.opensource.apple.com> Revision: 23198 http://trac.macosforge.org/projects/launchd/changeset/23198 Author: zarzycki@apple.com Date: 2007-04-02 13:43:42 -0700 (Mon, 02 Apr 2007) Log Message: ----------- We always want EV_CLEAR behavior. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-02 20:29:26 UTC (rev 23197) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-02 20:43:42 UTC (rev 23198) @@ -2723,7 +2723,7 @@ } job_log(j, LOG_DEBUG, "Watching Vnode: %d", si->fd); - job_assumes(j, kevent_mod(si->fd, EVFILT_VNODE, EV_ADD|EV_CLEAR, fflags, 0, j) != -1); + job_assumes(j, kevent_mod(si->fd, EVFILT_VNODE, EV_ADD, fflags, 0, j) != -1); } void @@ -3627,7 +3627,7 @@ if (!jm) { jobmgr_assumes(jmr, kevent_mod(SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, jmr) != -1); - jobmgr_assumes(jmr, kevent_mod(0, EVFILT_FS, EV_ADD|EV_CLEAR, VQ_MOUNT|VQ_UNMOUNT|VQ_UPDATE, 0, jmr) != -1); + jobmgr_assumes(jmr, kevent_mod(0, EVFILT_FS, EV_ADD, VQ_MOUNT|VQ_UNMOUNT|VQ_UPDATE, 0, jmr) != -1); } if (name) { Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-04-02 20:29:26 UTC (rev 23197) +++ trunk/launchd/src/launchd_runtime.c 2007-04-02 20:43:42 UTC (rev 23198) @@ -264,9 +264,9 @@ else FLAGIF(EV_DELETE) else FLAGIF(EV_ENABLE) else FLAGIF(EV_DISABLE) - else FLAGIF(EV_ONESHOT) else FLAGIF(EV_CLEAR) else FLAGIF(EV_EOF) + else FLAGIF(EV_ONESHOT) else FLAGIF(EV_ERROR) else { flags_off += sprintf(flags_off, "0x%x", flags); @@ -678,6 +678,8 @@ struct kevent kev; int q = mainkq; + flags |= EV_CLEAR; + if (EVFILT_TIMER == filter || EVFILT_VNODE == filter) { q = asynckq; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070402/4aef7ec0/attachment.html From source_changes at macosforge.org Mon Apr 2 14:32:00 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23199] trunk/launchd/src Message-ID: <20070402213200.0A29B50FE5F@cvs.opensource.apple.com> Revision: 23199 http://trac.macosforge.org/projects/launchd/changeset/23199 Author: zarzycki@apple.com Date: 2007-04-02 14:31:59 -0700 (Mon, 02 Apr 2007) Log Message: ----------- The IOKit team would like kextd to get a head start on all the other daemons at boot up 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 2007-04-02 20:43:42 UTC (rev 23198) +++ trunk/launchd/src/launchctl.c 2007-04-02 21:31:59 UTC (rev 23199) @@ -1380,6 +1380,51 @@ assumes(load_and_unload_cmd(4, load_launchd_items) == 0); + /* + * 5066316 + * + * We need to revisit this after Leopard ships. + * + * I want a plist defined knob for jobs to give advisory hints that + * will "hopefully" serialize bootstrap. Reasons for doing so include + * pragmatic performance optimizations and attempts to workaround bugs + * in jobs. My current thought is something like what follows. + * + * The BootCache would switch to launchd and add this to the plist: + * + * HopefullyStartsSerially + * + * ReadyTimeout + * 2 + * + * + * And kextd would add the following: + * + * HopefullyStartsSerially + * + * ReadyTimeout + * 5 + * HopefullyStartsAfter + * com.apple.BootCache.daemon + * + * + * + * Then both the BootCache and kextd could call something like: + * + * vproc_declare_ready_state(); + * + * To tell launchd to short circuit the readiness timeout and let the + * next wave of jobs start. + * + * Yes, this mechanism smells a lot like SystemStarter, rc.d and + * friends. I think as long as we document that artificial + * serialization is only advisory and not guaranteed, we should be + * fine. Remember: IPC is the preferred way to serialize operations. + * + */ + mach_timespec_t w = { 5, 0 }; + IOKitWaitQuiet(kIOMasterPortDefault, &w); + do_BootCache_magic(BOOTCACHE_TAG); do_bootroot_magic(); Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-02 20:43:42 UTC (rev 23198) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-02 21:31:59 UTC (rev 23199) @@ -3112,7 +3112,13 @@ struct stat sb; bool good_exit = (WIFEXITED(j->last_exit_status) && WEXITSTATUS(j->last_exit_status) == 0); - if (j->mgr->global_on_demand_cnt > 0) { + /* + * 5066316 + * + * We definitely need to revisit this after Leopard ships. Please see + * launchctl.c for the other half of this hack. + */ + if (j->mgr->global_on_demand_cnt > 0 && strcmp(j->label, "com.apple.kextd") != 0) { return false; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070402/3a9a5dba/attachment.html From source_changes at macosforge.org Wed Apr 4 08:36:25 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23200] trunk/launchd/src/libvproc.c Message-ID: <20070404153625.6A4A6514512@cvs.opensource.apple.com> Revision: 23200 http://trac.macosforge.org/projects/launchd/changeset/23200 Author: zarzycki@apple.com Date: 2007-04-04 08:36:25 -0700 (Wed, 04 Apr 2007) Log Message: ----------- screen/nohup/sudo/su need to be taught (abstractly) about Mac OS X sessions (or else bootstrap_look_up() fails) Modified Paths: -------------- trunk/launchd/src/libvproc.c Modified: trunk/launchd/src/libvproc.c =================================================================== --- trunk/launchd/src/libvproc.c 2007-04-02 21:31:59 UTC (rev 23199) +++ trunk/launchd/src/libvproc.c 2007-04-04 15:36:25 UTC (rev 23200) @@ -38,6 +38,8 @@ #include "reboot2.h" +static mach_port_t get_root_bootstrap_port(void); + kern_return_t _vproc_grab_subset(mach_port_t bp, mach_port_t *reqport, mach_port_t *rcvright, name_array_t *service_names, mach_msg_type_number_t *service_namesCnt, @@ -52,14 +54,23 @@ { kern_return_t kr = 1; mach_port_t puc = 0, which_port = bootstrap_port; + bool is_bkgd = (strcmp(session_type, VPROCMGR_SESSION_BACKGROUND) == 0); - if (target_user && vproc_mig_lookup_per_user_context(bootstrap_port, target_user, &puc) == 0) { + if (target_user && vproc_mig_lookup_per_user_context(get_root_bootstrap_port(), target_user, &puc) == 0) { which_port = puc; } - kr = vproc_mig_move_subset(which_port, bootstrap_port, session_type); + if (is_bkgd) { + kr = 0; + } else { + kr = vproc_mig_move_subset(which_port, bootstrap_port, session_type); + } - if (puc) { + if (puc && is_bkgd) { + task_set_bootstrap_port(mach_task_self(), puc); + mach_port_deallocate(mach_task_self(), bootstrap_port); + bootstrap_port = puc; + } else if (puc) { mach_port_deallocate(mach_task_self(), puc); } @@ -251,8 +262,8 @@ return (vproc_err_t)vproc_swap_integer; } -void * -reboot2(uint64_t flags) +mach_port_t +get_root_bootstrap_port(void) { mach_port_t parent_port = 0; mach_port_t previous_port = 0; @@ -266,16 +277,21 @@ } if (bootstrap_parent(previous_port, &parent_port) != 0) { - goto out_bad; + return MACH_PORT_NULL; } } while (parent_port != previous_port); - if (vproc_mig_reboot2(parent_port, flags) == 0) { + return parent_port; +} + +void * +reboot2(uint64_t flags) +{ + if (vproc_mig_reboot2(get_root_bootstrap_port(), flags) == 0) { return NULL; } -out_bad: return reboot2; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070404/ecf7fbb2/attachment.html From source_changes at macosforge.org Wed Apr 4 08:43:37 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23201] trunk/launchd/src/libvproc.c Message-ID: <20070404154337.1AD39514527@cvs.opensource.apple.com> Revision: 23201 http://trac.macosforge.org/projects/launchd/changeset/23201 Author: zarzycki@apple.com Date: 2007-04-04 08:43:36 -0700 (Wed, 04 Apr 2007) Log Message: ----------- Don't cache vproc attributes if we're running as loginwindow Modified Paths: -------------- trunk/launchd/src/libvproc.c Modified: trunk/launchd/src/libvproc.c =================================================================== --- trunk/launchd/src/libvproc.c 2007-04-04 15:36:25 UTC (rev 23200) +++ trunk/launchd/src/libvproc.c 2007-04-04 15:43:36 UTC (rev 23201) @@ -40,6 +40,8 @@ static mach_port_t get_root_bootstrap_port(void); +static int64_t cached_pid = -1; + kern_return_t _vproc_grab_subset(mach_port_t bp, mach_port_t *reqport, mach_port_t *rcvright, name_array_t *service_names, mach_msg_type_number_t *service_namesCnt, @@ -74,6 +76,8 @@ mach_port_deallocate(mach_task_self(), puc); } + cached_pid = -1; + return kr == 0 ? NULL : (vproc_err_t)_vprocmgr_move_subset_to_user; } @@ -224,7 +228,6 @@ vproc_err_t vproc_swap_integer(vproc_t vp __attribute__((unused)), vproc_gsk_t key, int64_t *inval, int64_t *outval) { - static int64_t cached_pid = -1; static int64_t cached_is_managed = -1; int64_t dummyval = 0; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070404/2b77fba5/attachment.html From source_changes at macosforge.org Wed Apr 4 12:10:17 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23202] trunk/launchd/src Message-ID: <20070404191017.634FF5147ED@cvs.opensource.apple.com> Revision: 23202 http://trac.macosforge.org/projects/launchd/changeset/23202 Author: zarzycki@apple.com Date: 2007-04-04 12:10:17 -0700 (Wed, 04 Apr 2007) Log Message: ----------- We need a "HopefullyExitsFirst" key for broken designs like SystemStarter Modified Paths: -------------- trunk/launchd/src/com.apple.SystemStarter.plist trunk/launchd/src/launchd.plist.5 trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/liblaunch_public.h Modified: trunk/launchd/src/com.apple.SystemStarter.plist =================================================================== --- trunk/launchd/src/com.apple.SystemStarter.plist 2007-04-04 15:43:36 UTC (rev 23201) +++ trunk/launchd/src/com.apple.SystemStarter.plist 2007-04-04 19:10:17 UTC (rev 23202) @@ -21,5 +21,7 @@ /Library/StartupItems /System/Library/StartupItems + HopefullyExitsFirst + Modified: trunk/launchd/src/launchd.plist.5 =================================================================== --- trunk/launchd/src/launchd.plist.5 2007-04-04 15:43:36 UTC (rev 23201) +++ trunk/launchd/src/launchd.plist.5 2007-04-04 19:10:17 UTC (rev 23202) @@ -273,12 +273,18 @@ This optional key specifies what .Xr nice 3 value should be applied to the daemon. +.It Sy HopefullyExitsFirst +This optional key causes programs to exit earlier during system shutdown. +This key exists because some jobs do more than flush buffers and exit like +they're supposed to. The use of this key should be considered a +temporary solution until the software can be changed to only flush dirty buffers +and then exit. .It Sy HopefullyExitsLast -This optional key causes programs to exit in a second wave during system -shutdown. This key exists because some jobs don't reference count their -clients, and therefore do not know when it is safe to exit. The use of this key -should be considered a temporary solution until the software can be changed to -properly reference count clients. +This optional key causes programs to exit later during system shutdown. This +key exists because some jobs don't reference count their clients, and therefore +do not know when it is safe to exit. The use of this key should be considered a +temporary solution until the software can be changed to properly reference +count clients. .It Sy LowPriorityIO This optional key specifies whether the kernel should consider this daemon to be low priority when doing file system I/O. .It Sy LaunchOnlyOnce Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-04 15:43:36 UTC (rev 23201) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-04 19:10:17 UTC (rev 23202) @@ -223,7 +223,9 @@ jobmgr_t parentmgr; int reboot_flags; unsigned int global_on_demand_cnt; - unsigned int sent_stop_to_hopeful_jobs:1, shutting_down:1; + unsigned int hopefully_first_cnt; + unsigned int normal_active_cnt; + unsigned int sent_stop_to_normal_jobs:1, sent_stop_to_hopefully_last_jobs:1, shutting_down:1; char name[0]; }; @@ -303,7 +305,7 @@ unsigned int globargv:1, wait4debugger:1, unload_at_exit:1, stall_before_exec:1, only_once:1, currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1, hopefully_exits_last:1, removal_pending:1, wait4pipe_eof:1, sent_sigkill:1, debug_before_kill:1, weird_bootstrap:1, start_on_mount:1, - per_user:1; + per_user:1, hopefully_exits_first:1; const char label[0]; }; @@ -574,7 +576,7 @@ jobmgr_shutdown(jobmgr_t jm) { jobmgr_t jmi, jmn; - job_t ji, jn; + job_t ji; jobmgr_log(jm, LOG_DEBUG, "Beginning job manager shutdown with flags: %s", reboot_flags_to_C_names(jm->reboot_flags)); @@ -584,11 +586,11 @@ jobmgr_shutdown(jmi); } - LIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { - if (!job_active(ji)) { - job_remove(ji); - } else if (!ji->hopefully_exits_last) { - job_stop(ji); + if (jm->hopefully_first_cnt) { + LIST_FOREACH(ji, &jm->jobs, sle) { + if (ji->p && ji->hopefully_exits_first) { + job_stop(ji); + } } } @@ -974,7 +976,7 @@ /* anonymous process reaping is messy */ LIST_INSERT_HEAD(&jm->active_jobs[ACTIVE_JOB_HASH(jr->p)], jr, pid_hash_sle); job_assumes(jr, kevent_mod(jr->p, EVFILT_PROC, EV_ADD, NOTE_EXEC|NOTE_EXIT, 0, root_jobmgr) != -1); - if (shutdown_state) { + if (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. Blame PID %u: %s", kp.kp_eproc.e_ppid, ppid_kp.kp_proc.p_comm); } @@ -1152,6 +1154,8 @@ case 'H': if (strcasecmp(key, LAUNCH_JOBKEY_HOPEFULLYEXITSLAST) == 0) { j->hopefully_exits_last = value; + } else if (strcasecmp(key, LAUNCH_JOBKEY_HOPEFULLYEXITSFIRST) == 0) { + j->hopefully_exits_first = value; } break; case 's': @@ -1805,6 +1809,11 @@ } } + if (j->hopefully_exits_first) { + j->mgr->hopefully_first_cnt--; + } else if (!j->hopefully_exits_last) { + j->mgr->normal_active_cnt--; + } j->last_exit_status = status; j->sent_sigkill = false; j->p = 0; @@ -2146,6 +2155,11 @@ job_assumes(j, runtime_close(oepair[1]) != -1); } j->p = c; + if (j->hopefully_exits_first) { + j->mgr->hopefully_first_cnt++; + } else if (!j->hopefully_exits_last) { + j->mgr->normal_active_cnt++; + } j->forkfd = _fd(execspair[0]); job_assumes(j, runtime_close(execspair[1]) == 0); if (sipc) { @@ -3236,7 +3250,7 @@ } SLIST_FOREACH(ms, &j->machservices, sle) { - if (ms->isActive) { + if (ms->recv && ms->isActive) { return true; } } @@ -3432,7 +3446,7 @@ jobmgr_do_garbage_collection(jobmgr_t jm) { jobmgr_t jmi, jmn; - job_t ji; + job_t ji, jn; SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { jobmgr_do_garbage_collection(jmi); @@ -3450,23 +3464,44 @@ return NULL; } - if (jm->sent_stop_to_hopeful_jobs) { + if (jm->hopefully_first_cnt) { return jm; } - LIST_FOREACH(ji, &jm->jobs, sle) { - if (ji->p && !ji->anonymous && !ji->hopefully_exits_last) { - return jm; + if (!jm->sent_stop_to_normal_jobs) { + jobmgr_log(jm, LOG_DEBUG, "Asking \"normal\" jobs to exit."); + + LIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { + if (!job_active(ji)) { + job_remove(ji); + } else if (!ji->hopefully_exits_last) { + job_stop(ji); + } } + + jm->sent_stop_to_normal_jobs = true; + return jm; } - jobmgr_log(jm, LOG_DEBUG, "Asking \"hopeful\" jobs to exit."); + if (jm->normal_active_cnt) { + return jm; + } + if (jm->sent_stop_to_hopefully_last_jobs) { + return jm; + } + + jobmgr_log(jm, LOG_DEBUG, "Asking \"hopefully last\" jobs to exit."); + LIST_FOREACH(ji, &jm->jobs, sle) { - job_stop(ji); + if (ji->p && ji->anonymous) { + continue; + } else if (ji->p && job_assumes(ji, ji->hopefully_exits_last)) { + job_stop(ji); + } } - jm->sent_stop_to_hopeful_jobs = true; + jm->sent_stop_to_hopefully_last_jobs = true; return jm; } Modified: trunk/launchd/src/liblaunch_public.h =================================================================== --- trunk/launchd/src/liblaunch_public.h 2007-04-04 15:43:36 UTC (rev 23201) +++ trunk/launchd/src/liblaunch_public.h 2007-04-04 19:10:17 UTC (rev 23202) @@ -78,6 +78,7 @@ #define LAUNCH_JOBKEY_USERENVIRONMENTVARIABLES "UserEnvironmentVariables" #define LAUNCH_JOBKEY_UMASK "Umask" #define LAUNCH_JOBKEY_NICE "Nice" +#define LAUNCH_JOBKEY_HOPEFULLYEXITSFIRST "HopefullyExitsFirst" #define LAUNCH_JOBKEY_HOPEFULLYEXITSLAST "HopefullyExitsLast" #define LAUNCH_JOBKEY_LOWPRIORITYIO "LowPriorityIO" #define LAUNCH_JOBKEY_SESSIONCREATE "SessionCreate" -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070404/b87052d6/attachment.html From source_changes at macosforge.org Wed Apr 4 13:05:30 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23203] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070404200530.BD62F5148CB@cvs.opensource.apple.com> Revision: 23203 http://trac.macosforge.org/projects/launchd/changeset/23203 Author: zarzycki@apple.com Date: 2007-04-04 13:05:30 -0700 (Wed, 04 Apr 2007) Log Message: ----------- Small bug fixes. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-04 19:10:17 UTC (rev 23202) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-04 20:05:30 UTC (rev 23203) @@ -1811,7 +1811,7 @@ if (j->hopefully_exits_first) { j->mgr->hopefully_first_cnt--; - } else if (!j->hopefully_exits_last) { + } else if (!j->anonymous && !j->hopefully_exits_last) { j->mgr->normal_active_cnt--; } j->last_exit_status = status; @@ -3468,6 +3468,10 @@ return jm; } + if (jm->parentmgr && jm->parentmgr->shutting_down && jm->parentmgr->hopefully_first_cnt) { + return jm; + } + if (!jm->sent_stop_to_normal_jobs) { jobmgr_log(jm, LOG_DEBUG, "Asking \"normal\" jobs to exit."); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070404/4d6245ee/attachment.html From source_changes at macosforge.org Wed Apr 4 15:36:37 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23204] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070404223637.2BCF2514D6F@cvs.opensource.apple.com> Revision: 23204 http://trac.macosforge.org/projects/launchd/changeset/23204 Author: zarzycki@apple.com Date: 2007-04-04 15:36:36 -0700 (Wed, 04 Apr 2007) Log Message: ----------- Better jobmgr_t GC. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-04 20:05:30 UTC (rev 23203) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-04 22:36:36 UTC (rev 23204) @@ -236,7 +236,6 @@ static jobmgr_t jobmgr_parent(jobmgr_t jm); static jobmgr_t jobmgr_do_garbage_collection(jobmgr_t jm); static void jobmgr_reap_bulk(jobmgr_t jm, struct kevent *kev); -static bool jobmgr_is_idle(jobmgr_t jm); static void jobmgr_log_stray_children(jobmgr_t jm); static void jobmgr_remove(jobmgr_t jm); static void jobmgr_dispatch_all(jobmgr_t jm, bool newmounthack); @@ -3458,12 +3457,6 @@ jobmgr_log(jm, LOG_DEBUG, "Garbage collecting."); - if (jobmgr_is_idle(jm)) { - jobmgr_log_stray_children(jm); - jobmgr_remove(jm); - return NULL; - } - if (jm->hopefully_first_cnt) { return jm; } @@ -3484,30 +3477,39 @@ } jm->sent_stop_to_normal_jobs = true; - return jm; } if (jm->normal_active_cnt) { return jm; } - if (jm->sent_stop_to_hopefully_last_jobs) { + if (!jm->sent_stop_to_hopefully_last_jobs) { + jobmgr_log(jm, LOG_DEBUG, "Asking \"hopefully last\" jobs to exit."); + + LIST_FOREACH(ji, &jm->jobs, sle) { + if (ji->p && ji->anonymous) { + continue; + } else if (ji->p && job_assumes(ji, ji->hopefully_exits_last)) { + job_stop(ji); + } + } + + jm->sent_stop_to_hopefully_last_jobs = true; + } + + if (!SLIST_EMPTY(&jm->submgrs)) { return jm; } - jobmgr_log(jm, LOG_DEBUG, "Asking \"hopefully last\" jobs to exit."); - LIST_FOREACH(ji, &jm->jobs, sle) { - if (ji->p && ji->anonymous) { - continue; - } else if (ji->p && job_assumes(ji, ji->hopefully_exits_last)) { - job_stop(ji); + if (!ji->anonymous) { + return jm; } } - jm->sent_stop_to_hopefully_last_jobs = true; - - return jm; + jobmgr_log_stray_children(jm); + jobmgr_remove(jm); + return NULL; } void @@ -3552,24 +3554,6 @@ free(kp); } -bool -jobmgr_is_idle(jobmgr_t jm) -{ - job_t ji; - - if (!SLIST_EMPTY(&jm->submgrs)) { - return false; - } - - LIST_FOREACH(ji, &jm->jobs, sle) { - if (ji->p && !ji->anonymous) { - return false; - } - } - - return true; -} - jobmgr_t jobmgr_parent(jobmgr_t jm) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070404/b9770e26/attachment.html From source_changes at macosforge.org Wed Apr 4 17:17:39 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23205] tags/launchd-208/ Message-ID: <20070405001739.F1804514E77@cvs.opensource.apple.com> Revision: 23205 http://trac.macosforge.org/projects/launchd/changeset/23205 Author: zarzycki@apple.com Date: 2007-04-04 17:17:39 -0700 (Wed, 04 Apr 2007) Log Message: ----------- "Tagging launchd-208 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-208/ Copied: tags/launchd-208 (from rev 23204, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070404/243b9b32/attachment.html From source_changes at macosforge.org Thu Apr 5 11:45:08 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23206] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070405184508.69838515B9E@cvs.opensource.apple.com> Revision: 23206 http://trac.macosforge.org/projects/launchd/changeset/23206 Author: zarzycki@apple.com Date: 2007-04-05 11:45:08 -0700 (Thu, 05 Apr 2007) Log Message: ----------- Consolidate PID lookups within a given jobmgr_t. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-05 00:17:39 UTC (rev 23205) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-05 18:45:08 UTC (rev 23206) @@ -239,6 +239,7 @@ static void jobmgr_log_stray_children(jobmgr_t jm); static void jobmgr_remove(jobmgr_t jm); static void jobmgr_dispatch_all(jobmgr_t jm, bool newmounthack); +static job_t jobmgr_find_by_pid(jobmgr_t jm, pid_t p); static job_t job_mig_intran2(jobmgr_t jm, mach_port_t p); static void job_export_all2(jobmgr_t jm, launch_data_t where); static void jobmgr_callback(void *obj, struct kevent *kev); @@ -1601,26 +1602,33 @@ return NULL; } +job_t +jobmgr_find_by_pid(jobmgr_t jm, pid_t p) +{ + job_t ji = NULL; + + LIST_FOREACH(ji, &jm->active_jobs[ACTIVE_JOB_HASH(p)], pid_hash_sle) { + if (ji->p == p) { + break; + } + } + + return ji; +} + job_t job_mig_intran2(jobmgr_t jm, mach_port_t p) { + struct ldcred ldc; + jobmgr_t jmi; job_t ji; - jobmgr_t jmi; if (jm->jm_port == p) { - struct ldcred ldc; - pid_t hashp; - runtime_get_caller_creds(&ldc); - hashp = ACTIVE_JOB_HASH(ldc.pid); + ji = jobmgr_find_by_pid(jm, ldc.pid); - LIST_FOREACH(ji, &jm->active_jobs[hashp], pid_hash_sle) { - if (ji->p == ldc.pid) { - return ji; - } - } - return job_new_anonymous(jm, ldc.pid); + return ji ? ji : job_new_anonymous(jm, ldc.pid); } SLIST_FOREACH(jmi, &jm->submgrs, sle) { @@ -1986,22 +1994,15 @@ jobmgr_reap_bulk(jobmgr_t jm, struct kevent *kev) { jobmgr_t jmi; - job_t ji; + job_t j; SLIST_FOREACH(jmi, &jm->submgrs, sle) { jobmgr_reap_bulk(jmi, kev); } - LIST_FOREACH(ji, &jm->active_jobs[ACTIVE_JOB_HASH(kev->ident)], pid_hash_sle) { - if (ji->p != (pid_t)kev->ident) { - continue; - } - - kev->udata = ji; - job_callback(ji, kev); - - /* A given PID exists only once per jobmgr_t */ - break; + if ((j = jobmgr_find_by_pid(jm, kev->ident))) { + kev->udata = j; + job_callback(j, kev); } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070405/f3114ac6/attachment.html From source_changes at macosforge.org Thu Apr 5 14:14:12 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23207] trunk/launchd/src Message-ID: <20070405211412.0C256515E98@cvs.opensource.apple.com> Revision: 23207 http://trac.macosforge.org/projects/launchd/changeset/23207 Author: zarzycki@apple.com Date: 2007-04-05 14:14:11 -0700 (Thu, 05 Apr 2007) Log Message: ----------- SUBTASK: Changes to launchd's job management in support of Seatbelt Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/libbootstrap.c trunk/launchd/src/libbootstrap_private.h trunk/launchd/src/liblaunch_public.h trunk/launchd/src/protocol_job.defs Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-05 18:45:08 UTC (rev 23206) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-05 21:14:11 UTC (rev 23207) @@ -100,6 +100,17 @@ mach_port_t inherited_bootstrap_port; +struct mspolicy { + SLIST_ENTRY(mspolicy) sle; + unsigned int allow:1, per_pid:1; + const char name[0]; +}; + +static bool mspolicy_new(job_t j, const char *name, bool allow, bool pid_local); +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; LIST_ENTRY(machservice) name_hash_sle; @@ -239,8 +250,8 @@ static void jobmgr_log_stray_children(jobmgr_t jm); static void jobmgr_remove(jobmgr_t jm); static void jobmgr_dispatch_all(jobmgr_t jm, bool newmounthack); -static job_t jobmgr_find_by_pid(jobmgr_t jm, pid_t p); -static job_t job_mig_intran2(jobmgr_t jm, mach_port_t p); +static job_t jobmgr_find_by_pid(jobmgr_t jm, pid_t p, bool create_anon); +static job_t job_mig_intran2(jobmgr_t jm, mach_port_t mport, pid_t upid); static void job_export_all2(jobmgr_t jm, launch_data_t where); static void jobmgr_callback(void *obj, struct kevent *kev); static void jobmgr_setup_env_from_other_jobs(jobmgr_t jm); @@ -264,6 +275,7 @@ 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; #if DO_RUSAGE_SUMMATION @@ -305,7 +317,7 @@ unsigned int globargv:1, wait4debugger:1, unload_at_exit:1, stall_before_exec:1, only_once:1, currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1, hopefully_exits_last:1, removal_pending:1, wait4pipe_eof:1, sent_sigkill:1, debug_before_kill:1, weird_bootstrap:1, start_on_mount:1, - per_user:1, hopefully_exits_first:1; + per_user:1, hopefully_exits_first:1, deny_unknown_mslookups:1; const char label[0]; }; @@ -617,9 +629,7 @@ while ((ji = LIST_FIRST(&jm->jobs))) { /* We should only have anonymous jobs left */ - if (job_assumes(ji, ji->anonymous) && ji->p) { - job_reap(ji); - } + job_assumes(ji, ji->anonymous); job_remove(ji); } @@ -651,13 +661,16 @@ job_remove(job_t j) { struct calendarinterval *ci; + struct semaphoreitem *si; struct socketgroup *sg; + struct machservice *ms; struct limititem *li; + struct mspolicy *msp; struct envitem *ei; - struct machservice *ms; - struct semaphoreitem *si; - if (j->p && !j->anonymous) { + if (j->p && j->anonymous) { + job_reap(j); + } else if (j->p) { job_log(j, LOG_DEBUG, "Removal pended until the job exits."); if (!j->removal_pending) { @@ -690,6 +703,9 @@ 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); } @@ -1412,6 +1428,8 @@ 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: @@ -1603,7 +1621,7 @@ } job_t -jobmgr_find_by_pid(jobmgr_t jm, pid_t p) +jobmgr_find_by_pid(jobmgr_t jm, pid_t p, bool create_anon) { job_t ji = NULL; @@ -1613,34 +1631,35 @@ } } - return ji; + if (ji) { + return ji; + } else if (create_anon) { + return job_new_anonymous(jm, p); + } else { + return NULL; + } } job_t -job_mig_intran2(jobmgr_t jm, mach_port_t p) +job_mig_intran2(jobmgr_t jm, mach_port_t mport, pid_t upid) { - struct ldcred ldc; jobmgr_t jmi; job_t ji; - if (jm->jm_port == p) { - runtime_get_caller_creds(&ldc); - - ji = jobmgr_find_by_pid(jm, ldc.pid); - - return ji ? ji : job_new_anonymous(jm, ldc.pid); + if (jm->jm_port == mport) { + return jobmgr_find_by_pid(jm, upid, true); } SLIST_FOREACH(jmi, &jm->submgrs, sle) { job_t jr; - if ((jr = job_mig_intran2(jmi, p))) { + if ((jr = job_mig_intran2(jmi, mport, upid))) { return jr; } } LIST_FOREACH(ji, &jm->jobs, sle) { - if (ji->j_port == p) { + if (ji->j_port == mport) { return ji; } } @@ -1651,15 +1670,18 @@ job_t job_mig_intran(mach_port_t p) { - job_t jr = job_mig_intran2(root_jobmgr, p); + struct ldcred ldc; + job_t jr; + runtime_get_caller_creds(&ldc); + + jr = job_mig_intran2(root_jobmgr, p, ldc.pid); + if (!jobmgr_assumes(root_jobmgr, jr != NULL)) { int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 }; struct kinfo_proc kp; - struct ldcred ldc; size_t len = sizeof(kp); - runtime_get_caller_creds(&ldc); mib[3] = ldc.pid; if (jobmgr_assumes(root_jobmgr, sysctl(mib, 4, &kp, &len, NULL, 0) != -1)) { @@ -2000,7 +2022,7 @@ jobmgr_reap_bulk(jmi, kev); } - if ((j = jobmgr_find_by_pid(jm, kev->ident))) { + if ((j = jobmgr_find_by_pid(jm, kev->ident, false))) { kev->udata = j; job_callback(j, kev); } @@ -4697,6 +4719,11 @@ return VPROC_ERR_TRY_PER_USER; } + if (!mspolicy_check(j, servicename, flags & BOOTSTRAP_PER_PID_SERVICE)) { + job_log(j, LOG_NOTICE, "Policy denied Mach service lookup: %s", servicename); + return BOOTSTRAP_NOT_PRIVILEGED; + } + if (flags & BOOTSTRAP_PER_PID_SERVICE) { ms = jobmgr_lookup_service(j->mgr, servicename, false, target_pid); } else { @@ -4884,7 +4911,7 @@ snprintf(thelabel, sizeof(thelabel), "com.apple.launchctl.%s", session_type); - job_assumes(j, (j2 = job_mig_intran2(root_jobmgr, target_subset)) != NULL); + job_assumes(j, (j2 = job_mig_intran(target_subset)) != NULL); j = j2; jobmgr_log(j->mgr, LOG_DEBUG, "Renaming to: %s", session_type); strcpy(j->mgr->name, session_type); @@ -4897,7 +4924,7 @@ return 0; } - if (getpid() != 1 && job_mig_intran2(root_jobmgr, target_subset)) { + if (getpid() != 1 && job_mig_intran(target_subset)) { job_assumes(j, launchd_mport_deallocate(target_subset) == KERN_SUCCESS); return 0; } @@ -5164,6 +5191,34 @@ } kern_return_t +job_mig_set_service_policy(job_t j, pid_t target_pid, uint64_t flags, name_t target_service) +{ + job_t target_j; + + if (!launchd_assumes(j != NULL)) { + return BOOTSTRAP_NO_MEMORY; + } + + if (!job_assumes(j, (target_j = jobmgr_find_by_pid(j->mgr, target_pid, true)) != NULL)) { + return BOOTSTRAP_NO_MEMORY; + } + + if (SLIST_EMPTY(&j->mspolicies)) { + job_log(j, LOG_DEBUG, "Setting policy on job \"%s\" for Mach service: %s", target_j->label, target_service); + if (target_service[0]) { + job_assumes(j, mspolicy_new(target_j, target_service, flags & BOOTSTRAP_ALLOW_LOOKUP, flags & BOOTSTRAP_PER_PID_SERVICE)); + } else { + target_j->deny_unknown_mslookups = !(flags & BOOTSTRAP_ALLOW_LOOKUP); + } + } else { + job_log(j, LOG_WARNING, "Jobs that have policies assigned to them may not set policies."); + return BOOTSTRAP_NOT_PRIVILEGED; + } + + return 0; +} + +kern_return_t job_mig_spawn(job_t j, _internal_string_t charbuf, mach_msg_type_number_t charbuf_cnt, uint32_t argc, uint32_t envc, uint64_t flags, uint16_t mig_umask, binpref_t bin_pref, uint32_t binpref_cnt, pid_t *child_pid, mach_port_t *obsvr_port) @@ -5286,3 +5341,66 @@ { return our_strhash(msstr) % MACHSERVICE_HASH_SIZE; } + +bool +mspolicy_new(job_t j, const char *name, bool allow, bool pid_local) +{ + struct mspolicy *msp; + + SLIST_FOREACH(msp, &j->mspolicies, sle) { + if (msp->per_pid != pid_local) { + continue; + } else if (strcmp(msp->name, name) == 0) { + return false; + } + } + + if ((msp = calloc(1, sizeof(struct mspolicy) + strlen(name) + 1)) == NULL) { + return false; + } + + strcpy((char *)msp->name, name); + msp->per_pid = pid_local; + + 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)); +} + +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); +} Modified: trunk/launchd/src/libbootstrap.c =================================================================== --- trunk/launchd/src/libbootstrap.c 2007-04-05 18:45:08 UTC (rev 23206) +++ trunk/launchd/src/libbootstrap.c 2007-04-05 21:14:11 UTC (rev 23207) @@ -69,6 +69,12 @@ } kern_return_t +bootstrap_set_policy(mach_port_t bp, pid_t target_pid, uint64_t flags, const char *target_service) +{ + return vproc_mig_set_service_policy(bp, target_pid, flags, target_service ? (char *)target_service : ""); +} + +kern_return_t bootstrap_register(mach_port_t bp, name_t service_name, mach_port_t sp) { return bootstrap_register2(bp, service_name, sp, 0); Modified: trunk/launchd/src/libbootstrap_private.h =================================================================== --- trunk/launchd/src/libbootstrap_private.h 2007-04-05 18:45:08 UTC (rev 23206) +++ trunk/launchd/src/libbootstrap_private.h 2007-04-05 21:14:11 UTC (rev 23207) @@ -27,7 +27,8 @@ #pragma GCC visibility push(default) -#define BOOTSTRAP_PER_PID_SERVICE 1 +#define BOOTSTRAP_PER_PID_SERVICE 0x1 +#define BOOTSTRAP_ALLOW_LOOKUP 0x2 kern_return_t bootstrap_register2(mach_port_t bp, name_t service_name, mach_port_t sp, uint64_t flags); @@ -35,6 +36,8 @@ kern_return_t bootstrap_look_up_per_user(mach_port_t bp, name_t service_name, uid_t target_user, mach_port_t *sp); +kern_return_t bootstrap_set_policy(mach_port_t bp, pid_t target_pid, uint64_t flags, const char *target_service); + #pragma GCC visibility pop __END_DECLS Modified: trunk/launchd/src/liblaunch_public.h =================================================================== --- trunk/launchd/src/liblaunch_public.h 2007-04-05 18:45:08 UTC (rev 23206) +++ trunk/launchd/src/liblaunch_public.h 2007-04-05 21:14:11 UTC (rev 23207) @@ -62,6 +62,7 @@ #define LAUNCH_JOBKEY_INITGROUPS "InitGroups" #define LAUNCH_JOBKEY_SOCKETS "Sockets" #define LAUNCH_JOBKEY_MACHSERVICES "MachServices" +#define LAUNCH_JOBKEY_MACHSERVICELOOKUPPOLICIES "MachServiceLookupPolicies" #define LAUNCH_JOBKEY_INETDCOMPATIBILITY "inetdCompatibility" #define LAUNCH_JOBKEY_ENABLEGLOBBING "EnableGlobbing" #define LAUNCH_JOBKEY_PROGRAMARGUMENTS "ProgramArguments" Modified: trunk/launchd/src/protocol_job.defs =================================================================== --- trunk/launchd/src/protocol_job.defs 2007-04-05 18:45:08 UTC (rev 23206) +++ trunk/launchd/src/protocol_job.defs 2007-04-05 21:14:11 UTC (rev 23207) @@ -130,7 +130,11 @@ __inval : int64_t; out __outval : int64_t); -skip; +routine set_service_policy( + __bs_port : job_t; + __target_pid : pid_t; + __flags : uint64_t; + __service : name_t); simpleroutine log( __bs_port : job_t; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070405/982c26a7/attachment.html From source_changes at macosforge.org Thu Apr 5 16:26:16 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23208] trunk/launchd/src Message-ID: <20070405232616.C3737516127@cvs.opensource.apple.com> Revision: 23208 http://trac.macosforge.org/projects/launchd/changeset/23208 Author: zarzycki@apple.com Date: 2007-04-05 16:26:16 -0700 (Thu, 05 Apr 2007) Log Message: ----------- Let's be smarter about post fork() behavior and how we setup the Mach exception port. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/libvproc.c trunk/launchd/src/libvproc_internal.h trunk/launchd/src/protocol_job.defs trunk/launchd/src/protocol_job_reply.defs Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-05 21:14:11 UTC (rev 23207) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-05 23:26:16 UTC (rev 23208) @@ -352,6 +352,7 @@ static void job_postfork_become_user(job_t j); static void job_find_and_blame_pids_with_weird_uids(job_t j); static void job_force_sampletool(job_t j); +static void job_setup_exception_port(job_t j, task_t target_task); static void job_reparent_hack(job_t j, const char *where); static void job_callback(void *obj, struct kevent *kev); static void job_callback_proc(job_t j, int flags, int fflags); @@ -400,6 +401,8 @@ static int dir_has_files(job_t j, const char *path); static char **mach_cmd2argv(const char *string); static size_t our_strhash(const char *s) __attribute__((pure)); +static mach_port_t the_exception_server; + jobmgr_t root_jobmgr; void @@ -2153,6 +2156,9 @@ } break; case 0: + if (_vproc_post_fork_ping()) { + _exit(EXIT_FAILURE); + } if (!j->legacy_mach_job) { job_assumes(j, dup2(oepair[1], STDOUT_FILENO) != -1); job_assumes(j, dup2(oepair[1], STDERR_FILENO) != -1); @@ -3359,16 +3365,15 @@ } void -machservice_setup_options(launch_data_t obj, const char *key, void *context) +job_setup_exception_port(job_t j, task_t target_task) { - struct machservice *ms = context; - mach_port_t mhp = mach_host_self(); - mach_port_t mts = mach_task_self(); thread_state_flavor_t f = 0; exception_mask_t em; - int which_port; - bool b; + if (!the_exception_server) { + return; + } + #if defined (__ppc__) f = PPC_THREAD_STATE64; #elif defined(__i386__) @@ -3381,6 +3386,19 @@ em = EXC_MASK_RPC_ALERT; #endif + job_assumes(j, task_set_exception_ports(target_task, em, the_exception_server, + EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); + +} + +void +machservice_setup_options(launch_data_t obj, const char *key, void *context) +{ + struct machservice *ms = context; + mach_port_t mhp = mach_host_self(); + int which_port; + bool b; + if (!job_assumes(ms->job, mhp != MACH_PORT_NULL)) { return; } @@ -3399,7 +3417,7 @@ job_log(ms->job, LOG_WARNING, "Tried to set a reserved task special port: %d", which_port); break; default: - job_assumes(ms->job, (errno = task_set_special_port(mts, which_port, ms->port)) == KERN_SUCCESS); + job_assumes(ms->job, (errno = task_set_special_port(mach_task_self(), which_port, ms->port)) == KERN_SUCCESS); break; } } else if (strcasecmp(key, LAUNCH_JOBKEY_MACH_HOSTSPECIALPORT) == 0 && getpid() == 1) { @@ -3418,20 +3436,22 @@ } else if (strcasecmp(key, LAUNCH_JOBKEY_MACH_HIDEUNTILCHECKIN) == 0) { ms->hide = b; } else if (strcasecmp(key, LAUNCH_JOBKEY_MACH_EXCEPTIONSERVER) == 0) { - job_assumes(ms->job, task_set_exception_ports(mts, em, ms->port, - EXCEPTION_STATE_IDENTITY, f) == KERN_SUCCESS); + if (!the_exception_server) { + the_exception_server = ms->port; + } else { + job_log(ms->job, LOG_WARNING, "The exception server is already claimed!"); + } } else if (strcasecmp(key, LAUNCH_JOBKEY_MACH_KUNCSERVER) == 0) { ms->kUNCServer = b; job_assumes(ms->job, host_set_UNDServer(mhp, ms->port) == KERN_SUCCESS); } break; case LAUNCH_DATA_DICTIONARY: -#ifdef MACH_EXCEPTION_CODES - if (strcasecmp(key, LAUNCH_JOBKEY_MACH_EXCEPTIONSERVER) == 0) { - job_assumes(ms->job, task_set_exception_ports(mts, em, ms->port, - EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); + if (!the_exception_server) { + the_exception_server = ms->port; + } else { + job_log(ms->job, LOG_WARNING, "The exception server is already claimed!"); } -#endif break; default: break; @@ -4458,6 +4478,22 @@ } kern_return_t +job_mig_post_fork_ping(job_t j, task_t child_task) +{ + if (!launchd_assumes(j != NULL)) { + return BOOTSTRAP_NO_MEMORY; + } + + job_log(j, LOG_DEBUG, "Post fork ping."); + + job_setup_exception_port(j, child_task); + + job_assumes(j, launchd_mport_deallocate(child_task) == KERN_SUCCESS); + + return 0; +} + +kern_return_t job_mig_reboot2(job_t j, uint64_t flags) { char who_started_the_reboot[2048] = ""; Modified: trunk/launchd/src/libvproc.c =================================================================== --- trunk/launchd/src/libvproc.c 2007-04-05 21:14:11 UTC (rev 23207) +++ trunk/launchd/src/libvproc.c 2007-04-05 23:26:16 UTC (rev 23208) @@ -52,6 +52,12 @@ } vproc_err_t +_vproc_post_fork_ping(void) +{ + return vproc_mig_post_fork_ping(bootstrap_port, mach_task_self()) == 0 ? NULL : _vproc_post_fork_ping; +} + +vproc_err_t _vprocmgr_move_subset_to_user(uid_t target_user, char *session_type) { kern_return_t kr = 1; Modified: trunk/launchd/src/libvproc_internal.h =================================================================== --- trunk/launchd/src/libvproc_internal.h 2007-04-05 21:14:11 UTC (rev 23207) +++ trunk/launchd/src/libvproc_internal.h 2007-04-05 23:26:16 UTC (rev 23208) @@ -39,6 +39,8 @@ #pragma GCC visibility push(default) +vproc_err_t _vproc_post_fork_ping(void); + #define SPAWN_HAS_PATH 0x0001 #define SPAWN_HAS_WDIR 0x0002 #define SPAWN_HAS_UMASK 0x0004 Modified: trunk/launchd/src/protocol_job.defs =================================================================== --- trunk/launchd/src/protocol_job.defs 2007-04-05 21:14:11 UTC (rev 23207) +++ trunk/launchd/src/protocol_job.defs 2007-04-05 23:26:16 UTC (rev 23208) @@ -74,7 +74,9 @@ __bs_port : job_t; out __parent_port : mach_port_send_t); -skip; /* last used in 10.4 */ +routine post_fork_ping( + __bs_port : job_t; + __task_port : task_t); routine info( __bs_port : job_t; Modified: trunk/launchd/src/protocol_job_reply.defs =================================================================== --- trunk/launchd/src/protocol_job_reply.defs 2007-04-05 21:14:11 UTC (rev 23207) +++ trunk/launchd/src/protocol_job_reply.defs 2007-04-05 23:26:16 UTC (rev 23208) @@ -41,7 +41,7 @@ skip; /* parent */ -skip; +skip; /* post_fork_ping */ skip; /* info */ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070405/978b98be/attachment.html From source_changes at macosforge.org Fri Apr 6 15:00:12 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23209] trunk/launchd/src/liblaunch.c Message-ID: <20070406220012.2BCF8517500@cvs.opensource.apple.com> Revision: 23209 http://trac.macosforge.org/projects/launchd/changeset/23209 Author: zarzycki@apple.com Date: 2007-04-06 15:00:11 -0700 (Fri, 06 Apr 2007) Log Message: ----------- Leopard9A403: filesystem issues? under 9A401 and later Modified Paths: -------------- trunk/launchd/src/liblaunch.c Modified: trunk/launchd/src/liblaunch.c =================================================================== --- trunk/launchd/src/liblaunch.c 2007-04-05 23:26:16 UTC (rev 23208) +++ trunk/launchd/src/liblaunch.c 2007-04-06 22:00:11 UTC (rev 23209) @@ -347,7 +347,7 @@ launch_data_array_set_index(launch_data_t where, launch_data_t what, size_t ind) { if ((ind + 1) >= where->_array_cnt) { - where->_array = realloc(where->_array, (ind + 1) * sizeof(launch_data_t)); + where->_array = reallocf(where->_array, (ind + 1) * sizeof(launch_data_t)); memset(where->_array + where->_array_cnt, 0, (ind + 1 - where->_array_cnt) * sizeof(launch_data_t)); where->_array_cnt = ind + 1; } @@ -582,7 +582,7 @@ launch_data_t o_in_w; size_t i; - *where = realloc(*where, *len + sizeof(struct _launch_data)); + *where = reallocf(*where, *len + sizeof(struct _launch_data)); o_in_w = *where + *len; memset(o_in_w, 0, sizeof(struct _launch_data)); @@ -606,27 +606,27 @@ case LAUNCH_DATA_FD: o_in_w->fd = host2big(d->fd); if (d->fd != -1) { - *fd_where = realloc(*fd_where, (*fdcnt + 1) * sizeof(int)); + *fd_where = reallocf(*fd_where, (*fdcnt + 1) * sizeof(int)); (*fd_where)[*fdcnt] = d->fd; (*fdcnt)++; } break; case LAUNCH_DATA_STRING: o_in_w->string_len = host2big(d->string_len); - *where = realloc(*where, *len + strlen(d->string) + 1); + *where = reallocf(*where, ROUND_TO_64BIT_WORD_SIZE(*len + strlen(d->string) + 1)); memcpy(*where + *len, d->string, strlen(d->string) + 1); *len += ROUND_TO_64BIT_WORD_SIZE(strlen(d->string) + 1); break; case LAUNCH_DATA_OPAQUE: o_in_w->opaque_size = host2big(d->opaque_size); - *where = realloc(*where, *len + d->opaque_size); + *where = reallocf(*where, ROUND_TO_64BIT_WORD_SIZE(*len + d->opaque_size)); memcpy(*where + *len, d->opaque, d->opaque_size); *len += ROUND_TO_64BIT_WORD_SIZE(d->opaque_size); break; case LAUNCH_DATA_DICTIONARY: case LAUNCH_DATA_ARRAY: o_in_w->_array_cnt = host2big(d->_array_cnt); - *where = realloc(*where, *len + (d->_array_cnt * sizeof(uint64_t))); + *where = reallocf(*where, *len + (d->_array_cnt * sizeof(uint64_t))); memset(*where + *len, 0, d->_array_cnt * sizeof(uint64_t)); *len += d->_array_cnt * sizeof(uint64_t); @@ -920,7 +920,7 @@ mh.msg_iov = &iov; mh.msg_iovlen = 1; - lh->recvbuf = realloc(lh->recvbuf, lh->recvlen + 8*1024); + lh->recvbuf = reallocf(lh->recvbuf, lh->recvlen + 8*1024); iov.iov_base = lh->recvbuf + lh->recvlen; iov.iov_len = 8*1024; @@ -939,7 +939,7 @@ } lh->recvlen += r; if (mh.msg_controllen > 0) { - lh->recvfds = realloc(lh->recvfds, lh->recvfdcnt * sizeof(int) + mh.msg_controllen - sizeof(struct cmsghdr)); + lh->recvfds = reallocf(lh->recvfds, lh->recvfdcnt * sizeof(int) + mh.msg_controllen - sizeof(struct cmsghdr)); memcpy(lh->recvfds + lh->recvfdcnt, CMSG_DATA(cm), mh.msg_controllen - sizeof(struct cmsghdr)); lh->recvfdcnt += (mh.msg_controllen - sizeof(struct cmsghdr)) / sizeof(int); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070406/15e5f924/attachment.html From source_changes at macosforge.org Fri Apr 6 15:11:15 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23210] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070406221115.EF6E9517540@cvs.opensource.apple.com> Revision: 23210 http://trac.macosforge.org/projects/launchd/changeset/23210 Author: zarzycki@apple.com Date: 2007-04-06 15:11:15 -0700 (Fri, 06 Apr 2007) Log Message: ----------- Fix another memory smasher. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-06 22:00:11 UTC (rev 23209) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-06 22:11:15 UTC (rev 23210) @@ -1016,7 +1016,8 @@ char auto_label[1000]; char *bn = NULL; char *co; - int minlabel_len, i, cc = 0; + size_t minlabel_len; + int i, cc = 0; job_t j; launchd_assert(offsetof(struct job_s, kqjob_callback) == 0); @@ -1038,9 +1039,10 @@ } /* This is so we can do gross things later. See NOTE_EXEC for anonymous jobs */ +#define MAX_ANONYMOUS_LABEL_LEN (sizeof("anonymous-100000.") + MAXCOMLEN) minlabel_len = strlen(label); - if (minlabel_len < MAXCOMLEN) { - minlabel_len = MAXCOMLEN; + if (minlabel_len < MAX_ANONYMOUS_LABEL_LEN) { + minlabel_len = MAX_ANONYMOUS_LABEL_LEN; } j = calloc(1, sizeof(struct job_s) + minlabel_len + 1); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070406/e8830aaa/attachment.html From source_changes at macosforge.org Tue Apr 10 13:25:07 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23211] tags/launchd-209/ Message-ID: <20070410202507.9066152869C@cvs.opensource.apple.com> Revision: 23211 http://trac.macosforge.org/projects/launchd/changeset/23211 Author: zarzycki@apple.com Date: 2007-04-10 13:25:07 -0700 (Tue, 10 Apr 2007) Log Message: ----------- "Tagging launchd-209 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-209/ Copied: tags/launchd-209 (from rev 23210, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070410/6023d363/attachment.html From source_changes at macosforge.org Wed Apr 11 08:33:08 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23212] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070411153308.894B352D6D4@cvs.opensource.apple.com> Revision: 23212 http://trac.macosforge.org/projects/launchd/changeset/23212 Author: zarzycki@apple.com Date: 2007-04-11 08:33:07 -0700 (Wed, 11 Apr 2007) Log Message: ----------- launchd should use confstr(_CS_DARWIN_USER_TEMP_DIR, ...) Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-10 20:25:07 UTC (rev 23211) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-11 15:33:07 UTC (rev 23212) @@ -2342,9 +2342,11 @@ job_postfork_become_user(job_t j) { char loginname[2000]; + char tmpdirpath[PATH_MAX]; char shellpath[PATH_MAX]; char homedir[PATH_MAX]; struct passwd *pwe; + size_t r; gid_t desired_gid = -1; uid_t desired_uid = -1; @@ -2419,6 +2421,12 @@ _exit(EXIT_FAILURE); } + r = confstr(_CS_DARWIN_USER_TEMP_DIR, tmpdirpath, sizeof(tmpdirpath)); + + if (r > 0 && r < sizeof(tmpdirpath)) { + setenv("TMPDIR", tmpdirpath, 0); + } + setenv("SHELL", shellpath, 0); setenv("HOME", homedir, 0); setenv("USER", loginname, 0); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070411/a1f9f6f3/attachment.html From source_changes at macosforge.org Wed Apr 11 09:29:38 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23213] trunk/launchd/src/launchctl.c Message-ID: <20070411162938.7CFF252D757@cvs.opensource.apple.com> Revision: 23213 http://trac.macosforge.org/projects/launchd/changeset/23213 Author: zarzycki@apple.com Date: 2007-04-11 09:29:37 -0700 (Wed, 11 Apr 2007) Log Message: ----------- 9A380: launchd.conf limit core unlimited not honored Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-04-11 15:33:07 UTC (rev 23212) +++ trunk/launchd/src/launchctl.c 2007-04-11 16:29:37 UTC (rev 23213) @@ -140,6 +140,7 @@ static void do_bootroot_magic(void); static void do_single_user_mode(bool); static bool do_single_user_mode2(void); +static void read_launchd_conf(void); typedef enum { BOOTCACHE_START = 1, @@ -287,6 +288,39 @@ return 1; } +void +read_launchd_conf(void) +{ + FILE *f = fopen("/etc/launchd.conf", "r"); + char s[1000], *c, *av[100]; + size_t len, i; + + if (!(f = fopen("/etc/launchd.conf", "r"))) { + return; + } + + while ((c = fgets(s, sizeof(s), f))) { + len = strlen(c); + if (len && c[len - 1] == '\n') { + c[len - 1] = '\0'; + } + + i = 0; + + while ((av[i] = strsep(&c, " \t"))) { + if (*(av[i]) != '\0') { + i++; + } + } + + if (i > 0) { + demux_cmd(i, av); + } + } + + fclose(f); +} + int unsetenv_cmd(int argc, char *const argv[]) { @@ -1332,6 +1366,8 @@ do_potential_fsck(); } + read_launchd_conf(); + if (path_check("/var/account/acct")) { assumes(acct("/var/account/acct") != -1); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070411/2e0a309b/attachment.html From source_changes at macosforge.org Wed Apr 11 11:22:27 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23214] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070411182227.D819452D940@cvs.opensource.apple.com> Revision: 23214 http://trac.macosforge.org/projects/launchd/changeset/23214 Author: zarzycki@apple.com Date: 2007-04-11 11:22:27 -0700 (Wed, 11 Apr 2007) Log Message: ----------- It is safer to assume that a program crashed. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-11 16:29:37 UTC (rev 23213) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-11 18:22:27 UTC (rev 23214) @@ -1752,7 +1752,7 @@ { struct timeval tve, tvd; struct rusage ru; - int status = 0; + int status; job_log(j, LOG_DEBUG, "Reaping"); @@ -1778,14 +1778,10 @@ } if (!j->anonymous && !job_assumes(j, wait4(j->p, &status, 0, &ru) != -1)) { - /* - * wait4() then kill() is still racy. - * Then again, we never should have got here in the first place... - */ - if (kill(j->p, 0) == 0) { - job_log(j, LOG_DEBUG, "Working around 5020256"); - } + job_log(j, LOG_NOTICE, "Working around 5020256. Assuming the job crashed."); + status = W_EXITCODE(0, SIGSEGV); + memset(&ru, 0, sizeof(ru)); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070411/75c4188c/attachment.html From source_changes at macosforge.org Wed Apr 11 11:28:22 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23215] trunk/launchd/src/launchctl.c Message-ID: <20070411182822.379E652D988@cvs.opensource.apple.com> Revision: 23215 http://trac.macosforge.org/projects/launchd/changeset/23215 Author: zarzycki@apple.com Date: 2007-04-11 11:28:22 -0700 (Wed, 11 Apr 2007) Log Message: ----------- Copy/paste error. Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-04-11 18:22:27 UTC (rev 23214) +++ trunk/launchd/src/launchctl.c 2007-04-11 18:28:22 UTC (rev 23215) @@ -291,9 +291,9 @@ void read_launchd_conf(void) { - FILE *f = fopen("/etc/launchd.conf", "r"); char s[1000], *c, *av[100]; size_t len, i; + FILE *f; if (!(f = fopen("/etc/launchd.conf", "r"))) { return; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070411/a51cde6a/attachment.html From source_changes at macosforge.org Wed Apr 11 14:19:27 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23216] tags/launchd-210/ Message-ID: <20070411211927.53DC752DDFD@cvs.opensource.apple.com> Revision: 23216 http://trac.macosforge.org/projects/launchd/changeset/23216 Author: zarzycki@apple.com Date: 2007-04-11 14:19:26 -0700 (Wed, 11 Apr 2007) Log Message: ----------- "Tagging launchd-210 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-210/ Copied: tags/launchd-210 (from rev 23215, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070411/5c760c1a/attachment.html From source_changes at macosforge.org Wed Apr 11 19:06:44 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23217] trunk/launchd/TODO Message-ID: <20070412020644.4690152E29D@cvs.opensource.apple.com> Revision: 23217 http://trac.macosforge.org/projects/launchd/changeset/23217 Author: zarzycki@apple.com Date: 2007-04-11 19:06:44 -0700 (Wed, 11 Apr 2007) Log Message: ----------- I use Apple's internal issue ("bug") tracking system for my TODO list. Modified Paths: -------------- trunk/launchd/TODO Modified: trunk/launchd/TODO =================================================================== --- trunk/launchd/TODO 2007-04-11 21:19:26 UTC (rev 23216) +++ trunk/launchd/TODO 2007-04-12 02:06:44 UTC (rev 23217) @@ -1,20 +0,0 @@ -per user support -\_ job mgmt -\_ tmp dir -job exponential backoff and recursion prevention - - - -file system events -mach events -cron -at -legacy parsers -monitor -\_ cocoa -\_ cli -documentation -code audit -init support -anacron support -sample dameon -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070411/198292c2/attachment.html From source_changes at macosforge.org Thu Apr 12 13:54:45 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23218] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070412205445.10F0952ED1A@cvs.opensource.apple.com> Revision: 23218 http://trac.macosforge.org/projects/launchd/changeset/23218 Author: zarzycki@apple.com Date: 2007-04-12 13:54:44 -0700 (Thu, 12 Apr 2007) Log Message: ----------- Miscellaneous fixes. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-12 02:06:44 UTC (rev 23217) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-12 20:54:44 UTC (rev 23218) @@ -1777,7 +1777,10 @@ j->forkfd = 0; } - if (!j->anonymous && !job_assumes(j, wait4(j->p, &status, 0, &ru) != -1)) { + if (j->anonymous) { + status = 0; + memset(&ru, 0, sizeof(ru)); + } else if (!job_assumes(j, wait4(j->p, &status, 0, &ru) != -1)) { job_log(j, LOG_NOTICE, "Working around 5020256. Assuming the job crashed."); status = W_EXITCODE(0, SIGSEGV); @@ -3295,7 +3298,9 @@ void machservice_watch(job_t j, struct machservice *ms) { - job_assumes(j, runtime_add_mport(ms->port, NULL, 0) == KERN_SUCCESS); + if (job_assumes(j, ms->recv)) { + job_assumes(j, runtime_add_mport(ms->port, NULL, 0) == KERN_SUCCESS); + } } void -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070412/984bceb2/attachment.html From source_changes at macosforge.org Thu Apr 12 14:35:38 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23219] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070412213538.0959852ED6D@cvs.opensource.apple.com> Revision: 23219 http://trac.macosforge.org/projects/launchd/changeset/23219 Author: zarzycki@apple.com Date: 2007-04-12 14:35:37 -0700 (Thu, 12 Apr 2007) Log Message: ----------- setuid processes should have their exception ports repointed at the ReportCrash launchdaemon Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-12 20:54:44 UTC (rev 23218) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-12 21:35:37 UTC (rev 23219) @@ -371,6 +371,7 @@ static void job_logv(job_t j, int pri, int err, const char *msg, va_list ap) __attribute__((format(printf, 4, 0))); static void job_log_error(job_t j, int pri, const char *msg, ...) __attribute__((format(printf, 3, 4))); static void job_log_bug(job_t j, const char *rcs_rev, const char *path, unsigned int line, const char *test); +static void job_set_exeception_port(job_t j, mach_port_t port); static kern_return_t job_handle_mpm_wait(job_t j, mach_port_t srp, int *waitstatus); @@ -3397,12 +3398,30 @@ em = EXC_MASK_RPC_ALERT; #endif - job_assumes(j, task_set_exception_ports(target_task, em, the_exception_server, - EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); + if (target_task) { + job_assumes(j, task_set_exception_ports(target_task, em, the_exception_server, + EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); + } else if (getpid() == 1) { + mach_port_t mhp = mach_host_self(); + job_assumes(j, host_set_exception_ports(mhp, em, the_exception_server, + EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); + job_assumes(j, launchd_mport_deallocate(mhp) == KERN_SUCCESS); + } } void +job_set_exeception_port(job_t j, mach_port_t port) +{ + if (!the_exception_server) { + the_exception_server = port; + job_setup_exception_port(j, 0); + } else { + job_log(j, LOG_WARNING, "The exception server is already claimed!"); + } +} + +void machservice_setup_options(launch_data_t obj, const char *key, void *context) { struct machservice *ms = context; @@ -3447,22 +3466,14 @@ } else if (strcasecmp(key, LAUNCH_JOBKEY_MACH_HIDEUNTILCHECKIN) == 0) { ms->hide = b; } else if (strcasecmp(key, LAUNCH_JOBKEY_MACH_EXCEPTIONSERVER) == 0) { - if (!the_exception_server) { - the_exception_server = ms->port; - } else { - job_log(ms->job, LOG_WARNING, "The exception server is already claimed!"); - } + job_set_exeception_port(ms->job, ms->port); } else if (strcasecmp(key, LAUNCH_JOBKEY_MACH_KUNCSERVER) == 0) { ms->kUNCServer = b; job_assumes(ms->job, host_set_UNDServer(mhp, ms->port) == KERN_SUCCESS); } break; case LAUNCH_DATA_DICTIONARY: - if (!the_exception_server) { - the_exception_server = ms->port; - } else { - job_log(ms->job, LOG_WARNING, "The exception server is already claimed!"); - } + job_set_exeception_port(ms->job, ms->port); break; default: break; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070412/f5dd5102/attachment.html From source_changes at macosforge.org Thu Apr 12 14:41:07 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23220] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070412214107.24DD952ED85@cvs.opensource.apple.com> Revision: 23220 http://trac.macosforge.org/projects/launchd/changeset/23220 Author: zarzycki@apple.com Date: 2007-04-12 14:41:06 -0700 (Thu, 12 Apr 2007) Log Message: ----------- Delete transitional conditional. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-12 21:35:37 UTC (rev 23219) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-12 21:41:06 UTC (rev 23220) @@ -3380,7 +3380,6 @@ job_setup_exception_port(job_t j, task_t target_task) { thread_state_flavor_t f = 0; - exception_mask_t em; if (!the_exception_server) { return; @@ -3392,18 +3391,12 @@ f = x86_THREAD_STATE; #endif -#if defined(EXC_MASK_CRASH) - em = EXC_MASK_CRASH; -#else - em = EXC_MASK_RPC_ALERT; -#endif - if (target_task) { - job_assumes(j, task_set_exception_ports(target_task, em, the_exception_server, + job_assumes(j, task_set_exception_ports(target_task, EXC_MASK_CRASH, the_exception_server, EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); } else if (getpid() == 1) { mach_port_t mhp = mach_host_self(); - job_assumes(j, host_set_exception_ports(mhp, em, the_exception_server, + job_assumes(j, host_set_exception_ports(mhp, EXC_MASK_CRASH, the_exception_server, EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); job_assumes(j, launchd_mport_deallocate(mhp) == KERN_SUCCESS); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070412/afe7daa5/attachment.html From source_changes at macosforge.org Mon Apr 16 13:23:05 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23221] tags/launchd-211/ Message-ID: <20070416202305.2D80C5331F6@cvs.opensource.apple.com> Revision: 23221 http://trac.macosforge.org/projects/launchd/changeset/23221 Author: zarzycki@apple.com Date: 2007-04-16 13:23:04 -0700 (Mon, 16 Apr 2007) Log Message: ----------- "Tagging launchd-211 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-211/ Copied: tags/launchd-211 (from rev 23220, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070416/ca78220e/attachment.html From source_changes at macosforge.org Mon Apr 16 15:33:32 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23222] trunk/launchd/src Message-ID: <20070416223332.4DAAA5333A1@cvs.opensource.apple.com> Revision: 23222 http://trac.macosforge.org/projects/launchd/changeset/23222 Author: zarzycki@apple.com Date: 2007-04-16 15:33:31 -0700 (Mon, 16 Apr 2007) Log Message: ----------- Miscellaneous fixes. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-16 20:23:04 UTC (rev 23221) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-16 22:33:31 UTC (rev 23222) @@ -2121,8 +2121,6 @@ return; } - job_log(j, LOG_DEBUG, "Starting"); - j->sent_sigterm_time.tv_sec = 0; j->sent_sigterm_time.tv_usec = 0; @@ -2130,7 +2128,6 @@ sipc = (!SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices)); } - j->checkedin = false; if (sipc) { @@ -2178,6 +2175,8 @@ job_start_child(j); break; default: + job_log(j, LOG_DEBUG, "Started as PID: %u", c); + total_children++; LIST_INSERT_HEAD(&j->mgr->active_jobs[ACTIVE_JOB_HASH(c)], j, pid_hash_sle); @@ -3299,7 +3298,7 @@ void machservice_watch(job_t j, struct machservice *ms) { - if (job_assumes(j, ms->recv)) { + if (ms->recv) { job_assumes(j, runtime_add_mport(ms->port, NULL, 0) == KERN_SUCCESS); } } Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-04-16 20:23:04 UTC (rev 23221) +++ trunk/launchd/src/launchd_runtime.c 2007-04-16 22:33:31 UTC (rev 23222) @@ -132,8 +132,8 @@ launchd_assert(pthread_create(&demand_thread, &attr, mport_demand_loop, NULL) == 0); pthread_attr_destroy(&attr); - openlog(getprogname(), LOG_PID|LOG_CONS, LOG_LAUNCHD); - setlogmask(LOG_UPTO(/* LOG_DEBUG */ LOG_NOTICE)); + runtime_openlog(getprogname(), LOG_PID|LOG_CONS, LOG_LAUNCHD); + runtime_setlogmask(LOG_UPTO(/* LOG_DEBUG */ LOG_NOTICE)); } void * -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070416/60d0e5ca/attachment.html From source_changes at macosforge.org Tue Apr 17 08:46:11 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:46 2007 Subject: [launchd-changes] [23223] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070417154611.64B5C534198@cvs.opensource.apple.com> Revision: 23223 http://trac.macosforge.org/projects/launchd/changeset/23223 Author: zarzycki@apple.com Date: 2007-04-17 08:46:10 -0700 (Tue, 17 Apr 2007) Log Message: ----------- tag BootCache twice Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-16 22:33:31 UTC (rev 23222) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-17 15:46:10 UTC (rev 23223) @@ -403,6 +403,7 @@ static char **mach_cmd2argv(const char *string); static size_t our_strhash(const char *s) __attribute__((pure)); static mach_port_t the_exception_server; +static bool did_first_per_user_launchd_BootCache_hack; jobmgr_t root_jobmgr; @@ -2180,6 +2181,10 @@ total_children++; LIST_INSERT_HEAD(&j->mgr->active_jobs[ACTIVE_JOB_HASH(c)], j, pid_hash_sle); + if (j->per_user && !did_first_per_user_launchd_BootCache_hack) { + did_first_per_user_launchd_BootCache_hack = true; + } + if (!j->legacy_mach_job) { job_assumes(j, runtime_close(oepair[1]) != -1); } @@ -2209,6 +2214,23 @@ } } +static void +do_first_per_user_launchd_hack(void) +{ + char *bcct_tool[] = { "/usr/sbin/BootCacheControl", "tag", NULL }; + int dummystatus; + pid_t bcp; + + if (launchd_assumes((bcp = vfork()) != -1)) { + if (bcp == 0) { + execve(bcct_tool[0], bcct_tool, environ); + _exit(EXIT_FAILURE); + } else { + launchd_assumes(waitpid(bcp, &dummystatus, 0) != -1); + } + } +} + void job_start_child(job_t j) { @@ -2222,6 +2244,10 @@ size_t binpref_out_cnt = 0; int i; + if (j->per_user && !did_first_per_user_launchd_BootCache_hack) { + do_first_per_user_launchd_hack(); + } + job_assumes(j, posix_spawnattr_init(&spattr) == 0); job_setup_attributes(j); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070417/24f38f57/attachment.html From source_changes at macosforge.org Tue Apr 17 08:56:02 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23224] trunk/launchd/src Message-ID: <20070417155602.F3EEA5341BE@cvs.opensource.apple.com> Revision: 23224 http://trac.macosforge.org/projects/launchd/changeset/23224 Author: zarzycki@apple.com Date: 2007-04-17 08:56:02 -0700 (Tue, 17 Apr 2007) Log Message: ----------- Need direct access to TimeOut key Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/libvproc_private.h Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-17 15:46:10 UTC (rev 23223) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-17 15:56:02 UTC (rev 23224) @@ -4479,6 +4479,12 @@ case VPROC_GSK_START_INTERVAL: *outval = j->start_interval; break; + case VPROC_GSK_IDLE_TIMEOUT: + *outval = j->timeout; + break; + case VPROC_GSK_EXIT_TIMEOUT: + *outval = j->exit_timeout; + break; case 0: *outval = 0; break; @@ -4503,6 +4509,16 @@ j->start_interval = 0; } break; + case VPROC_GSK_IDLE_TIMEOUT: + if ((unsigned int)inval > 0) { + j->timeout = inval; + } + break; + case VPROC_GSK_EXIT_TIMEOUT: + if ((unsigned int)inval > 0) { + j->exit_timeout = inval; + } + break; case 0: break; case VPROC_GSK_IS_MANAGED: Modified: trunk/launchd/src/libvproc_private.h =================================================================== --- trunk/launchd/src/libvproc_private.h 2007-04-17 15:46:10 UTC (rev 23223) +++ trunk/launchd/src/libvproc_private.h 2007-04-17 15:56:02 UTC (rev 23224) @@ -37,6 +37,8 @@ VPROC_GSK_IS_MANAGED, VPROC_GSK_BASIC_KEEPALIVE, VPROC_GSK_START_INTERVAL, + VPROC_GSK_IDLE_TIMEOUT, + VPROC_GSK_EXIT_TIMEOUT, } vproc_gsk_t; vproc_err_t vproc_swap_integer(vproc_t vp, vproc_gsk_t key, int64_t *inval, int64_t *outval); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070417/6e410a78/attachment.html From source_changes at macosforge.org Tue Apr 17 13:40:43 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23225] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070417204043.AF0315346C1@cvs.opensource.apple.com> Revision: 23225 http://trac.macosforge.org/projects/launchd/changeset/23225 Author: zarzycki@apple.com Date: 2007-04-17 13:40:43 -0700 (Tue, 17 Apr 2007) Log Message: ----------- Loginwindow is always the exception to every rule. They're playing both in the 'Aqua' and 'Background' bootstraps and confusing launchd. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-17 15:56:02 UTC (rev 23224) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-17 20:40:43 UTC (rev 23225) @@ -263,7 +263,7 @@ #define DO_RUSAGE_SUMMATION 0 -#define AUTO_PICK_LEGACY_MACH_LABEL (const char *)(~0) +#define AUTO_PICK_LEGACY_LABEL (const char *)(~0) struct job_s { kq_callback kqjob_callback; @@ -863,7 +863,7 @@ goto out_bad; } - jr = job_new(j->mgr, AUTO_PICK_LEGACY_MACH_LABEL, NULL, argv); + jr = job_new(j->mgr, AUTO_PICK_LEGACY_LABEL, NULL, argv); free(argv); @@ -967,7 +967,6 @@ job_new_anonymous(jobmgr_t jm, pid_t anonpid) { int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, anonpid }; - char newlabel[1000]; struct kinfo_proc kp, ppid_kp; size_t len = sizeof(kp); bool shutdown_state; @@ -983,14 +982,12 @@ return NULL; } - snprintf(newlabel, sizeof(newlabel), "anonymous-%u.%s", anonpid, kp.kp_proc.p_comm); - /* A total hack: Normally, job_new() returns an error during shutdown, but anonymous jobs are special. */ if ((shutdown_state = jm->shutting_down)) { jm->shutting_down = false; } - if (jobmgr_assumes(jm, (jr = job_new(jm, newlabel, kp.kp_proc.p_comm, NULL)) != NULL)) { + if (jobmgr_assumes(jm, (jr = job_new(jm, AUTO_PICK_LEGACY_LABEL, kp.kp_proc.p_comm, NULL)) != NULL)) { total_children++; jr->anonymous = true; jr->p = anonpid; @@ -1016,7 +1013,7 @@ { const char *const *argv_tmp = argv; char auto_label[1000]; - char *bn = NULL; + const char *bn = NULL; char *co; size_t minlabel_len; int i, cc = 0; @@ -1034,19 +1031,16 @@ return NULL; } - if (label == AUTO_PICK_LEGACY_MACH_LABEL) { - bn = basename((char *)argv[0]); + if (label == AUTO_PICK_LEGACY_LABEL) { + bn = prog ? prog : basename((char *)argv[0]); /* prog for auto labels is kp.kp_kproc.p_comm */ snprintf(auto_label, sizeof(auto_label), "%s.%s", sizeof(void *) == 8 ? "0xdeadbeeffeedface" : "0xbabecafe", bn); label = auto_label; + /* This is so we can do gross things later. See NOTE_EXEC for anonymous jobs */ + minlabel_len = strlen(label) + MAXCOMLEN; + } else { + minlabel_len = strlen(label); } - /* This is so we can do gross things later. See NOTE_EXEC for anonymous jobs */ -#define MAX_ANONYMOUS_LABEL_LEN (sizeof("anonymous-100000.") + MAXCOMLEN) - minlabel_len = strlen(label); - if (minlabel_len < MAX_ANONYMOUS_LABEL_LEN) { - minlabel_len = MAX_ANONYMOUS_LABEL_LEN; - } - j = calloc(1, sizeof(struct job_s) + minlabel_len + 1); if (!jobmgr_assumes(jm, j != NULL)) { @@ -1954,7 +1948,7 @@ if (job_assumes(j, sysctl(mib, 4, &kp, &len, NULL, 0) != -1)) { char newlabel[1000]; - snprintf(newlabel, sizeof(newlabel), "anonymous-%u.%s", j->p, kp.kp_proc.p_comm); + snprintf(newlabel, sizeof(newlabel), "%p.%s", j, kp.kp_proc.p_comm); job_log(j, LOG_DEBUG, "Program changed. Updating the label to: %s", newlabel); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070417/42341fd0/attachment.html From source_changes at macosforge.org Tue Apr 17 13:41:58 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23226] tags/launchd-212/ Message-ID: <20070417204158.F0DEE5346C5@cvs.opensource.apple.com> Revision: 23226 http://trac.macosforge.org/projects/launchd/changeset/23226 Author: zarzycki@apple.com Date: 2007-04-17 13:41:58 -0700 (Tue, 17 Apr 2007) Log Message: ----------- "Tagging launchd-212 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-212/ Copied: tags/launchd-212 (from rev 23225, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070417/27cf4be8/attachment.html From source_changes at macosforge.org Wed Apr 18 09:05:53 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23227] trunk/launchd/src Message-ID: <20070418160553.14F5E535113@cvs.opensource.apple.com> Revision: 23227 http://trac.macosforge.org/projects/launchd/changeset/23227 Author: zarzycki@apple.com Date: 2007-04-18 09:05:52 -0700 (Wed, 18 Apr 2007) Log Message: ----------- Kerberos needs to be enabled only when one or more other jobs are enabled Modified Paths: -------------- trunk/launchd/src/launchd.plist.5 trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/liblaunch_public.h Modified: trunk/launchd/src/launchd.plist.5 =================================================================== --- trunk/launchd/src/launchd.plist.5 2007-04-17 20:41:58 UTC (rev 23226) +++ trunk/launchd/src/launchd.plist.5 2007-04-18 16:05:52 UTC (rev 23227) @@ -155,6 +155,11 @@ true, then the job will be kept alive as long as the path exists. If false, the job will be kept alive in the inverse condition. The intent of this feature is that two or more jobs may create semaphores in the file-system namespace. +.It Sy OtherJobEnabled +Each key in this dictionary is the label of another job. If the value of the key is +true, then this job is kept alive as long as that other job is enabled. Otherwise, +if the value is false, then this job is kept alive as long as the other job is disabled. +This feature should not be considered a substitute for the use of IPC. .El .It Sy RunAtLoad This optional key is used to control whether your job is launched once at the time the job is loaded. The default is false. Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-17 20:41:58 UTC (rev 23226) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-18 16:05:52 UTC (rev 23227) @@ -195,6 +195,8 @@ FAILED_EXIT, PATH_EXISTS, PATH_MISSING, + OTHER_JOB_ENABLED, + OTHER_JOB_DISABLED, OTHER_JOB_ACTIVE, OTHER_JOB_INACTIVE, PATH_CHANGES, @@ -209,11 +211,16 @@ char what[0]; }; +struct semaphoreitem_dict_iter_context { + job_t j; + semaphore_reason_t why_true; + semaphore_reason_t why_false; +}; + static bool semaphoreitem_new(job_t j, semaphore_reason_t why, const char *what); static void semaphoreitem_delete(job_t j, struct semaphoreitem *si); static void semaphoreitem_setup(launch_data_t obj, const char *key, void *context); -static void semaphoreitem_setup_paths(launch_data_t obj, const char *key, void *context); -static void semaphoreitem_setup_otherjobs(launch_data_t obj, const char *key, void *context); +static void semaphoreitem_setup_dict_iter(launch_data_t obj, const char *key, void *context); static void semaphoreitem_callback(job_t j, struct kevent *kev); static void semaphoreitem_watch(job_t j, struct semaphoreitem *si); static void semaphoreitem_ignore(job_t j, struct semaphoreitem *si); @@ -3239,6 +3246,14 @@ return true; } break; + case OTHER_JOB_ENABLED: + wanted_state = true; + case OTHER_JOB_DISABLED: + if ((bool)job_find(si->what) == wanted_state) { + job_log(j, LOG_DEBUG, "KeepAlive: The following job is %s: %s", wanted_state ? "enabled" : "disabled", si->what); + return true; + } + break; case OTHER_JOB_ACTIVE: wanted_state = true; case OTHER_JOB_INACTIVE: @@ -4154,46 +4169,56 @@ } void -semaphoreitem_setup_otherjobs(launch_data_t obj, const char *key, void *context) +semaphoreitem_setup_dict_iter(launch_data_t obj, const char *key, void *context) { - job_t j = context; + struct semaphoreitem_dict_iter_context *sdic = context; semaphore_reason_t why; - why = launch_data_get_bool(obj) ? OTHER_JOB_ACTIVE : OTHER_JOB_INACTIVE; + why = launch_data_get_bool(obj) ? sdic->why_true : sdic->why_false; - semaphoreitem_new(j, why, key); + semaphoreitem_new(sdic->j, why, key); } void -semaphoreitem_setup_paths(launch_data_t obj, const char *key, void *context) +semaphoreitem_setup(launch_data_t obj, const char *key, void *context) { + struct semaphoreitem_dict_iter_context sdic = { context, 0, 0 }; job_t j = context; semaphore_reason_t why; - why = launch_data_get_bool(obj) ? PATH_EXISTS : PATH_MISSING; + switch (launch_data_get_type(obj)) { + case LAUNCH_DATA_BOOL: + if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_NETWORKSTATE) == 0) { + why = launch_data_get_bool(obj) ? NETWORK_UP : NETWORK_DOWN; + semaphoreitem_new(j, why, NULL); + } else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT) == 0) { + why = launch_data_get_bool(obj) ? SUCCESSFUL_EXIT : FAILED_EXIT; + semaphoreitem_new(j, why, NULL); + j->runatload = true; + } else { + job_assumes(j, false); + } + break; + case LAUNCH_DATA_DICTIONARY: + if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_PATHSTATE) == 0) { + sdic.why_true = PATH_EXISTS; + sdic.why_false = PATH_MISSING; + } else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBACTIVE) == 0) { + sdic.why_true = OTHER_JOB_ACTIVE; + sdic.why_false = OTHER_JOB_INACTIVE; + } else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBENABLED) == 0) { + sdic.why_true = OTHER_JOB_ENABLED; + sdic.why_false = OTHER_JOB_DISABLED; + } else { + job_assumes(j, false); + break; + } - semaphoreitem_new(j, why, key); -} - -void -semaphoreitem_setup(launch_data_t obj, const char *key, void *context) -{ - job_t j = context; - semaphore_reason_t why; - - if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_NETWORKSTATE) == 0) { - why = launch_data_get_bool(obj) ? NETWORK_UP : NETWORK_DOWN; - semaphoreitem_new(j, why, NULL); - } else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT) == 0) { - why = launch_data_get_bool(obj) ? SUCCESSFUL_EXIT : FAILED_EXIT; - semaphoreitem_new(j, why, NULL); - j->runatload = true; - } else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_PATHSTATE) == 0 && - launch_data_get_type(obj) == LAUNCH_DATA_DICTIONARY) { - launch_data_dict_iterate(obj, semaphoreitem_setup_paths, j); - } else if (strcasecmp(key, LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBSTATE) == 0 && - launch_data_get_type(obj) == LAUNCH_DATA_DICTIONARY) { - launch_data_dict_iterate(obj, semaphoreitem_setup_otherjobs, j); + launch_data_dict_iterate(obj, semaphoreitem_setup_dict_iter, &sdic); + break; + default: + job_assumes(j, false); + break; } } Modified: trunk/launchd/src/liblaunch_public.h =================================================================== --- trunk/launchd/src/liblaunch_public.h 2007-04-17 20:41:58 UTC (rev 23226) +++ trunk/launchd/src/liblaunch_public.h 2007-04-18 16:05:52 UTC (rev 23227) @@ -108,7 +108,8 @@ #define LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT "SuccessfulExit" #define LAUNCH_JOBKEY_KEEPALIVE_NETWORKSTATE "NetworkState" #define LAUNCH_JOBKEY_KEEPALIVE_PATHSTATE "PathState" -#define LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBSTATE "OtherJobState" +#define LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBACTIVE "OtherJobActive" +#define LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBENABLED "OtherJobEnabled" #define LAUNCH_JOBKEY_CAL_MINUTE "Minute" #define LAUNCH_JOBKEY_CAL_HOUR "Hour" -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070418/630873f8/attachment.html From source_changes at macosforge.org Wed Apr 18 10:30:47 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23228] trunk/launchd/src Message-ID: <20070418173047.A460653520F@cvs.opensource.apple.com> Revision: 23228 http://trac.macosforge.org/projects/launchd/changeset/23228 Author: zarzycki@apple.com Date: 2007-04-18 10:30:47 -0700 (Wed, 18 Apr 2007) Log Message: ----------- need a way to have launchd safely send a signal to one of its child processes Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/libvproc.c trunk/launchd/src/libvproc_private.h trunk/launchd/src/protocol_job.defs Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-18 16:05:52 UTC (rev 23227) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-18 17:30:47 UTC (rev 23228) @@ -4456,6 +4456,33 @@ } kern_return_t +job_mig_send_signal(job_t j, name_t targetlabel, int sig) +{ + struct ldcred ldc; + job_t otherj; + + if (!launchd_assumes(j != NULL)) { + return BOOTSTRAP_NO_MEMORY; + } + + runtime_get_caller_creds(&ldc); + + if (ldc.euid != 0 && ldc.euid != getuid()) { + return BOOTSTRAP_NOT_PRIVILEGED; + } + + if (!(otherj = job_find(targetlabel))) { + return BOOTSTRAP_UNKNOWN_SERVICE; + } + + if (otherj->p) { + job_assumes(j, kill(otherj->p, sig) != -1); + } + + return 0; +} + +kern_return_t job_mig_swap_integer(job_t j, vproc_gsk_t inkey, vproc_gsk_t outkey, int64_t inval, int64_t *outval) { const char *action; Modified: trunk/launchd/src/libvproc.c =================================================================== --- trunk/launchd/src/libvproc.c 2007-04-18 16:05:52 UTC (rev 23227) +++ trunk/launchd/src/libvproc.c 2007-04-18 17:30:47 UTC (rev 23228) @@ -232,6 +232,16 @@ } vproc_err_t +_vproc_send_signal_by_label(const char *label, int sig) +{ + if (vproc_mig_send_signal(bootstrap_port, (char *)label, sig) == 0) { + return NULL; + } + + return _vproc_send_signal_by_label; +} + +vproc_err_t vproc_swap_integer(vproc_t vp __attribute__((unused)), vproc_gsk_t key, int64_t *inval, int64_t *outval) { static int64_t cached_is_managed = -1; Modified: trunk/launchd/src/libvproc_private.h =================================================================== --- trunk/launchd/src/libvproc_private.h 2007-04-18 16:05:52 UTC (rev 23227) +++ trunk/launchd/src/libvproc_private.h 2007-04-18 17:30:47 UTC (rev 23228) @@ -46,6 +46,8 @@ vproc_err_t _vproc_get_last_exit_status(int *wstatus); vproc_err_t _vproc_set_global_on_demand(bool val); +vproc_err_t _vproc_send_signal_by_label(const char *label, int sig); + void _vproc_log(int pri, const char *msg, ...) __attribute__((format(printf, 2, 3))); void _vproc_log_error(int pri, const char *msg, ...) __attribute__((format(printf, 2, 3))); Modified: trunk/launchd/src/protocol_job.defs =================================================================== --- trunk/launchd/src/protocol_job.defs 2007-04-18 16:05:52 UTC (rev 23227) +++ trunk/launchd/src/protocol_job.defs 2007-04-18 17:30:47 UTC (rev 23228) @@ -68,7 +68,10 @@ __target_pid : pid_t; __flags : uint64_t); -skip; /* last used in 10.4 */ +routine send_signal( + __bs_port : job_t; + __label : name_t; + __signal : integer_t); routine parent( __bs_port : job_t; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070418/ebd35d37/attachment.html From source_changes at macosforge.org Thu Apr 19 08:01:41 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23229] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070419150141.B10D3536931@cvs.opensource.apple.com> Revision: 23229 http://trac.macosforge.org/projects/launchd/changeset/23229 Author: zarzycki@apple.com Date: 2007-04-19 08:01:41 -0700 (Thu, 19 Apr 2007) Log Message: ----------- Prep for the arrival of NOTE_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 2007-04-18 17:30:47 UTC (rev 23228) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-19 15:01:41 UTC (rev 23229) @@ -995,12 +995,18 @@ } if (jobmgr_assumes(jm, (jr = job_new(jm, AUTO_PICK_LEGACY_LABEL, kp.kp_proc.p_comm, NULL)) != NULL)) { + u_int proc_fflags = NOTE_EXEC|NOTE_EXIT; + +#ifdef NOTE_REAP + proc_fflags |= NOTE_REAP; +#endif + total_children++; jr->anonymous = true; jr->p = anonpid; /* anonymous process reaping is messy */ LIST_INSERT_HEAD(&jm->active_jobs[ACTIVE_JOB_HASH(jr->p)], jr, pid_hash_sle); - job_assumes(jr, kevent_mod(jr->p, EVFILT_PROC, EV_ADD, NOTE_EXEC|NOTE_EXIT, 0, root_jobmgr) != -1); + job_assumes(jr, kevent_mod(jr->p, EVFILT_PROC, EV_ADD, proc_fflags, 0, root_jobmgr) != -1); if (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. Blame PID %u: %s", kp.kp_eproc.e_ppid, ppid_kp.kp_proc.p_comm); @@ -1977,9 +1983,15 @@ if (j->anonymous) { job_remove(j); } else { - job_dispatch(j, false); + j = job_dispatch(j, false); } } + +#ifdef NOTE_REAP + if (j && (fflags & NOTE_REAP)) { + job_assumes(j, j->p == 0); + } +#endif } void @@ -2102,7 +2114,12 @@ pid_t c; bool sipc = false; time_t td; + u_int proc_fflags = /* NOTE_EXEC|NOTE_FORK| */ NOTE_EXIT; +#ifdef NOTE_REAP + proc_fflags |= NOTE_REAP; +#endif + if (!job_assumes(j, j->mgr != NULL)) { return; } @@ -2201,11 +2218,10 @@ job_assumes(j, runtime_close(spair[1]) == 0); ipc_open(_fd(spair[0]), j); } - if (kevent_mod(c, EVFILT_PROC, EV_ADD, /* NOTE_EXEC|NOTE_FORK| */ NOTE_EXIT, 0, root_jobmgr ? root_jobmgr : j->mgr) == -1) { - job_log_error(j, LOG_ERR, "kevent()"); + if (job_assumes(j, kevent_mod(c, EVFILT_PROC, EV_ADD, proc_fflags, 0, root_jobmgr ? root_jobmgr : j->mgr) != -1)) { + job_ignore(j); + } else { job_reap(j); - } else { - job_ignore(j); } if (!j->stall_before_exec) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070419/4cf0562a/attachment.html From source_changes at macosforge.org Thu Apr 19 13:29:17 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23230] tags/launchd-213/ Message-ID: <20070419202917.704F9536E26@cvs.opensource.apple.com> Revision: 23230 http://trac.macosforge.org/projects/launchd/changeset/23230 Author: zarzycki@apple.com Date: 2007-04-19 13:29:17 -0700 (Thu, 19 Apr 2007) Log Message: ----------- "Tagging launchd-213 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-213/ Copied: tags/launchd-213 (from rev 23229, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070419/ca1d5d42/attachment.html From source_changes at macosforge.org Mon Apr 23 13:11:59 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23231] trunk/launchd/src/com.apple.SystemStarter.plist Message-ID: <20070423201159.ADCCE5C5388@cvs.opensource.apple.com> Revision: 23231 http://trac.macosforge.org/projects/launchd/changeset/23231 Author: zarzycki@apple.com Date: 2007-04-23 13:11:59 -0700 (Mon, 23 Apr 2007) Log Message: ----------- A dumb typo. Modified Paths: -------------- trunk/launchd/src/com.apple.SystemStarter.plist Modified: trunk/launchd/src/com.apple.SystemStarter.plist =================================================================== --- trunk/launchd/src/com.apple.SystemStarter.plist 2007-04-19 20:29:17 UTC (rev 23230) +++ trunk/launchd/src/com.apple.SystemStarter.plist 2007-04-23 20:11:59 UTC (rev 23231) @@ -8,7 +8,7 @@ /sbin/SystemStarter KeepAlive - KeepAlive + PathState /etc/rc.local -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070423/1e2072aa/attachment.html From source_changes at macosforge.org Tue Apr 24 10:56:25 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23232] trunk/launchd/src/liblaunch.c Message-ID: <20070424175625.769BB5CB9C9@cvs.opensource.apple.com> Revision: 23232 http://trac.macosforge.org/projects/launchd/changeset/23232 Author: zarzycki@apple.com Date: 2007-04-24 10:56:25 -0700 (Tue, 24 Apr 2007) Log Message: ----------- Getting ready for growth again... This is a redesign of the pack and unpack routines. We're about to mix them with MIG calls. Modified Paths: -------------- trunk/launchd/src/liblaunch.c Modified: trunk/launchd/src/liblaunch.c =================================================================== --- trunk/launchd/src/liblaunch.c 2007-04-23 20:11:59 UTC (rev 23231) +++ trunk/launchd/src/liblaunch.c 2007-04-24 17:56:25 UTC (rev 23232) @@ -37,6 +37,7 @@ #include #include #include +#include #include "libbootstrap_public.h" #include "libvproc_public.h" @@ -138,8 +139,8 @@ int fd; }; -static void launch_data_pack(launch_data_t, void **, size_t *, int **, size_t *); -static launch_data_t launch_data_unpack(launch_t, size_t *, size_t *); +static size_t launch_data_pack(launch_data_t d, void *where, size_t len, int *fd_where, size_t *fdslotsleft); +static 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); static launch_data_t launch_data_array_pop_first(launch_data_t where); static int _fd(int fd); static void launch_client_init(void); @@ -576,17 +577,17 @@ #define ROUND_TO_64BIT_WORD_SIZE(x) ((x + 7) & ~7) -void -launch_data_pack(launch_data_t d, void **where, size_t *len, int **fd_where, size_t *fdcnt) +size_t +launch_data_pack(launch_data_t d, void *where, size_t len, int *fd_where, size_t *fd_cnt) { - launch_data_t o_in_w; - size_t i; + launch_data_t o_in_w = where; + size_t i, rsz, total_data_len = sizeof(struct _launch_data); - *where = reallocf(*where, *len + sizeof(struct _launch_data)); + if (total_data_len > len) { + return 0; + } - o_in_w = *where + *len; - memset(o_in_w, 0, sizeof(struct _launch_data)); - *len += sizeof(struct _launch_data); + where += total_data_len; o_in_w->type = host2big(d->type); @@ -605,46 +606,62 @@ break; case LAUNCH_DATA_FD: o_in_w->fd = host2big(d->fd); - if (d->fd != -1) { - *fd_where = reallocf(*fd_where, (*fdcnt + 1) * sizeof(int)); - (*fd_where)[*fdcnt] = d->fd; - (*fdcnt)++; + if (!fd_where) { + return 0; + } else if (d->fd != -1) { + fd_where[*fd_cnt] = d->fd; + (*fd_cnt)++; } break; case LAUNCH_DATA_STRING: o_in_w->string_len = host2big(d->string_len); - *where = reallocf(*where, ROUND_TO_64BIT_WORD_SIZE(*len + strlen(d->string) + 1)); - memcpy(*where + *len, d->string, strlen(d->string) + 1); - *len += ROUND_TO_64BIT_WORD_SIZE(strlen(d->string) + 1); + total_data_len += ROUND_TO_64BIT_WORD_SIZE(strlen(d->string) + 1); + if (total_data_len > len) { + return 0; + } + memcpy(where, d->string, strlen(d->string) + 1); break; case LAUNCH_DATA_OPAQUE: o_in_w->opaque_size = host2big(d->opaque_size); - *where = reallocf(*where, ROUND_TO_64BIT_WORD_SIZE(*len + d->opaque_size)); - memcpy(*where + *len, d->opaque, d->opaque_size); - *len += ROUND_TO_64BIT_WORD_SIZE(d->opaque_size); + total_data_len += ROUND_TO_64BIT_WORD_SIZE(d->opaque_size); + if (total_data_len > len) { + return 0; + } + memcpy(where, d->opaque, d->opaque_size); break; case LAUNCH_DATA_DICTIONARY: case LAUNCH_DATA_ARRAY: o_in_w->_array_cnt = host2big(d->_array_cnt); - *where = reallocf(*where, *len + (d->_array_cnt * sizeof(uint64_t))); - memset(*where + *len, 0, d->_array_cnt * sizeof(uint64_t)); - *len += d->_array_cnt * sizeof(uint64_t); + total_data_len += d->_array_cnt * sizeof(uint64_t); + if (total_data_len > len) { + return 0; + } - for (i = 0; i < d->_array_cnt; i++) - launch_data_pack(d->_array[i], where, len, fd_where, fdcnt); + where += d->_array_cnt * sizeof(uint64_t); + + for (i = 0; i < d->_array_cnt; i++) { + rsz = launch_data_pack(d->_array[i], where, len - total_data_len, fd_where, fd_cnt); + if (rsz == 0) { + return 0; + } + where += rsz; + total_data_len += rsz; + } break; default: break; } + + return total_data_len; } launch_data_t -launch_data_unpack(launch_t conn, size_t *data_offset, size_t *fdoffset) +launch_data_unpack(void *data, size_t data_size, int *fds, size_t fd_cnt, size_t *data_offset, size_t *fdoffset) { - launch_data_t r = conn->recvbuf + *data_offset; + launch_data_t r = data + *data_offset; size_t i, tmpcnt; - if ((conn->recvlen - *data_offset) < sizeof(struct _launch_data)) + if ((data_size - *data_offset) < sizeof(struct _launch_data)) return NULL; *data_offset += sizeof(struct _launch_data); @@ -652,14 +669,14 @@ case LAUNCH_DATA_DICTIONARY: case LAUNCH_DATA_ARRAY: tmpcnt = big2host(r->_array_cnt); - if ((conn->recvlen - *data_offset) < (tmpcnt * sizeof(uint64_t))) { + if ((data_size - *data_offset) < (tmpcnt * sizeof(uint64_t))) { errno = EAGAIN; return NULL; } - r->_array = conn->recvbuf + *data_offset; + r->_array = data + *data_offset; *data_offset += tmpcnt * sizeof(uint64_t); for (i = 0; i < tmpcnt; i++) { - r->_array[i] = launch_data_unpack(conn, data_offset, fdoffset); + r->_array[i] = launch_data_unpack(data, data_size, fds, fd_cnt, data_offset, fdoffset); if (r->_array[i] == NULL) return NULL; } @@ -667,27 +684,27 @@ break; case LAUNCH_DATA_STRING: tmpcnt = big2host(r->string_len); - if ((conn->recvlen - *data_offset) < (tmpcnt + 1)) { + if ((data_size - *data_offset) < (tmpcnt + 1)) { errno = EAGAIN; return NULL; } - r->string = conn->recvbuf + *data_offset; + r->string = data + *data_offset; r->string_len = tmpcnt; *data_offset += ROUND_TO_64BIT_WORD_SIZE(tmpcnt + 1); break; case LAUNCH_DATA_OPAQUE: tmpcnt = big2host(r->opaque_size); - if ((conn->recvlen - *data_offset) < tmpcnt) { + if ((data_size - *data_offset) < tmpcnt) { errno = EAGAIN; return NULL; } - r->opaque = conn->recvbuf + *data_offset; + r->opaque = data + *data_offset; r->opaque_size = tmpcnt; *data_offset += ROUND_TO_64BIT_WORD_SIZE(tmpcnt); break; case LAUNCH_DATA_FD: - if (r->fd != -1) { - r->fd = _fd(conn->recvfds[*fdoffset]); + if (r->fd != -1 && fd_cnt > *fdoffset) { + r->fd = _fd(fds[*fdoffset]); *fdoffset += 1; } break; @@ -726,12 +743,30 @@ memset(&mh, 0, sizeof(mh)); + /* confirm that the next hack works */ + assert((d && lh->sendlen == 0) || (!d && lh->sendlen)); + if (d) { - uint64_t msglen = lh->sendlen; + size_t fd_slots_used = 0; + size_t good_enough_size = 10 * 1024 * 1024; + uint64_t msglen; - launch_data_pack(d, &lh->sendbuf, &lh->sendlen, &lh->sendfds, &lh->sendfdcnt); + /* hack, see the above assert to verify "correctness" */ + free(lh->sendbuf); + lh->sendbuf = malloc(good_enough_size); + free(lh->sendfds); + lh->sendfds = malloc(4 * 1024); - msglen = (lh->sendlen - msglen) + sizeof(struct launch_msg_header); + lh->sendlen = launch_data_pack(d, lh->sendbuf, good_enough_size, lh->sendfds, &fd_slots_used); + + if (lh->sendlen == 0) { + errno = ENOMEM; + return -1; + } + + lh->sendfdcnt = fd_slots_used; + + msglen = lh->sendlen + sizeof(struct launch_msg_header); /* type promotion to make the host2big() macro work right */ lmh.len = host2big(msglen); lmh.magic = host2big(LAUNCH_MSG_HEADER_MAGIC); @@ -966,7 +1001,7 @@ goto need_more_data; } - if ((rmsg = launch_data_unpack(lh, &data_offset, &fd_offset)) == NULL) { + if ((rmsg = launch_data_unpack(lh->recvbuf, lh->recvlen, lh->recvfds, lh->recvfdcnt, &data_offset, &fd_offset)) == NULL) { errno = EBADRPC; goto out_bad; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070424/00045341/attachment.html From source_changes at macosforge.org Tue Apr 24 12:48:39 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23233] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070424194839.350F85CBCEA@cvs.opensource.apple.com> Revision: 23233 http://trac.macosforge.org/projects/launchd/changeset/23233 Author: zarzycki@apple.com Date: 2007-04-24 12:48:38 -0700 (Tue, 24 Apr 2007) Log Message: ----------- More debugging. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-24 17:56:25 UTC (rev 23232) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-24 19:48:38 UTC (rev 23233) @@ -134,7 +134,7 @@ static struct machservice *machservice_new(job_t j, const char *name, mach_port_t *serviceport, bool pid_local); 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 *); +static void machservice_delete(job_t j, struct machservice *, bool port_died); static void machservice_request_notifications(struct machservice *); static mach_port_t machservice_port(struct machservice *); static job_t machservice_job(struct machservice *); @@ -734,7 +734,7 @@ limititem_delete(j, li); } while ((ms = SLIST_FIRST(&j->machservices))) { - machservice_delete(j, ms); + machservice_delete(j, ms, false); } while ((si = SLIST_FIRST(&j->semaphores))) { semaphoreitem_delete(j, si); @@ -3824,7 +3824,7 @@ if (jm == root_jobmgr) { LIST_FOREACH_SAFE(ms, &port_hash[HASH_PORT(port)], port_hash_sle, next_ms) { if (ms->port == port) { - machservice_delete(ms->job, ms); + machservice_delete(ms->job, ms, true); } } } @@ -3834,6 +3834,7 @@ } if (jm->req_port == port) { + jobmgr_log(jm, LOG_DEBUG, "Request port died: 0x%x", port); return jobmgr_shutdown(jm); } @@ -3899,7 +3900,7 @@ } void -machservice_delete(job_t j, struct machservice *ms) +machservice_delete(job_t j, struct machservice *ms, bool port_died) { if (ms->debug_on_close) { job_log(j, LOG_NOTICE, "About to enter kernel debugger because of Mach port: 0x%x", ms->port); @@ -3912,7 +3913,7 @@ job_assumes(j, launchd_mport_deallocate(ms->port) == KERN_SUCCESS); - job_log(j, LOG_INFO, "Mach service deleted: %s", ms->name); + job_log(j, LOG_INFO, "Mach service deleted%s: %s", port_died ? " (port died)" : "", ms->name); SLIST_REMOVE(&j->machservices, ms, machservice, sle); LIST_REMOVE(ms, name_hash_sle); @@ -4842,7 +4843,7 @@ return BOOTSTRAP_SERVICE_ACTIVE; } job_checkin(j); - machservice_delete(j, ms); + machservice_delete(j, ms, false); } if (serviceport != MACH_PORT_NULL) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070424/1b712e1b/attachment.html From source_changes at macosforge.org Wed Apr 25 16:40:49 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23234] trunk/launchd Message-ID: <20070425234049.D91675D7608@cvs.opensource.apple.com> Revision: 23234 http://trac.macosforge.org/projects/launchd/changeset/23234 Author: zarzycki@apple.com Date: 2007-04-25 16:40:49 -0700 (Wed, 25 Apr 2007) Log Message: ----------- _vprocmgr_move_subset_to_user should set environment variables This is the beginning of the end for launch_msg() being implemented via Unix sockets (they're good for networking, but clumbsy for local IPC). Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/liblaunch.c trunk/launchd/src/libvproc.c trunk/launchd/src/libvproc_private.h trunk/launchd/src/protocol_job.defs Added Paths: ----------- trunk/launchd/src/liblaunch_internal.h trunk/launchd/testing/vproc_swap_complex.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-24 19:48:38 UTC (rev 23233) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-25 23:40:49 UTC (rev 23234) @@ -75,6 +75,7 @@ #include "liblaunch_public.h" #include "liblaunch_private.h" +#include "liblaunch_internal.h" #include "libbootstrap_public.h" #include "libbootstrap_private.h" #include "libvproc_public.h" @@ -262,6 +263,7 @@ static void job_export_all2(jobmgr_t jm, launch_data_t where); static void jobmgr_callback(void *obj, struct kevent *kev); static void jobmgr_setup_env_from_other_jobs(jobmgr_t jm); +static void jobmgr_export_env_from_other_jobs(jobmgr_t jm, launch_data_t dict); static struct machservice *jobmgr_lookup_service(jobmgr_t jm, const char *name, bool check_parent, pid_t target_pid); static void jobmgr_logv(jobmgr_t jm, int pri, int err, const char *msg, va_list ap) __attribute__((format(printf, 4, 0))); static void jobmgr_log(jobmgr_t jm, int pri, const char *msg, ...) __attribute__((format(printf, 3, 4))); @@ -2326,12 +2328,43 @@ _exit(EXIT_FAILURE); } -void jobmgr_setup_env_from_other_jobs(jobmgr_t jm) +void +jobmgr_export_env_from_other_jobs(jobmgr_t jm, launch_data_t dict) { + launch_data_t tmp; struct envitem *ei; job_t ji; if (jm->parentmgr) { + jobmgr_export_env_from_other_jobs(jm->parentmgr, dict); + } else { + char **tmpenviron = environ; + for (; *tmpenviron; tmpenviron++) { + char envkey[1024]; + launch_data_t s = launch_data_alloc(LAUNCH_DATA_STRING); + launch_data_set_string(s, strchr(*tmpenviron, '=') + 1); + strncpy(envkey, *tmpenviron, sizeof(envkey)); + *(strchr(envkey, '=')) = '\0'; + launch_data_dict_insert(dict, s, envkey); + } + } + + LIST_FOREACH(ji, &jm->jobs, sle) { + SLIST_FOREACH(ei, &ji->global_env, sle) { + if ((tmp = launch_data_new_string(ei->value))) { + launch_data_dict_insert(dict, tmp, ei->key); + } + } + } +} + +void +jobmgr_setup_env_from_other_jobs(jobmgr_t jm) +{ + struct envitem *ei; + job_t ji; + + if (jm->parentmgr) { jobmgr_setup_env_from_other_jobs(jm->parentmgr); } @@ -4500,6 +4533,76 @@ } kern_return_t +job_mig_swap_complex(job_t j, vproc_gsk_t inkey, vproc_gsk_t outkey, + vm_offset_t inval, mach_msg_type_number_t invalCnt, + vm_offset_t *outval, mach_msg_type_number_t *outvalCnt) +{ + const char *action; + launch_data_t input_obj, output_obj; + size_t data_offset = 0; + + *outvalCnt = 10 * 1024 * 1024; + + if (!launchd_assumes(j != NULL)) { + return BOOTSTRAP_NO_MEMORY; + } + + if (inkey && outkey && !job_assumes(j, inkey == outkey)) { + return 1; + } + + if (inkey && outkey) { + action = "Swapping"; + } else if (inkey) { + action = "Setting"; + } else { + action = "Getting"; + } + + job_log(j, LOG_DEBUG, "%s key: %u", action, inkey ? inkey : outkey); + + if (invalCnt && !job_assumes(j, (input_obj = launch_data_unpack((void *)inval, invalCnt, NULL, 0, &data_offset, NULL)) != NULL)) { + return 1; + } + + switch (outkey) { + case VPROC_GSK_ENVIRONMENT: + mig_allocate(outval, *outvalCnt); + if (!job_assumes(j, *outval != 0)) { + return 1; + } + if (job_assumes(j, (output_obj = launch_data_alloc(LAUNCH_DATA_DICTIONARY)))) { + jobmgr_export_env_from_other_jobs(j->mgr, output_obj); + } + if (!job_assumes(j, launch_data_pack(output_obj, (void *)*outval, *outvalCnt, NULL, NULL) != 0)) { + mig_deallocate(*outval, *outvalCnt); + return 1; + } + break; + case 0: + *outval = 0; + *outvalCnt = 0; + break; + default: + return 1; + } + + if (invalCnt) switch (inkey) { + case VPROC_GSK_ENVIRONMENT: + job_assumes(j, false); + break; + case 0: + break; + default: + return 1; + } + + mig_deallocate(inval, invalCnt); + + return 0; +} + +kern_return_t job_mig_swap_integer(job_t j, vproc_gsk_t inkey, vproc_gsk_t outkey, int64_t inval, int64_t *outval) { const char *action; @@ -4584,10 +4687,6 @@ break; case 0: break; - case VPROC_GSK_IS_MANAGED: - case VPROC_GSK_LAST_EXIT_STATUS: - case VPROC_GSK_MGR_UID: - case VPROC_GSK_MGR_PID: default: kr = 1; break; Modified: trunk/launchd/src/liblaunch.c =================================================================== --- trunk/launchd/src/liblaunch.c 2007-04-24 19:48:38 UTC (rev 23233) +++ trunk/launchd/src/liblaunch.c 2007-04-25 23:40:49 UTC (rev 23234) @@ -21,6 +21,7 @@ #include "config.h" #include "liblaunch_public.h" #include "liblaunch_private.h" +#include "liblaunch_internal.h" #include #include @@ -139,8 +140,6 @@ int fd; }; -static size_t launch_data_pack(launch_data_t d, void *where, size_t len, int *fd_where, size_t *fdslotsleft); -static 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); static launch_data_t launch_data_array_pop_first(launch_data_t where); static int _fd(int fd); static void launch_client_init(void); Added: trunk/launchd/src/liblaunch_internal.h =================================================================== --- trunk/launchd/src/liblaunch_internal.h (rev 0) +++ trunk/launchd/src/liblaunch_internal.h 2007-04-25 23:40:49 UTC (rev 23234) @@ -0,0 +1,30 @@ +#ifndef _LAUNCH_INTERNAL_H_ +#define _LAUNCH_INTERNAL_H_ +/* + * Copyright (c) 2007 Apple Computer, Inc. All rights reserved. + * + * @APPLE_APACHE_LICENSE_HEADER_START@ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @APPLE_APACHE_LICENSE_HEADER_END@ + */ + +#pragma GCC visibility push(default) + +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); + +#pragma GCC visibility pop + +#endif Modified: trunk/launchd/src/libvproc.c =================================================================== --- trunk/launchd/src/libvproc.c 2007-04-24 19:48:38 UTC (rev 23233) +++ trunk/launchd/src/libvproc.c 2007-04-25 23:40:49 UTC (rev 23234) @@ -33,6 +33,7 @@ #include "liblaunch_public.h" #include "liblaunch_private.h" +#include "liblaunch_internal.h" #include "protocol_vproc.h" @@ -57,9 +58,16 @@ return vproc_mig_post_fork_ping(bootstrap_port, mach_task_self()) == 0 ? NULL : _vproc_post_fork_ping; } +static void +setup_env_hack(const launch_data_t obj, const char *key, void *context __attribute__((unused))) +{ + setenv(key, launch_data_get_string(obj), 1); +} + vproc_err_t _vprocmgr_move_subset_to_user(uid_t target_user, char *session_type) { + launch_data_t output_obj; kern_return_t kr = 1; mach_port_t puc = 0, which_port = bootstrap_port; bool is_bkgd = (strcmp(session_type, VPROCMGR_SESSION_BACKGROUND) == 0); @@ -84,7 +92,18 @@ cached_pid = -1; - return kr == 0 ? NULL : (vproc_err_t)_vprocmgr_move_subset_to_user; + if (kr) { + return (vproc_err_t)_vprocmgr_move_subset_to_user; + } + + if (vproc_swap_complex(NULL, VPROC_GSK_ENVIRONMENT, NULL, &output_obj) == NULL) { + if (launch_data_get_type(output_obj) == LAUNCH_DATA_DICTIONARY) { + launch_data_dict_iterate(output_obj, setup_env_hack, NULL); + launch_data_free(output_obj); + } + } + + return NULL; } @@ -304,6 +323,55 @@ return parent_port; } +vproc_err_t +vproc_swap_complex(vproc_t vp __attribute__((unused)), vproc_gsk_t key, launch_data_t inval, launch_data_t *outval) +{ + size_t data_offset = 0, good_enough_size = 10*1024*1024; + mach_msg_type_number_t indata_cnt = 0, outdata_cnt; + vm_offset_t indata = 0, outdata = 0; + launch_data_t out_obj; + void *rval = vproc_swap_complex; + void *buf = NULL; + + if (inval) { + if (!(buf = malloc(good_enough_size))) { + goto out; + } + + if ((indata_cnt = launch_data_pack(inval, buf, good_enough_size, NULL, NULL)) == 0) { + goto out; + } + + indata = (vm_offset_t)buf; + } + + if (vproc_mig_swap_complex(bootstrap_port, inval ? key : 0, outval ? key : 0, indata, indata_cnt, &outdata, &outdata_cnt) != 0) { + goto out; + } + + if (outval) { + if (!(out_obj = launch_data_unpack((void *)outdata, outdata_cnt, NULL, 0, &data_offset, NULL))) { + goto out; + } + + if (!(*outval = launch_data_copy(out_obj))) { + goto out; + } + } + + rval = NULL; +out: + if (buf) { + free(buf); + } + + if (outdata) { + mig_deallocate(outdata, outdata_cnt); + } + + return rval; +} + void * reboot2(uint64_t flags) { Modified: trunk/launchd/src/libvproc_private.h =================================================================== --- trunk/launchd/src/libvproc_private.h 2007-04-24 19:48:38 UTC (rev 23233) +++ trunk/launchd/src/libvproc_private.h 2007-04-25 23:40:49 UTC (rev 23234) @@ -24,6 +24,7 @@ #include #include #include +#include __BEGIN_DECLS @@ -39,9 +40,11 @@ VPROC_GSK_START_INTERVAL, VPROC_GSK_IDLE_TIMEOUT, VPROC_GSK_EXIT_TIMEOUT, + VPROC_GSK_ENVIRONMENT, } vproc_gsk_t; vproc_err_t vproc_swap_integer(vproc_t vp, vproc_gsk_t key, int64_t *inval, int64_t *outval); +vproc_err_t vproc_swap_complex(vproc_t vp, vproc_gsk_t key, launch_data_t inval, launch_data_t *outval); vproc_err_t _vproc_get_last_exit_status(int *wstatus); vproc_err_t _vproc_set_global_on_demand(bool val); Modified: trunk/launchd/src/protocol_job.defs =================================================================== --- trunk/launchd/src/protocol_job.defs 2007-04-24 19:48:38 UTC (rev 23233) +++ trunk/launchd/src/protocol_job.defs 2007-04-25 23:40:49 UTC (rev 23234) @@ -156,3 +156,10 @@ __bs_port : job_t; __target_port : mach_port_t; __sessiontype : name_t); + +routine swap_complex( + __bs_port : job_t; + __inkey : vproc_gsk_t; + __outkey : vproc_gsk_t; + __inval : pointer_t; + out __outval : pointer_t, dealloc); Added: trunk/launchd/testing/vproc_swap_complex.c =================================================================== --- trunk/launchd/testing/vproc_swap_complex.c (rev 0) +++ trunk/launchd/testing/vproc_swap_complex.c 2007-04-25 23:40:49 UTC (rev 23234) @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include +#include +#include + +static void my_callback(const launch_data_t obj, const char *key, void *context); + +int main(void) +{ + launch_data_t output_obj = NULL; + + assert(vproc_swap_complex(NULL, VPROC_GSK_ENVIRONMENT, NULL, &output_obj) == 0); + + assert(launch_data_get_type(output_obj) == LAUNCH_DATA_DICTIONARY); + + launch_data_dict_iterate(output_obj, my_callback, stdout); + + return 0; +} + +void +my_callback(const launch_data_t obj, const char *key, void *context) +{ + fprintf(context, "%s == %s\n", key, launch_data_get_string(obj)); +} -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070425/43e7c758/attachment.html From source_changes at macosforge.org Thu Apr 26 16:28:44 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23235] trunk/launchd/src Message-ID: <20070426232844.902555D89CB@cvs.opensource.apple.com> Revision: 23235 http://trac.macosforge.org/projects/launchd/changeset/23235 Author: zarzycki@apple.com Date: 2007-04-26 16:28:44 -0700 (Thu, 26 Apr 2007) Log Message: ----------- launchctl export does not print all variables There are other changes included in this diff. Please note that more IPC is migrating to MIG. Modified Paths: -------------- trunk/launchd/src/launchctl.c trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_unix_ipc.c trunk/launchd/src/liblaunch.c trunk/launchd/src/liblaunch_private.h trunk/launchd/src/liblaunch_public.h trunk/launchd/src/libvproc_private.h Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-04-25 23:40:49 UTC (rev 23234) +++ trunk/launchd/src/launchctl.c 2007-04-26 23:28:44 UTC (rev 23235) @@ -402,9 +402,9 @@ } int -getenv_and_export_cmd(int argc, char *const argv[] __attribute__((unused))) +getenv_and_export_cmd(int argc, char *const argv[]) { - launch_data_t resp, msg; + launch_data_t resp; bool is_csh = false; char *k; @@ -420,21 +420,18 @@ k = argv[1]; - msg = launch_data_new_string(LAUNCH_KEY_GETUSERENVIRONMENT); - - resp = launch_msg(msg); - launch_data_free(msg); - - if (resp) { + if (vproc_swap_complex(NULL, VPROC_GSK_ENVIRONMENT, NULL, &resp) == NULL) { if (!strcmp(argv[0], "export")) { launch_data_dict_iterate(resp, print_launchd_env, &is_csh); } else { launch_data_dict_iterate(resp, print_key_value, k); } launch_data_free(resp); + return 0; } else { - fprintf(stderr, "launch_msg(\"" LAUNCH_KEY_GETUSERENVIRONMENT "\"): %s\n", strerror(errno)); + return 1; } + return 0; } @@ -1932,7 +1929,7 @@ } int -list_cmd(int argc, char *const argv[]) +list_cmd(int argc, char *const argv[] __attribute__((unused))) { launch_data_t resp, msg; int r = 0; @@ -1943,8 +1940,13 @@ } else if (argc == 2) { msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY); launch_data_dict_insert(msg, launch_data_new_string(argv[1]), LAUNCH_KEY_GETJOB); + } else if (vproc_swap_complex(NULL, VPROC_GSK_ALLJOBS, NULL, &resp) == NULL) { + fprintf(stdout, "PID\tStatus\tLabel\n"); + launch_data_dict_iterate(resp, print_jobs, NULL); + launch_data_free(resp); + return 0; } else { - msg = launch_data_new_string(LAUNCH_KEY_GETJOBS); + return 1; } resp = launch_msg(msg); @@ -1954,12 +1956,7 @@ fprintf(stderr, "launch_msg(): %s\n", strerror(errno)); return 1; } else if (launch_data_get_type(resp) == LAUNCH_DATA_DICTIONARY) { - if (argc == 1) { - fprintf(stdout, "PID\tStatus\tLabel\n"); - launch_data_dict_iterate(resp, print_jobs, NULL); - } else { - print_obj(resp, NULL, NULL); - } + print_obj(resp, NULL, NULL); } else { fprintf(stderr, "%s %s returned unknown response\n", getprogname(), argv[0]); r = 1; @@ -2022,10 +2019,9 @@ int logupdate_cmd(int argc, char *const argv[]) { - launch_data_t resp, msg; - int e, i, j, r = 0, m = 0; + int64_t inval, outval; + int i, j, m = 0; bool badargs = false, maskmode = false, onlymode = false, levelmode = false; - const char *whichcmd = LAUNCH_KEY_SETLOGMASK; static const struct { const char *name; int level; @@ -2080,9 +2076,7 @@ } if (j == logtblsz) badargs = true; - } else if (argc == 1) { - whichcmd = LAUNCH_KEY_GETLOGMASK; - } else { + } else if (argc != 1) { badargs = true; } @@ -2091,41 +2085,21 @@ return 1; } - if (whichcmd == LAUNCH_KEY_SETLOGMASK) { - msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY); - launch_data_dict_insert(msg, launch_data_new_integer(m), whichcmd); - } else { - msg = launch_data_new_string(whichcmd); - } + inval = m; - resp = launch_msg(msg); - launch_data_free(msg); - - if (resp == NULL) { - fprintf(stderr, "launch_msg(): %s\n", strerror(errno)); - return 1; - } else if (launch_data_get_type(resp) == LAUNCH_DATA_ERRNO) { - if ((e = launch_data_get_errno(resp))) { - fprintf(stderr, "%s %s error: %s\n", getprogname(), argv[0], strerror(e)); - r = 1; - } - } else if (launch_data_get_type(resp) == LAUNCH_DATA_INTEGER) { - if (whichcmd == LAUNCH_KEY_GETLOGMASK) { - m = launch_data_get_integer(resp); + if (vproc_swap_integer(NULL, VPROC_GSK_GLOBAL_LOG_MASK, argc != 1 ? &inval : NULL, &outval) == NULL) { + if (argc == 1) { for (j = 0; j < logtblsz; j++) { - if (m & LOG_MASK(logtbl[j].level)) + if (outval & LOG_MASK(logtbl[j].level)) { fprintf(stdout, "%s ", logtbl[j].name); + } } fprintf(stdout, "\n"); } + return 0; } else { - fprintf(stderr, "%s %s returned unknown response\n", getprogname(), argv[0]); - r = 1; + return 1; } - - launch_data_free(resp); - - return r; } static const struct { @@ -2292,11 +2266,10 @@ int umask_cmd(int argc, char *const argv[]) { - launch_data_t resp, msg; bool badargs = false; char *endptr; long m = 0; - int r = 0; + int64_t inval, outval; if (argc == 2) { m = strtol(argv[1], &endptr, 8); @@ -2309,32 +2282,16 @@ return 1; } + inval = m; - if (argc == 1) { - msg = launch_data_new_string(LAUNCH_KEY_GETUMASK); + if (vproc_swap_integer(NULL, VPROC_GSK_GLOBAL_UMASK, argc == 2 ? &inval : NULL, &outval) == NULL) { + if (argc == 1) { + fprintf(stdout, "%o\n", (unsigned int)outval); + } + return 0; } else { - msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY); - launch_data_dict_insert(msg, launch_data_new_integer(m), LAUNCH_KEY_SETUMASK); - } - resp = launch_msg(msg); - launch_data_free(msg); - - if (resp == NULL) { - fprintf(stderr, "launch_msg(): %s\n", strerror(errno)); return 1; - } else if (launch_data_get_type(resp) == LAUNCH_DATA_STRING) { - fprintf(stderr, "%s %s error: %s\n", getprogname(), argv[0], launch_data_get_string(resp)); - r = 1; - } else if (launch_data_get_type(resp) != LAUNCH_DATA_INTEGER) { - fprintf(stderr, "%s %s returned unknown response\n", getprogname(), argv[0]); - r = 1; - } else if (argc == 1) { - fprintf(stdout, "%o\n", (unsigned int)launch_data_get_integer(resp)); } - - launch_data_free(resp); - - return r; } int Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-25 23:40:49 UTC (rev 23234) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-26 23:28:44 UTC (rev 23235) @@ -4540,9 +4540,8 @@ const char *action; launch_data_t input_obj, output_obj; size_t data_offset = 0; + size_t packed_size; - *outvalCnt = 10 * 1024 * 1024; - if (!launchd_assumes(j != NULL)) { return BOOTSTRAP_NO_MEMORY; } @@ -4561,30 +4560,45 @@ job_log(j, LOG_DEBUG, "%s key: %u", action, inkey ? inkey : outkey); - if (invalCnt && !job_assumes(j, (input_obj = launch_data_unpack((void *)inval, invalCnt, NULL, 0, &data_offset, NULL)) != NULL)) { + *outvalCnt = 20 * 1024 * 1024; + mig_allocate(outval, *outvalCnt); + if (!job_assumes(j, *outval != 0)) { return 1; } + if (invalCnt && !job_assumes(j, (input_obj = launch_data_unpack((void *)inval, invalCnt, NULL, 0, &data_offset, NULL)) != NULL)) { + goto out_bad; + } + switch (outkey) { case VPROC_GSK_ENVIRONMENT: - mig_allocate(outval, *outvalCnt); - if (!job_assumes(j, *outval != 0)) { - return 1; + if (!job_assumes(j, (output_obj = launch_data_alloc(LAUNCH_DATA_DICTIONARY)))) { + goto out_bad; } - if (job_assumes(j, (output_obj = launch_data_alloc(LAUNCH_DATA_DICTIONARY)))) { - jobmgr_export_env_from_other_jobs(j->mgr, output_obj); - } + jobmgr_export_env_from_other_jobs(j->mgr, output_obj); if (!job_assumes(j, launch_data_pack(output_obj, (void *)*outval, *outvalCnt, NULL, NULL) != 0)) { - mig_deallocate(*outval, *outvalCnt); - return 1; + goto out_bad; } + launch_data_free(output_obj); break; + case VPROC_GSK_ALLJOBS: + if (!job_assumes(j, (output_obj = job_export_all()) != NULL)) { + goto out_bad; + } + ipc_revoke_fds(output_obj); + 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; *outvalCnt = 0; break; default: - return 1; + goto out_bad; } if (invalCnt) switch (inkey) { @@ -4594,12 +4608,18 @@ case 0: break; default: - return 1; + goto out_bad; } mig_deallocate(inval, invalCnt); return 0; + +out_bad: + if (*outval) { + mig_deallocate(*outval, *outvalCnt); + } + return 1; } kern_return_t @@ -4607,6 +4627,7 @@ { const char *action; kern_return_t kr = 0; + int oldmask; if (!launchd_assumes(j != NULL)) { return BOOTSTRAP_NO_MEMORY; @@ -4651,6 +4672,16 @@ case VPROC_GSK_EXIT_TIMEOUT: *outval = j->exit_timeout; break; + case VPROC_GSK_GLOBAL_LOG_MASK: + oldmask = runtime_setlogmask(LOG_UPTO(LOG_DEBUG)); + *outval = oldmask; + runtime_setlogmask(oldmask); + break; + case VPROC_GSK_GLOBAL_UMASK: + oldmask = umask(0); + *outval = oldmask; + umask(oldmask); + break; case 0: *outval = 0; break; @@ -4685,6 +4716,12 @@ j->exit_timeout = inval; } break; + case VPROC_GSK_GLOBAL_LOG_MASK: + runtime_setlogmask(inval); + break; + case VPROC_GSK_GLOBAL_UMASK: + umask(inval); + break; case 0: break; default: Modified: trunk/launchd/src/launchd_unix_ipc.c =================================================================== --- trunk/launchd/src/launchd_unix_ipc.c 2007-04-25 23:40:49 UTC (rev 23234) +++ trunk/launchd/src/launchd_unix_ipc.c 2007-04-26 23:28:44 UTC (rev 23235) @@ -361,25 +361,6 @@ ipc_revoke_fds(resp); } else if (!strcmp(cmd, LAUNCH_KEY_GETRESOURCELIMITS)) { resp = adjust_rlimits(NULL); - } else if (!strcmp(cmd, LAUNCH_KEY_GETUSERENVIRONMENT)) { - char **tmpenviron = environ; - resp = launch_data_alloc(LAUNCH_DATA_DICTIONARY); - for (; *tmpenviron; tmpenviron++) { - char envkey[1024]; - launch_data_t s = launch_data_alloc(LAUNCH_DATA_STRING); - launch_data_set_string(s, strchr(*tmpenviron, '=') + 1); - strncpy(envkey, *tmpenviron, sizeof(envkey)); - *(strchr(envkey, '=')) = '\0'; - launch_data_dict_insert(resp, s, envkey); - } - } else if (!strcmp(cmd, LAUNCH_KEY_GETLOGMASK)) { - int oldmask = setlogmask(LOG_UPTO(LOG_DEBUG)); - resp = launch_data_new_integer(oldmask); - setlogmask(oldmask); - } else if (!strcmp(cmd, LAUNCH_KEY_GETUMASK)) { - mode_t oldmask = umask(0); - resp = launch_data_new_integer(oldmask); - umask(oldmask); } else if (!strcmp(cmd, LAUNCH_KEY_GETRUSAGESELF)) { struct rusage rusage; getrusage(RUSAGE_SELF, &rusage); @@ -434,16 +415,6 @@ resp = job_export(j); ipc_revoke_fds(resp); } - } else if (!strcmp(cmd, LAUNCH_KEY_GETJOBWITHHANDLES)) { - if ((j = job_find(launch_data_get_string(data))) == NULL) { - resp = launch_data_new_errno(errno); - } else { - resp = job_export(j); - } - } else if (!strcmp(cmd, LAUNCH_KEY_SETLOGMASK)) { - resp = launch_data_new_integer(setlogmask(launch_data_get_integer(data))); - } else if (!strcmp(cmd, LAUNCH_KEY_SETUMASK)) { - resp = launch_data_new_integer(umask(launch_data_get_integer(data))); } else if (!strcmp(cmd, LAUNCH_KEY_BATCHCONTROL)) { batch_job_enable(launch_data_get_bool(data), rmc->c); resp = launch_data_new_errno(0); Modified: trunk/launchd/src/liblaunch.c =================================================================== --- trunk/launchd/src/liblaunch.c 2007-04-25 23:40:49 UTC (rev 23234) +++ trunk/launchd/src/liblaunch.c 2007-04-26 23:28:44 UTC (rev 23235) @@ -605,9 +605,7 @@ break; case LAUNCH_DATA_FD: o_in_w->fd = host2big(d->fd); - if (!fd_where) { - return 0; - } else if (d->fd != -1) { + if (fd_where && d->fd != -1) { fd_where[*fd_cnt] = d->fd; (*fd_cnt)++; } @@ -897,6 +895,12 @@ { launch_data_t resp = NULL; + if (d && (launch_data_get_type(d) == LAUNCH_DATA_STRING) + && (strcmp(launch_data_get_string(d), LAUNCH_KEY_GETJOBS) == 0) + && vproc_swap_complex(NULL, VPROC_GSK_ALLJOBS, NULL, &resp) == NULL) { + return resp; + } + pthread_once(&_lc_once, launch_client_init); if (!_lc) { Modified: trunk/launchd/src/liblaunch_private.h =================================================================== --- trunk/launchd/src/liblaunch_private.h 2007-04-25 23:40:49 UTC (rev 23234) +++ trunk/launchd/src/liblaunch_private.h 2007-04-26 23:28:44 UTC (rev 23235) @@ -29,17 +29,12 @@ __BEGIN_DECLS -#define LAUNCH_KEY_GETUSERENVIRONMENT "GetUserEnvironment" #define LAUNCH_KEY_SETUSERENVIRONMENT "SetUserEnvironment" #define LAUNCH_KEY_UNSETUSERENVIRONMENT "UnsetUserEnvironment" #define LAUNCH_KEY_SHUTDOWN "Shutdown" #define LAUNCH_KEY_SINGLEUSER "SingleUser" #define LAUNCH_KEY_GETRESOURCELIMITS "GetResourceLimits" #define LAUNCH_KEY_SETRESOURCELIMITS "SetResourceLimits" -#define LAUNCH_KEY_SETLOGMASK "SetLogMask" -#define LAUNCH_KEY_GETLOGMASK "GetLogMask" -#define LAUNCH_KEY_SETUMASK "SetUmask" -#define LAUNCH_KEY_GETUMASK "GetUmask" #define LAUNCH_KEY_GETRUSAGESELF "GetResourceUsageSelf" #define LAUNCH_KEY_GETRUSAGECHILDREN "GetResourceUsageChildren" Modified: trunk/launchd/src/liblaunch_public.h =================================================================== --- trunk/launchd/src/liblaunch_public.h 2007-04-25 23:40:49 UTC (rev 23234) +++ trunk/launchd/src/liblaunch_public.h 2007-04-26 23:28:44 UTC (rev 23235) @@ -49,7 +49,6 @@ #define LAUNCH_KEY_STARTJOB "StartJob" #define LAUNCH_KEY_STOPJOB "StopJob" #define LAUNCH_KEY_GETJOB "GetJob" -#define LAUNCH_KEY_GETJOBWITHHANDLES "GetJobWithHandles" #define LAUNCH_KEY_GETJOBS "GetJobs" #define LAUNCH_KEY_CHECKIN "CheckIn" Modified: trunk/launchd/src/libvproc_private.h =================================================================== --- trunk/launchd/src/libvproc_private.h 2007-04-25 23:40:49 UTC (rev 23234) +++ trunk/launchd/src/libvproc_private.h 2007-04-26 23:28:44 UTC (rev 23235) @@ -41,6 +41,9 @@ VPROC_GSK_IDLE_TIMEOUT, VPROC_GSK_EXIT_TIMEOUT, VPROC_GSK_ENVIRONMENT, + VPROC_GSK_ALLJOBS, + VPROC_GSK_GLOBAL_LOG_MASK, + VPROC_GSK_GLOBAL_UMASK, } vproc_gsk_t; vproc_err_t vproc_swap_integer(vproc_t vp, vproc_gsk_t key, int64_t *inval, int64_t *outval); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070426/1e360942/attachment.html From source_changes at macosforge.org Thu Apr 26 16:35:46 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23236] trunk/launchd/src/launchctl.c Message-ID: <20070426233546.D08785D89E7@cvs.opensource.apple.com> Revision: 23236 http://trac.macosforge.org/projects/launchd/changeset/23236 Author: zarzycki@apple.com Date: 2007-04-26 16:35:46 -0700 (Thu, 26 Apr 2007) Log Message: ----------- 9A422: launchd is passing \n to sysctl Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-04-26 23:28:44 UTC (rev 23235) +++ trunk/launchd/src/launchctl.c 2007-04-26 23:35:46 UTC (rev 23236) @@ -2849,6 +2849,10 @@ tmpstr[ln_len] = 0; val = tmpstr; + if (val[ln_len - 1] == '\n' || val[ln_len - 1] == '\r') { + val[ln_len - 1] = '\0'; + } + while (*val && isspace(*val)) val++; if (*val == '\0' || *val == '#') { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070426/51a2cbda/attachment.html From source_changes at macosforge.org Fri Apr 27 09:40:56 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23237] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070427164056.9A2F35D9938@cvs.opensource.apple.com> Revision: 23237 http://trac.macosforge.org/projects/launchd/changeset/23237 Author: zarzycki@apple.com Date: 2007-04-27 09:40:55 -0700 (Fri, 27 Apr 2007) Log Message: ----------- Clean up. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-26 23:35:46 UTC (rev 23236) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-27 16:40:55 UTC (rev 23237) @@ -5240,23 +5240,14 @@ } for (l2l_i = 0; l2l_i < l2l_name_cnt; l2l_i++) { + job_t j_for_service = jobmgr_find_by_pid(jmr, l2l_pids[l2l_i], true); struct machservice *ms; - job_t j_for_service; - LIST_FOREACH(j_for_service, &jmr->jobs, sle) { - if (j_for_service->p == l2l_pids[l2l_i]) { - break; + if (jobmgr_assumes(jmr, j_for_service != NULL)) { + if ((ms = machservice_new(j_for_service, l2l_names[l2l_i], &l2l_ports[l2l_i], false))) { + machservice_request_notifications(ms); } } - - if (!j_for_service) { - j_for_service = job_new_anonymous(jmr, l2l_pids[l2l_i]); - jobmgr_assumes(jmr, j_for_service != NULL); - } - - if ((ms = machservice_new(j_for_service, l2l_names[l2l_i], &l2l_ports[l2l_i], false))) { - machservice_request_notifications(ms); - } } kr = 0; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070427/b7d931e6/attachment.html From source_changes at macosforge.org Fri Apr 27 09:52:28 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23238] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070427165228.D9A765D994C@cvs.opensource.apple.com> Revision: 23238 http://trac.macosforge.org/projects/launchd/changeset/23238 Author: zarzycki@apple.com Date: 2007-04-27 09:52:28 -0700 (Fri, 27 Apr 2007) Log Message: ----------- More sanity checks and clean up. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-27 16:40:55 UTC (rev 23237) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-27 16:52:28 UTC (rev 23238) @@ -5191,8 +5191,8 @@ pid_array_t l2l_pids = NULL; mach_port_array_t l2l_ports = NULL; mach_port_t reqport, rcvright; - kern_return_t kr; - jobmgr_t jmr; + kern_return_t kr = 1; + jobmgr_t jmr = NULL; job_t j2; if (getuid() == 0) { @@ -5243,11 +5243,13 @@ job_t j_for_service = jobmgr_find_by_pid(jmr, l2l_pids[l2l_i], true); struct machservice *ms; - if (jobmgr_assumes(jmr, j_for_service != NULL)) { - if ((ms = machservice_new(j_for_service, l2l_names[l2l_i], &l2l_ports[l2l_i], false))) { - machservice_request_notifications(ms); - } + if (!jobmgr_assumes(jmr, j_for_service != NULL)) { + goto out; } + + if ((ms = machservice_new(j_for_service, l2l_names[l2l_i], &l2l_ports[l2l_i], false))) { + machservice_request_notifications(ms); + } } kr = 0; @@ -5262,6 +5264,9 @@ if (l2l_pids) { mig_deallocate((vm_address_t)l2l_pids, l2l_pid_cnt * sizeof(l2l_pids[0])); } + if (kr && jmr) { + jobmgr_shutdown(jmr); + } return kr; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070427/8961cfbd/attachment.html From source_changes at macosforge.org Fri Apr 27 10:11:50 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23239] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070427171150.DFE245D99FD@cvs.opensource.apple.com> Revision: 23239 http://trac.macosforge.org/projects/launchd/changeset/23239 Author: zarzycki@apple.com Date: 2007-04-27 10:11:50 -0700 (Fri, 27 Apr 2007) Log Message: ----------- More clean up and sanity checking. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-27 16:52:28 UTC (rev 23238) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-27 17:11:50 UTC (rev 23239) @@ -5206,35 +5206,29 @@ j = j2; jobmgr_log(j->mgr, LOG_DEBUG, "Renaming to: %s", session_type); strcpy(j->mgr->name, session_type); - job_assumes(j, launchd_mport_deallocate(target_subset) == KERN_SUCCESS); bootstrapper = job_new(j->mgr, thelabel, NULL, bootstrap_tool); if (job_assumes(j, bootstrapper != NULL)) { job_dispatch(bootstrapper, true); } - return 0; + + kr = 0; + goto out; } if (getpid() != 1 && job_mig_intran(target_subset)) { - job_assumes(j, launchd_mport_deallocate(target_subset) == KERN_SUCCESS); - return 0; + kr = 0; + goto out; } - kr = _vproc_grab_subset(target_subset, &reqport, - &rcvright, &l2l_names, &l2l_name_cnt, - &l2l_pids, &l2l_pid_cnt, - &l2l_ports, &l2l_port_cnt); - - if (job_assumes(j, kr == 0)) { - job_assumes(j, launchd_mport_deallocate(target_subset) == KERN_SUCCESS); - } else { + if (!job_assumes(j, (kr = _vproc_grab_subset(target_subset, &reqport, &rcvright, &l2l_names, &l2l_name_cnt, &l2l_pids, &l2l_pid_cnt, &l2l_ports, &l2l_port_cnt)) == 0)) { goto out; } launchd_assert(l2l_name_cnt == l2l_port_cnt); launchd_assert(l2l_name_cnt == l2l_pid_cnt); - if ((jmr = jobmgr_new(j->mgr, reqport, rcvright, false, session_type)) == NULL) { + if (!job_assumes(j, (jmr = jobmgr_new(j->mgr, reqport, rcvright, false, session_type)) != NULL)) { kr = BOOTSTRAP_NO_MEMORY; goto out; } @@ -5244,6 +5238,7 @@ struct machservice *ms; if (!jobmgr_assumes(jmr, j_for_service != NULL)) { + kr = BOOTSTRAP_NO_MEMORY; goto out; } @@ -5264,7 +5259,10 @@ if (l2l_pids) { mig_deallocate((vm_address_t)l2l_pids, l2l_pid_cnt * sizeof(l2l_pids[0])); } - if (kr && jmr) { + + if (kr == 0) { + job_assumes(j, launchd_mport_deallocate(target_subset) == KERN_SUCCESS); + } else if (jmr) { jobmgr_shutdown(jmr); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070427/9ef5c10b/attachment.html From source_changes at macosforge.org Fri Apr 27 11:49:01 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23240] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070427184901.D55615D9B82@cvs.opensource.apple.com> Revision: 23240 http://trac.macosforge.org/projects/launchd/changeset/23240 Author: zarzycki@apple.com Date: 2007-04-27 11:49:01 -0700 (Fri, 27 Apr 2007) Log Message: ----------- Help people debug configuration errors. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-04-27 17:11:50 UTC (rev 23239) +++ trunk/launchd/src/launchd_core_logic.c 2007-04-27 18:49:01 UTC (rev 23240) @@ -1237,6 +1237,7 @@ } break; default: + job_log(j, LOG_WARNING, "Unknown key for boolean: %s", key); break; } } @@ -1315,6 +1316,7 @@ } break; default: + job_log(j, LOG_WARNING, "Unknown key for string: %s", key); break; } @@ -1383,6 +1385,7 @@ } break; default: + job_log(j, LOG_WARNING, "Unknown key for integer: %s", key); break; } } @@ -1449,6 +1452,7 @@ } break; default: + job_log(j, LOG_WARNING, "Unknown key for dictionary: %s", key); break; } } @@ -1509,6 +1513,7 @@ } break; default: + job_log(j, LOG_WARNING, "Unknown key for array: %s", key); break; } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070427/038d7f9b/attachment.html From source_changes at macosforge.org Fri Apr 27 13:29:41 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:47 2007 Subject: [launchd-changes] [23241] tags/launchd-214/ Message-ID: <20070427202941.1AC025D9D59@cvs.opensource.apple.com> Revision: 23241 http://trac.macosforge.org/projects/launchd/changeset/23241 Author: zarzycki@apple.com Date: 2007-04-27 13:29:41 -0700 (Fri, 27 Apr 2007) Log Message: ----------- "Tagging launchd-214 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-214/ Copied: tags/launchd-214 (from rev 23240, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070427/1d3aad10/attachment.html