From source_changes at macosforge.org Tue Jan 2 10:32:46 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [22998] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070102183246.6A75C47266E@cvs.opensource.apple.com> Revision: 22998 http://trac.macosforge.org/projects/launchd/changeset/22998 Author: zarzycki@apple.com Date: 2007-01-02 10:32:46 -0800 (Tue, 02 Jan 2007) Log Message: ----------- Fix a Mach port leak. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2006-12-22 19:44:52 UTC (rev 22997) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-02 18:32:46 UTC (rev 22998) @@ -613,10 +613,9 @@ job_assumes(j, launchd_mport_close_recv(j->j_port) == KERN_SUCCESS); } -#if 0 - if (j->wait_reply_port) { + if (!job_assumes(j, j->wait_reply_port == MACH_PORT_NULL)) { + job_assumes(j, launchd_mport_deallocate(j->wait_reply_port) == KERN_SUCCESS); } -#endif while ((sg = SLIST_FIRST(&j->sockets))) { socketgroup_delete(j, sg); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070102/30edf367/attachment.html From source_changes at macosforge.org Tue Jan 2 14:35:13 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [22999] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070102223513.C8B3F47289A@cvs.opensource.apple.com> Revision: 22999 http://trac.macosforge.org/projects/launchd/changeset/22999 Author: zarzycki@apple.com Date: 2007-01-02 14:35:13 -0800 (Tue, 02 Jan 2007) Log Message: ----------- reflect stderr of launchd jobs to ASL ("console logging") 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-01-02 18:32:46 UTC (rev 22998) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-02 22:35:13 UTC (rev 22999) @@ -257,6 +257,7 @@ int argc; int last_exit_status; int forkfd; + int log_redirect_fd; int nice; int timeout; int stdout_err_fd; @@ -609,6 +610,10 @@ job_assumes(j, close(j->forkfd) != -1); } + if (j->log_redirect_fd) { + job_assumes(j, close(j->log_redirect_fd) != -1); + } + if (j->j_port) { job_assumes(j, launchd_mport_close_recv(j->j_port) == KERN_SUCCESS); } @@ -1586,6 +1591,11 @@ job_log(j, LOG_DEBUG, "Reaping"); + if (j->log_redirect_fd) { + job_assumes(j, close(j->log_redirect_fd) != -1); + j->log_redirect_fd = 0; + } + if (j->forkfd) { job_assumes(j, close(j->forkfd) != -1); j->forkfd = 0; @@ -1705,7 +1715,30 @@ watchpath_callback(j, kev); break; case EVFILT_READ: - socketgroup_callback(j, kev); + if (kev->ident == (uintptr_t)j->log_redirect_fd) { + char buf[4001]; + ssize_t rsz; + + rsz = read(j->log_redirect_fd, buf, sizeof(buf) - 1); + + if (rsz == 0) { + job_assumes(j, close(j->log_redirect_fd) != -1); + j->log_redirect_fd = 0; + } else if (job_assumes(j, rsz != -1)) { + buf[rsz] = '\0'; + switch (buf[0]) { + case '\n': + case '\r': + case '\0': + break; + default: + job_log(j, LOG_NOTICE, "Standard Out/Error: %s", buf); + break; + } + } + } else { + socketgroup_callback(j, kev); + } break; case EVFILT_MACHPORT: job_dispatch(j, true); @@ -1721,6 +1754,7 @@ { int spair[2]; int execspair[2]; + int oepair[2]; char nbuf[64]; pid_t c; bool sipc = false; @@ -1759,11 +1793,17 @@ j->checkedin = false; if (sipc) { - socketpair(AF_UNIX, SOCK_STREAM, 0, spair); + job_assumes(j, socketpair(AF_UNIX, SOCK_STREAM, 0, spair) != -1); } - socketpair(AF_UNIX, SOCK_STREAM, 0, execspair); + job_assumes(j, socketpair(AF_UNIX, SOCK_STREAM, 0, execspair) != -1); + if (job_assumes(j, pipe(oepair) != -1)) { + j->log_redirect_fd = _fd(oepair[0]); + job_assumes(j, fcntl(j->log_redirect_fd, F_SETFL, O_NONBLOCK) != -1); + job_assumes(j, kevent_mod(j->log_redirect_fd, EVFILT_READ, EV_ADD, 0, 0, j) != -1); + } + time(&j->start_time); switch (c = jobmgr_fork(j->mgr)) { @@ -1777,6 +1817,9 @@ } break; case 0: + job_assumes(j, dup2(oepair[1], STDOUT_FILENO) != -1); + job_assumes(j, dup2(oepair[1], STDERR_FILENO) != -1); + job_assumes(j, close(oepair[1]) != -1); job_assumes(j, close(execspair[0]) == 0); /* wait for our parent to say they've attached a kevent to us */ read(_fd(execspair[1]), &c, sizeof(c)); @@ -1797,6 +1840,7 @@ job_start_child(j); break; default: + job_assumes(j, close(oepair[1]) != -1); j->p = c; j->forkfd = _fd(execspair[0]); job_assumes(j, close(execspair[1]) == 0); @@ -2544,8 +2588,9 @@ job_log(j, LOG_DEBUG, "Ignoring Sockets:%s", buf); - for (i = 0; i < sg->fd_cnt; i++) + for (i = 0; i < sg->fd_cnt; i++) { job_assumes(j, kevent_mod(sg->fds[i], EVFILT_READ, EV_DELETE, 0, 0, NULL) != -1); + } } void @@ -2563,8 +2608,9 @@ job_log(j, LOG_DEBUG, "Watching sockets:%s", buf); - for (i = 0; i < sg->fd_cnt; i++) + for (i = 0; i < sg->fd_cnt; i++) { job_assumes(j, kevent_mod(sg->fds[i], EVFILT_READ, EV_ADD, 0, 0, j) != -1); + } } void -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070102/607266f1/attachment.html From source_changes at macosforge.org Thu Jan 4 12:05:30 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23000] tags/launchd-185/ Message-ID: <20070104200530.664294749A7@cvs.opensource.apple.com> Revision: 23000 http://trac.macosforge.org/projects/launchd/changeset/23000 Author: zarzycki@apple.com Date: 2007-01-04 12:05:30 -0800 (Thu, 04 Jan 2007) Log Message: ----------- "Tagging launchd-185 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-185/ Copied: tags/launchd-185 (from rev 22999, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070104/cc682619/attachment.html From source_changes at macosforge.org Thu Jan 4 12:17:27 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23001] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070104201727.5F29E4749C2@cvs.opensource.apple.com> Revision: 23001 http://trac.macosforge.org/projects/launchd/changeset/23001 Author: zarzycki@apple.com Date: 2007-01-04 12:17:27 -0800 (Thu, 04 Jan 2007) Log Message: ----------- Prepare for growth. 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-01-04 20:05:30 UTC (rev 23000) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-04 20:17:27 UTC (rev 23001) @@ -306,6 +306,7 @@ static pid_t job_get_pid(job_t j); static jobmgr_t job_get_bs(job_t j); static void job_uncork_fork(job_t j); +static void job_log_stdouterr(job_t j); static void job_logv(job_t j, int pri, int err, const char *msg, va_list ap); static void job_log(job_t j, int pri, const char *msg, ...) __attribute__((format(printf, 3, 4))); static void job_log_error(job_t j, int pri, const char *msg, ...) __attribute__((format(printf, 3, 4))); @@ -1683,6 +1684,31 @@ } void +job_log_stdouterr(job_t j) +{ + char buf[4001]; + ssize_t rsz; + + rsz = read(j->log_redirect_fd, buf, sizeof(buf) - 1); + + if (rsz == 0) { + job_assumes(j, close(j->log_redirect_fd) != -1); + j->log_redirect_fd = 0; + } else if (job_assumes(j, rsz != -1)) { + buf[rsz] = '\0'; + switch (buf[0]) { + case '\n': + case '\r': + case '\0': + break; + default: + job_log(j, LOG_NOTICE, "Standard Out/Error: %s", buf); + break; + } + } +} + +void job_callback(void *obj, struct kevent *kev) { job_t j = obj; @@ -1716,26 +1742,7 @@ break; case EVFILT_READ: if (kev->ident == (uintptr_t)j->log_redirect_fd) { - char buf[4001]; - ssize_t rsz; - - rsz = read(j->log_redirect_fd, buf, sizeof(buf) - 1); - - if (rsz == 0) { - job_assumes(j, close(j->log_redirect_fd) != -1); - j->log_redirect_fd = 0; - } else if (job_assumes(j, rsz != -1)) { - buf[rsz] = '\0'; - switch (buf[0]) { - case '\n': - case '\r': - case '\0': - break; - default: - job_log(j, LOG_NOTICE, "Standard Out/Error: %s", buf); - break; - } - } + job_log_stdouterr(j); } else { socketgroup_callback(j, kev); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070104/7ae8f4a4/attachment.html From source_changes at macosforge.org Thu Jan 4 15:15:47 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23002] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070104231547.2A673474EBA@cvs.opensource.apple.com> Revision: 23002 http://trac.macosforge.org/projects/launchd/changeset/23002 Author: zarzycki@apple.com Date: 2007-01-04 15:15:46 -0800 (Thu, 04 Jan 2007) Log Message: ----------- launchd needs to do better buffer management for job stdout/stderr 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-01-04 20:17:27 UTC (rev 23001) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-04 23:15:46 UTC (rev 23002) @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -1686,26 +1687,31 @@ void job_log_stdouterr(job_t j) { - char buf[4001]; + char *msg, *bufindex, *buf = malloc(BIG_PIPE_SIZE + 1); ssize_t rsz; - rsz = read(j->log_redirect_fd, buf, sizeof(buf) - 1); + if (!job_assumes(j, buf != NULL)) { + return; + } + bufindex = buf; + + rsz = read(j->log_redirect_fd, buf, BIG_PIPE_SIZE); + if (rsz == 0) { job_assumes(j, close(j->log_redirect_fd) != -1); j->log_redirect_fd = 0; } else if (job_assumes(j, rsz != -1)) { buf[rsz] = '\0'; - switch (buf[0]) { - case '\n': - case '\r': - case '\0': - break; - default: - job_log(j, LOG_NOTICE, "Standard Out/Error: %s", buf); - break; + + while ((msg = strsep(&bufindex, "\n\r"))) { + if (msg[0]) { + job_log(j, LOG_NOTICE, "Standard Out/Error: %s", msg); + } } } + + free(buf); } void -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070104/336a7e1c/attachment.html From source_changes at macosforge.org Thu Jan 4 15:29:06 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23003] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070104232906.BC584474F03@cvs.opensource.apple.com> Revision: 23003 http://trac.macosforge.org/projects/launchd/changeset/23003 Author: zarzycki@apple.com Date: 2007-01-04 15:29:06 -0800 (Thu, 04 Jan 2007) Log Message: ----------- It would be good to log that the job closed its end of the pipe pair. 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-01-04 23:15:46 UTC (rev 23002) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-04 23:29:06 UTC (rev 23003) @@ -1699,6 +1699,7 @@ rsz = read(j->log_redirect_fd, buf, BIG_PIPE_SIZE); if (rsz == 0) { + job_log(j, LOG_DEBUG, "Standard out/error pipe closed"); job_assumes(j, close(j->log_redirect_fd) != -1); j->log_redirect_fd = 0; } else if (job_assumes(j, rsz != -1)) { @@ -1706,7 +1707,7 @@ while ((msg = strsep(&bufindex, "\n\r"))) { if (msg[0]) { - job_log(j, LOG_NOTICE, "Standard Out/Error: %s", msg); + job_log(j, LOG_NOTICE, "Standard out/error: %s", msg); } } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070104/bd7a62ea/attachment.html From source_changes at macosforge.org Thu Jan 4 16:11:52 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23004] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070105001152.5DD134750A1@cvs.opensource.apple.com> Revision: 23004 http://trac.macosforge.org/projects/launchd/changeset/23004 Author: zarzycki@apple.com Date: 2007-01-04 16:11:52 -0800 (Thu, 04 Jan 2007) Log Message: ----------- Leopard9A328: /SourceCache/xnu/xnu-1005/bsd/kern/kern_exit.c:249 "init died\nState at Last Exc 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-01-04 23:29:06 UTC (rev 23003) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-05 00:11:52 UTC (rev 23004) @@ -903,6 +903,11 @@ int i, cc = 0; job_t j; + if (shutdown_in_progress) { + errno = EINVAL; + return NULL; + } + if (prog == NULL && argv == NULL) { errno = EINVAL; return NULL; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070104/55418604/attachment.html From source_changes at macosforge.org Thu Jan 4 17:14:24 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23005] trunk/launchd/src Message-ID: <20070105011424.1A228475458@cvs.opensource.apple.com> Revision: 23005 http://trac.macosforge.org/projects/launchd/changeset/23005 Author: zarzycki@apple.com Date: 2007-01-04 17:14:23 -0800 (Thu, 04 Jan 2007) Log Message: ----------- Unable to drag & drop, copy & paste when logged in as root. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/libvproc.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-01-05 00:11:52 UTC (rev 23004) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-05 01:14:23 UTC (rev 23005) @@ -4195,6 +4195,13 @@ kern_return_t kr; jobmgr_t jmr; + if (getuid() == 0) { + j = job_mig_intran2(root_jobmgr, target_subset); + job_assumes(j, launchd_mport_deallocate(target_subset) == KERN_SUCCESS); + strcpy(j->mgr->name, "Aqua"); + return 0; + } + kr = _vproc_grab_subset(target_subset, &reqport, &rcvright, &l2l_names, &l2l_name_cnt, &l2l_ports, &l2l_port_cnt); Modified: trunk/launchd/src/libvproc.c =================================================================== --- trunk/launchd/src/libvproc.c 2007-01-05 00:11:52 UTC (rev 23004) +++ trunk/launchd/src/libvproc.c 2007-01-05 01:14:23 UTC (rev 23005) @@ -29,6 +29,7 @@ #include #include #include +#include #include "liblaunch_public.h" #include "liblaunch_private.h" @@ -47,10 +48,15 @@ _vproc_move_subset_to_user(void) { kern_return_t kr = 1; - mach_port_t puc; + mach_port_t puc = 0, which_port = bootstrap_port; - if (vproc_mig_lookup_per_user_context(bootstrap_port, 0, &puc) == 0) { - kr = vproc_mig_move_subset_to_user(puc, bootstrap_port); + if ((getuid() || geteuid()) && vproc_mig_lookup_per_user_context(bootstrap_port, 0, &puc) == 0) { + which_port = puc; + } + + kr = vproc_mig_move_subset_to_user(which_port, bootstrap_port); + + if (puc) { mach_port_deallocate(mach_task_self(), puc); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070104/182d4499/attachment.html From source_changes at macosforge.org Fri Jan 5 14:03:52 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23006] tags/launchd-186/ Message-ID: <20070105220352.9CC96476B76@cvs.opensource.apple.com> Revision: 23006 http://trac.macosforge.org/projects/launchd/changeset/23006 Author: zarzycki@apple.com Date: 2007-01-05 14:03:52 -0800 (Fri, 05 Jan 2007) Log Message: ----------- "Tagging launchd-186 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-186/ Copied: tags/launchd-186 (from rev 23005, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070105/d552df15/attachment.html From source_changes at macosforge.org Wed Jan 10 10:38:28 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23007] trunk/launchd/src Message-ID: <20070110183828.D7F9847D39B@cvs.opensource.apple.com> Revision: 23007 http://trac.macosforge.org/projects/launchd/changeset/23007 Author: zarzycki@apple.com Date: 2007-01-10 10:38:28 -0800 (Wed, 10 Jan 2007) Log Message: ----------- support loading jobs into the loginwindow context Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/liblaunch.c trunk/launchd/src/liblaunch_private.h trunk/launchd/src/libvproc.c trunk/launchd/src/libvproc_internal.h Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-01-05 22:03:52 UTC (rev 23006) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-10 18:38:28 UTC (rev 23007) @@ -298,7 +298,7 @@ static void job_setup_fd(job_t j, int target_fd, const char *path, int flags); static void job_postfork_become_user(job_t j); static void job_force_sampletool(job_t j); -static void job_reparent_to_aqua_hack(job_t j); +static void job_reparent_hack(job_t j, const char *where); static void job_callback(void *obj, struct kevent *kev); static launch_data_t job_export2(job_t j, bool subjobs); static job_t job_new_spawn(job_t j, const char *label, const char *path, const char *workingdir, const char *const *argv, const char *const *env, mode_t *u_mask, bool w4d); @@ -840,7 +840,7 @@ return NULL; } - job_reparent_to_aqua_hack(jr); + job_reparent_hack(jr, "Aqua"); if (getpid() == 1) { struct ldcred ldc; @@ -1115,7 +1115,9 @@ return; } else if (strcasecmp(key, LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE) == 0) { if (strcmp(value, "Aqua") == 0) { - job_reparent_to_aqua_hack(j); + job_reparent_hack(j, "Aqua"); + } else if (strcmp(value, "LoginWindow") == 0) { + job_reparent_hack(j, "LoginWindow"); } return; } @@ -3179,7 +3181,7 @@ return NULL; } - jmr = calloc(1, sizeof(struct jobmgr_s) + strlen("100000") + 1); + jmr = calloc(1, sizeof(struct jobmgr_s) + strlen("LoginWindow") + 1); if (jmr == NULL) { return NULL; @@ -3832,6 +3834,9 @@ } switch (key) { + case GSK_LOGINWINDOW_CONTEXT: + strcpy(j->mgr->name, "LoginWindow"); + break; case GLOBAL_ON_DEMAND: kr = job_set_global_on_demand(j, (bool)val) ? 0 : 1; break; @@ -4166,14 +4171,13 @@ return BOOTSTRAP_NO_MEMORY; } - void -job_reparent_to_aqua_hack(job_t j) +job_reparent_hack(job_t j, const char *where) { jobmgr_t jmi = NULL; SLIST_FOREACH(jmi, &root_jobmgr->submgrs, sle) { - if (strcmp(jmi->name, "Aqua") == 0) { + if (strcmp(jmi->name, where) == 0) { break; } } Modified: trunk/launchd/src/liblaunch.c =================================================================== --- trunk/launchd/src/liblaunch.c 2007-01-05 22:03:52 UTC (rev 23006) +++ trunk/launchd/src/liblaunch.c 2007-01-10 18:38:28 UTC (rev 23007) @@ -1186,6 +1186,30 @@ _exit(EXIT_FAILURE); } +void +load_launchd_jobs_at_loginwindow_prompt(int flags, ...) +{ + char *largv[] = { "/bin/launchctl", "load", "-S", "LoginWindow", "-D", "all", "/etc/mach_init_per_login_session.d", NULL }; + int wstatus; + pid_t p; + + if (flags & LOAD_ONLY_SAFEMODE_LAUNCHAGENTS) { + largv[5] = "system"; + } + + if (__vproc_tag_loginwindow_context()) { + return; + } + + if ((p = fexecv_as_user("root", 0, 0, largv)) == -1) { + return; + } + + if (waitpid(p, &wstatus, 0) != p) { + return; + } +} + pid_t create_and_switch_to_per_session_launchd(const char *login, int flags, ...) { Modified: trunk/launchd/src/liblaunch_private.h =================================================================== --- trunk/launchd/src/liblaunch_private.h 2007-01-05 22:03:52 UTC (rev 23006) +++ trunk/launchd/src/liblaunch_private.h 2007-01-10 18:38:28 UTC (rev 23007) @@ -73,14 +73,18 @@ * * After this call, the task's bootstrap port is set to the per session launchd. * - * This returns the PID on of the per session launchd, and -1 on failure. - * - * If launchd terminates, loginwindow should exit. - * If loginwindow terminates, launchd will exit. + * This returns 1 on success (it used to return otherwise), and -1 on failure. */ #define LOAD_ONLY_SAFEMODE_LAUNCHAGENTS 1 pid_t create_and_switch_to_per_session_launchd(const char *login, int flags, ...); +/* Also for LoginWindow. + * + * This is will load jobs at the LoginWindow prompt. + */ +void load_launchd_jobs_at_loginwindow_prompt(int flags, ...); + + /* batch jobs will be implicity re-enabled when the last application who * disabled them exits. * Modified: trunk/launchd/src/libvproc.c =================================================================== --- trunk/launchd/src/libvproc.c 2007-01-05 22:03:52 UTC (rev 23006) +++ trunk/launchd/src/libvproc.c 2007-01-10 18:38:28 UTC (rev 23007) @@ -208,6 +208,16 @@ } vproc_err_t +__vproc_tag_loginwindow_context(void) +{ + if (vproc_mig_set_integer(bootstrap_port, GSK_LOGINWINDOW_CONTEXT, 1) == 0) { + return NULL; + } + + return (vproc_err_t)__vproc_tag_loginwindow_context; +} + +vproc_err_t _vproc_set_global_on_demand(bool state) { int64_t val = state ? ~0 : 0; Modified: trunk/launchd/src/libvproc_internal.h =================================================================== --- trunk/launchd/src/libvproc_internal.h 2007-01-05 22:03:52 UTC (rev 23006) +++ trunk/launchd/src/libvproc_internal.h 2007-01-10 18:38:28 UTC (rev 23007) @@ -31,6 +31,7 @@ typedef enum { LAST_EXIT_STATUS = 1, GLOBAL_ON_DEMAND, + GSK_LOGINWINDOW_CONTEXT, } get_set_int_key_t; #ifdef protocol_vproc_MSG_COUNT @@ -52,6 +53,8 @@ name_array_t *service_names, mach_msg_type_number_t *service_namesCnt, mach_port_array_t *ports, mach_msg_type_number_t *portCnt); +vproc_err_t __vproc_tag_loginwindow_context(void); + kern_return_t _vprocmgr_getsocket(name_t); vproc_err_t _vproc_move_subset_to_user(void); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070110/4cf06d7d/attachment.html From source_changes at macosforge.org Wed Jan 10 13:58:22 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23008] tags/launchd-187/ Message-ID: <20070110215822.9F5E647D78B@cvs.opensource.apple.com> Revision: 23008 http://trac.macosforge.org/projects/launchd/changeset/23008 Author: zarzycki@apple.com Date: 2007-01-10 13:58:22 -0800 (Wed, 10 Jan 2007) Log Message: ----------- "Tagging launchd-187 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-187/ Copied: tags/launchd-187 (from rev 23007, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070110/c21c2d83/attachment.html From source_changes at macosforge.org Thu Jan 11 16:33:20 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23009] trunk/launchd/src Message-ID: <20070112003320.DB03547F109@cvs.opensource.apple.com> Revision: 23009 http://trac.macosforge.org/projects/launchd/changeset/23009 Author: zarzycki@apple.com Date: 2007-01-11 16:33:20 -0800 (Thu, 11 Jan 2007) Log Message: ----------- KeepAlive with PathState should monitor for file creation state change Modified Paths: -------------- trunk/launchd/src/launchd.c trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_core_logic.h Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-01-10 21:58:22 UTC (rev 23008) +++ trunk/launchd/src/launchd.c 2007-01-12 00:33:20 UTC (rev 23009) @@ -645,7 +645,7 @@ if (new_networking_state != network_up) { network_up = new_networking_state; - jobmgr_dispatch_all_other_semaphores(root_jobmgr, NULL); + jobmgr_dispatch_all_semaphores(root_jobmgr); } } Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-01-10 21:58:22 UTC (rev 23008) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-12 00:33:20 UTC (rev 23009) @@ -104,8 +104,10 @@ static void machservice_setup_options(launch_data_t obj, const char *key, void *context); static void machservice_resetport(job_t j, struct machservice *ms); static struct machservice *machservice_new(job_t j, const char *name, mach_port_t *serviceport); +static void machservice_ignore(job_t j, struct machservice *ms); +static void machservice_watch(job_t j, struct machservice *ms); static void machservice_delete(struct machservice *); -static void machservice_watch(struct machservice *); +static void machservice_request_notifications(struct machservice *); static mach_port_t machservice_port(struct machservice *); static job_t machservice_job(struct machservice *); static bool machservice_hidden(struct machservice *); @@ -127,19 +129,6 @@ static void socketgroup_callback(job_t j, struct kevent *kev); static void socketgroup_setup(launch_data_t obj, const char *key, void *context); -struct watchpath { - SLIST_ENTRY(watchpath) sle; - int fd; - unsigned int is_qdir:1, __junk:31; - char name[0]; -}; - -static bool watchpath_new(job_t j, const char *name, bool qdir); -static void watchpath_delete(job_t j, struct watchpath *wp); -static void watchpath_watch(job_t j, struct watchpath *wp); -static void watchpath_ignore(job_t j, struct watchpath *wp); -static void watchpath_callback(job_t j, struct kevent *kev); - struct calendarinterval { SLIST_ENTRY(calendarinterval) sle; struct tm when; @@ -178,12 +167,15 @@ FAILED_EXIT, PATH_EXISTS, PATH_MISSING, + PATH_CHANGES, + DIR_NOT_EMPTY, // FILESYSTEMTYPE_IS_MOUNTED, /* for nfsiod, but maybe others */ } semaphore_reason_t; struct semaphoreitem { SLIST_ENTRY(semaphoreitem) sle; semaphore_reason_t why; + int fd; char what[0]; }; @@ -191,6 +183,9 @@ 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_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); struct jobmgr_s { SLIST_ENTRY(jobmgr_s) sle; @@ -231,7 +226,6 @@ kq_callback kqjob_callback; SLIST_ENTRY(job_s) sle; SLIST_HEAD(, socketgroup) sockets; - SLIST_HEAD(, watchpath) vnodes; SLIST_HEAD(, calendarinterval) cal_intervals; SLIST_HEAD(, envitem) global_env; SLIST_HEAD(, envitem) env; @@ -356,9 +350,9 @@ void job_ignore(job_t j) { + struct semaphoreitem *si; struct socketgroup *sg; struct machservice *ms; - struct watchpath *wp; if (j->currently_ignored) { return; @@ -370,12 +364,12 @@ socketgroup_ignore(j, sg); } - SLIST_FOREACH(wp, &j->vnodes, sle) { - watchpath_ignore(j, wp); + SLIST_FOREACH(ms, &j->machservices, sle) { + machservice_ignore(j, ms); } - SLIST_FOREACH(ms, &j->machservices, sle) { - job_assumes(j, runtime_remove_mport(ms->port) == KERN_SUCCESS); + SLIST_FOREACH(si, &j->semaphores, sle) { + semaphoreitem_ignore(j, si); } } @@ -385,7 +379,6 @@ struct semaphoreitem *si; struct socketgroup *sg; struct machservice *ms; - struct watchpath *wp; if (!j->currently_ignored) { return; @@ -397,19 +390,12 @@ socketgroup_watch(j, sg); } - SLIST_FOREACH(wp, &j->vnodes, sle) { - watchpath_watch(j, wp); - } - SLIST_FOREACH(ms, &j->machservices, sle) { - job_assumes(j, runtime_add_mport(ms->port, NULL, 0) == KERN_SUCCESS); + machservice_watch(j, ms); } SLIST_FOREACH(si, &j->semaphores, sle) { - if (si->why == PATH_EXISTS || si->why == PATH_MISSING) { - /* Maybe another job has the inverse path based semaphore as this job */ - jobmgr_dispatch_all_other_semaphores(root_jobmgr, j); - } + semaphoreitem_watch(j, si); } } @@ -583,7 +569,6 @@ { struct calendarinterval *ci; struct socketgroup *sg; - struct watchpath *wp; struct limititem *li; struct envitem *ei; struct machservice *ms; @@ -627,9 +612,6 @@ while ((sg = SLIST_FIRST(&j->sockets))) { socketgroup_delete(j, sg); } - while ((wp = SLIST_FIRST(&j->vnodes))) { - watchpath_delete(j, wp); - } while ((ci = SLIST_FIRST(&j->cal_intervals))) { calendarinterval_delete(j, ci); } @@ -1299,9 +1281,6 @@ void job_import_array(job_t j, const char *key, launch_data_t value) { - bool is_q_dir = false; - bool is_wp = false; - switch (key[0]) { case 'l': case 'L': @@ -1314,14 +1293,24 @@ case 'q': case 'Q': if (strcasecmp(key, LAUNCH_JOBKEY_QUEUEDIRECTORIES) == 0) { - is_q_dir = true; - is_wp = true; + size_t i, qd_cnt = launch_data_array_get_count(value); + const char *thepath; + for (i = 0; i < qd_cnt; i++) { + thepath = launch_data_get_string(launch_data_array_get_index(value, i)); + semaphoreitem_new(j, DIR_NOT_EMPTY, thepath); + } + } break; case 'w': case 'W': if (strcasecmp(key, LAUNCH_JOBKEY_WATCHPATHS) == 0) { - is_wp = true; + size_t i, wp_cnt = launch_data_array_get_count(value); + const char *thepath; + for (i = 0; i < wp_cnt; i++) { + thepath = launch_data_get_string(launch_data_array_get_index(value, i)); + semaphoreitem_new(j, PATH_CHANGES, thepath); + } } break; case 'b': @@ -1341,15 +1330,6 @@ default: break; } - - if (is_wp) { - size_t i, wp_cnt = launch_data_array_get_count(value); - const char *thepath; - for (i = 0; i < wp_cnt; i++) { - thepath = launch_data_get_string(launch_data_array_get_index(value, i)); - watchpath_new(j, thepath, is_q_dir); - } - } } void @@ -1752,7 +1732,7 @@ } break; case EVFILT_VNODE: - watchpath_callback(j, kev); + semaphoreitem_callback(j, kev); break; case EVFILT_READ: if (kev->ident == (uintptr_t)j->log_redirect_fd) { @@ -2365,111 +2345,82 @@ } } -bool -watchpath_new(job_t j, const char *name, bool qdir) -{ - struct watchpath *wp = calloc(1, sizeof(struct watchpath) + strlen(name) + 1); - - if (!job_assumes(j, wp != NULL)) { - return false; - } - - wp->is_qdir = qdir; - - wp->fd = -1; /* watchpath_watch() will open this */ - - strcpy(wp->name, name); - - SLIST_INSERT_HEAD(&j->vnodes, wp, sle); - - return true; -} - -void -watchpath_delete(job_t j, struct watchpath *wp) -{ - if (wp->fd != -1) { - job_assumes(j, close(wp->fd) != -1); - } - - SLIST_REMOVE(&j->vnodes, wp, watchpath, sle); - - free(wp); -} - void -watchpath_ignore(job_t j, struct watchpath *wp) +semaphoreitem_ignore(job_t j, struct semaphoreitem *si) { - if (wp->fd != -1) { - job_log(j, LOG_DEBUG, "Ignoring Vnode: %d", wp->fd); - job_assumes(j, kevent_mod(wp->fd, EVFILT_VNODE, EV_DELETE, 0, 0, NULL) != -1); + if (si->fd != -1) { + job_log(j, LOG_DEBUG, "Ignoring Vnode: %d", si->fd); + job_assumes(j, kevent_mod(si->fd, EVFILT_VNODE, EV_DELETE, 0, 0, NULL) != -1); } } void -watchpath_watch(job_t j, struct watchpath *wp) +semaphoreitem_watch(job_t j, struct semaphoreitem *si) { - int fflags = NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK; - int qdir_file_cnt; - - if (!wp->is_qdir) { - fflags |= NOTE_DELETE|NOTE_RENAME|NOTE_REVOKE; + char parentdir_path[PATH_MAX], *which_path = si->what; + int fflags = 0; + + switch (si->why) { + case PATH_EXISTS: + fflags = NOTE_DELETE|NOTE_RENAME|NOTE_REVOKE|NOTE_EXTEND|NOTE_WRITE; + strlcpy(parentdir_path, dirname(si->what), sizeof(parentdir_path)); + which_path = parentdir_path; + break; + case PATH_MISSING: + fflags = NOTE_DELETE|NOTE_RENAME; + break; + case PATH_CHANGES: + fflags = NOTE_DELETE|NOTE_RENAME|NOTE_REVOKE|NOTE_EXTEND|NOTE_WRITE|NOTE_ATTRIB|NOTE_LINK; + break; + default: + return; } - if (wp->fd == -1) { - wp->fd = _fd(open(wp->name, O_EVTONLY|O_NOCTTY|O_NOFOLLOW)); + if (si->fd == -1) { + si->fd = _fd(open(which_path, O_EVTONLY|O_NOCTTY)); } - if (wp->fd == -1) { - return job_log_error(j, LOG_ERR, "Watchpath monitoring failed on \"%s\"", wp->name); + if (si->fd == -1) { + return job_log_error(j, LOG_ERR, "Watchpath monitoring failed on \"%s\"", which_path); } - job_log(j, LOG_DEBUG, "Watching Vnode: %d", wp->fd); - job_assumes(j, kevent_mod(wp->fd, EVFILT_VNODE, EV_ADD|EV_CLEAR, fflags, 0, j) != -1); - - if (!wp->is_qdir) { - return; - } - - if (-1 == (qdir_file_cnt = dir_has_files(j, wp->name))) { - job_log_error(j, LOG_ERR, "dir_has_files(\"%s\", ...)", wp->name); - } else if (qdir_file_cnt > 0) { - job_dispatch(j, true); - } + 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); } void -watchpath_callback(job_t j, struct kevent *kev) +semaphoreitem_callback(job_t j, struct kevent *kev) { - struct watchpath *wp; - int dir_file_cnt; + struct semaphoreitem *si; - SLIST_FOREACH(wp, &j->vnodes, sle) { - if (wp->fd == (int)kev->ident) { + SLIST_FOREACH(si, &j->semaphores, sle) { + switch (si->why) { + case PATH_CHANGES: + case PATH_EXISTS: + case PATH_MISSING: break; + default: + continue; } + + if (si->fd == (int)kev->ident) { + break; + } } - job_assumes(j, wp != NULL); + if (!job_assumes(j, si != NULL)) { + return; + } if ((NOTE_DELETE|NOTE_RENAME|NOTE_REVOKE) & kev->fflags) { - job_log(j, LOG_DEBUG, "Path invalidated: %s", wp->name); - job_assumes(j, close(wp->fd) == 0); - wp->fd = -1; /* this will get fixed in watchpath_watch() */ - } else if (!wp->is_qdir) { - job_log(j, LOG_DEBUG, "Watch path modified: %s", wp->name); - } else { - job_log(j, LOG_DEBUG, "Queue directory modified: %s", wp->name); - - if (-1 == (dir_file_cnt = dir_has_files(j, wp->name))) { - job_log_error(j, LOG_ERR, "dir_has_files(\"%s\", ...)", wp->name); - } else if (0 == dir_file_cnt) { - job_log(j, LOG_DEBUG, "Spurious wake up, directory is empty again: %s", wp->name); - return; - } + job_log(j, LOG_DEBUG, "Path invalidated: %s", si->what); + job_assumes(j, close(si->fd) == 0); + si->fd = -1; /* this will get fixed in semaphoreitem_watch() */ } - job_dispatch(j, true); + job_log(j, LOG_DEBUG, "Watch path modified: %s", si->what); + + job_dispatch(j, si->why == PATH_CHANGES ? true : false); } bool @@ -2818,6 +2769,8 @@ SLIST_FOREACH(si, &j->semaphores, sle) { bool wanted_state = false; + int qdir_file_cnt; + switch (si->why) { case NETWORK_UP: wanted_state = true; @@ -2843,9 +2796,22 @@ if ((bool)(stat(si->what, &sb) == 0) == wanted_state) { job_log(j, LOG_DEBUG, "KeepAlive check: job configured to run while the following path %s: %s", wanted_state ? "exists" : "is missing", si->what); + if (si->fd != -1) { + job_assumes(j, close(si->fd) == 0); + si->fd = -1; + } return true; } break; + case PATH_CHANGES: + break; + case DIR_NOT_EMPTY: + if (-1 == (qdir_file_cnt = dir_has_files(j, si->what))) { + job_log_error(j, LOG_ERR, "dir_has_files(\"%s\", ...)", si->what); + } else if (qdir_file_cnt > 0) { + return true; + } + break; } } @@ -2928,6 +2894,18 @@ } void +machservice_watch(job_t j, struct machservice *ms) +{ + job_assumes(j, runtime_add_mport(ms->port, NULL, 0) == KERN_SUCCESS); +} + +void +machservice_ignore(job_t j, struct machservice *ms) +{ + job_assumes(j, runtime_remove_mport(ms->port) == KERN_SUCCESS); +} + +void machservice_resetport(job_t j, struct machservice *ms) { job_assumes(j, launchd_mport_close_recv(ms->port) == KERN_SUCCESS); @@ -3347,7 +3325,7 @@ } void -machservice_watch(struct machservice *ms) +machservice_request_notifications(struct machservice *ms) { mach_msg_id_t which = MACH_NOTIFY_DEAD_NAME; @@ -3521,6 +3499,7 @@ return false; } + si->fd = -1; si->why = why; if (what) { @@ -3533,11 +3512,15 @@ } void -semaphoreitem_delete(job_t j, struct semaphoreitem *ri) +semaphoreitem_delete(job_t j, struct semaphoreitem *si) { - SLIST_REMOVE(&j->semaphores, ri, semaphoreitem, sle); + SLIST_REMOVE(&j->semaphores, si, semaphoreitem, sle); - free(ri); + if (si->fd != -1) { + job_assumes(j, close(si->fd) != -1); + } + + free(si); } void @@ -3571,18 +3554,18 @@ } void -jobmgr_dispatch_all_other_semaphores(jobmgr_t jm, job_t nj) +jobmgr_dispatch_all_semaphores(jobmgr_t jm) { jobmgr_t jmi; job_t ji, jn; SLIST_FOREACH(jmi, &jm->submgrs, sle) { - jobmgr_dispatch_all_other_semaphores(jmi, nj); + jobmgr_dispatch_all_semaphores(jmi); } SLIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { - if (ji != nj && !SLIST_EMPTY(&ji->semaphores)) { + if (!SLIST_EMPTY(&ji->semaphores)) { job_dispatch(ji, false); } } @@ -3979,7 +3962,7 @@ return BOOTSTRAP_SERVICE_ACTIVE; } - machservice_watch(ms); + machservice_request_notifications(ms); job_log(j, LOG_INFO, "Check-in of service: %s", servicename); @@ -4034,7 +4017,7 @@ if (serviceport != MACH_PORT_NULL) { if ((ms = machservice_new(j, servicename, &serviceport))) { - machservice_watch(ms); + machservice_request_notifications(ms); } else { return BOOTSTRAP_NO_MEMORY; } @@ -4228,7 +4211,7 @@ struct machservice *ms; if ((ms = machservice_new(jmr->anonj, l2l_names[l2l_i], &l2l_ports[l2l_i]))) { - machservice_watch(ms); + machservice_request_notifications(ms); } } Modified: trunk/launchd/src/launchd_core_logic.h =================================================================== --- trunk/launchd/src/launchd_core_logic.h 2007-01-10 21:58:22 UTC (rev 23008) +++ trunk/launchd/src/launchd_core_logic.h 2007-01-12 00:33:20 UTC (rev 23009) @@ -33,7 +33,7 @@ void jobmgr_set_stderr(jobmgr_t jm, const char *what); bool jobmgr_is_idle(jobmgr_t jm); void jobmgr_remove_all_inactive(jobmgr_t jm); -void jobmgr_dispatch_all_other_semaphores(jobmgr_t jm, job_t nj); +void jobmgr_dispatch_all_semaphores(jobmgr_t jm); job_t jobmgr_find(jobmgr_t jm, const char *label); void jobmgr_delete_anything_with_port(jobmgr_t jm, mach_port_t port); bool jobmgr_ack_port_destruction(jobmgr_t jm, mach_port_t p); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070111/0b605740/attachment.html From source_changes at macosforge.org Fri Jan 12 08:47:31 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23010] trunk/launchd/src/launchctl.c Message-ID: <20070112164731.47CC247F9A2@cvs.opensource.apple.com> Revision: 23010 http://trac.macosforge.org/projects/launchd/changeset/23010 Author: zarzycki@apple.com Date: 2007-01-12 08:47:30 -0800 (Fri, 12 Jan 2007) Log Message: ----------- Fix a think-o. Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-01-12 00:33:20 UTC (rev 23009) +++ trunk/launchd/src/launchctl.c 2007-01-12 16:47:30 UTC (rev 23010) @@ -2827,7 +2827,7 @@ return; } - if (!WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == EX_OSFILE) { + if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == EX_OSFILE) { assumes(reboot(RB_AUTOBOOT) != -1); } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070112/7d9415cf/attachment.html From source_changes at macosforge.org Fri Jan 12 14:13:03 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23011] tags/launchd-188/ Message-ID: <20070112221303.D854047FD62@cvs.opensource.apple.com> Revision: 23011 http://trac.macosforge.org/projects/launchd/changeset/23011 Author: zarzycki@apple.com Date: 2007-01-12 14:13:03 -0800 (Fri, 12 Jan 2007) Log Message: ----------- "Tagging launchd-188 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-188/ Copied: tags/launchd-188 (from rev 23010, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070112/ca784719/attachment.html From source_changes at macosforge.org Thu Jan 18 12:13:26 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23012] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070118201326.6A53D485C9B@cvs.opensource.apple.com> Revision: 23012 http://trac.macosforge.org/projects/launchd/changeset/23012 Author: zarzycki@apple.com Date: 2007-01-18 12:13:26 -0800 (Thu, 18 Jan 2007) Log Message: ----------- Launch agent LimitLoadToSessionType values in array result in incorrect launching of process 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-01-12 22:13:03 UTC (rev 23011) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-18 20:13:26 UTC (rev 23012) @@ -1096,11 +1096,7 @@ } else if (strcasecmp(key, LAUNCH_JOBKEY_LIMITLOADFROMHOSTS) == 0) { return; } else if (strcasecmp(key, LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE) == 0) { - if (strcmp(value, "Aqua") == 0) { - job_reparent_hack(j, "Aqua"); - } else if (strcmp(value, "LoginWindow") == 0) { - job_reparent_hack(j, "LoginWindow"); - } + job_reparent_hack(j, value); return; } break; @@ -1281,6 +1277,9 @@ void job_import_array(job_t j, const char *key, launch_data_t value) { + size_t i, value_cnt = launch_data_array_get_count(value); + const char *str; + switch (key[0]) { case 'l': case 'L': @@ -1288,16 +1287,23 @@ return; } else if (strcasecmp(key, LAUNCH_JOBKEY_LIMITLOADFROMHOSTS) == 0) { return; + } else if (strcasecmp(key, LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE) == 0) { + for (i = 0; i < value_cnt; i++) { + str = launch_data_get_string(launch_data_array_get_index(value, i)); + if (job_assumes(j, str != NULL)) { + job_reparent_hack(j, str); + } + } } break; case 'q': case 'Q': if (strcasecmp(key, LAUNCH_JOBKEY_QUEUEDIRECTORIES) == 0) { - size_t i, qd_cnt = launch_data_array_get_count(value); - const char *thepath; - for (i = 0; i < qd_cnt; i++) { - thepath = launch_data_get_string(launch_data_array_get_index(value, i)); - semaphoreitem_new(j, DIR_NOT_EMPTY, thepath); + for (i = 0; i < value_cnt; i++) { + str = launch_data_get_string(launch_data_array_get_index(value, i)); + if (job_assumes(j, str != NULL)) { + semaphoreitem_new(j, DIR_NOT_EMPTY, str); + } } } @@ -1305,11 +1311,11 @@ case 'w': case 'W': if (strcasecmp(key, LAUNCH_JOBKEY_WATCHPATHS) == 0) { - size_t i, wp_cnt = launch_data_array_get_count(value); - const char *thepath; - for (i = 0; i < wp_cnt; i++) { - thepath = launch_data_get_string(launch_data_array_get_index(value, i)); - semaphoreitem_new(j, PATH_CHANGES, thepath); + for (i = 0; i < value_cnt; i++) { + str = launch_data_get_string(launch_data_array_get_index(value, i)); + if (job_assumes(j, str != NULL)) { + semaphoreitem_new(j, PATH_CHANGES, str); + } } } break; @@ -1322,9 +1328,9 @@ case 's': case 'S': if (strcasecmp(key, LAUNCH_JOBKEY_STARTCALENDARINTERVAL) == 0) { - size_t i = 0, ci_cnt = launch_data_array_get_count(value); - for (i = 0; i < ci_cnt; i++) + for (i = 0; i < value_cnt; i++) { calendarinterval_new_from_obj(j, launch_data_array_get_index(value, i)); + } } break; default: @@ -2437,6 +2443,10 @@ tmptm.tm_wday = -1; tmptm.tm_mon = -1; + if (!job_assumes(j, obj != NULL)) { + return false; + } + if (LAUNCH_DATA_DICTIONARY != launch_data_get_type(obj)) { return false; } @@ -4159,8 +4169,12 @@ { jobmgr_t jmi = NULL; + if (strcasecmp(where, "Aqua") != 0 && strcasecmp(where, "LoginWindow") != 0) { + return; + } + SLIST_FOREACH(jmi, &root_jobmgr->submgrs, sle) { - if (strcmp(jmi->name, where) == 0) { + if (strcasecmp(jmi->name, where) == 0) { break; } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070118/ba256892/attachment.html From source_changes at macosforge.org Thu Jan 18 12:37:42 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23013] trunk/launchd/src Message-ID: <20070118203742.8E5C9485CD8@cvs.opensource.apple.com> Revision: 23013 http://trac.macosforge.org/projects/launchd/changeset/23013 Author: zarzycki@apple.com Date: 2007-01-18 12:37:42 -0800 (Thu, 18 Jan 2007) Log Message: ----------- Fix the last checkin. 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-01-18 20:13:26 UTC (rev 23012) +++ trunk/launchd/src/launchctl.c 2007-01-18 20:37:42 UTC (rev 23013) @@ -554,6 +554,9 @@ allowed_session = launch_data_get_string(tmps); if (strcasecmp(lus->session_type, allowed_session) == 0) { skipjob = false; + /* we have to do the following so job_reparent_hack() works within launchd */ + tmpa = launch_data_new_string(lus->session_type); + launch_data_dict_insert(thejob, tmpa, LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE); break; } } Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-01-18 20:13:26 UTC (rev 23012) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-18 20:37:42 UTC (rev 23013) @@ -1288,12 +1288,8 @@ } else if (strcasecmp(key, LAUNCH_JOBKEY_LIMITLOADFROMHOSTS) == 0) { return; } else if (strcasecmp(key, LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE) == 0) { - for (i = 0; i < value_cnt; i++) { - str = launch_data_get_string(launch_data_array_get_index(value, i)); - if (job_assumes(j, str != NULL)) { - job_reparent_hack(j, str); - } - } + job_log(j, LOG_NOTICE, "launchctl should have transformed the \"%s\" array to a string", LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE); + return; } break; case 'q': -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070118/82c3a50e/attachment.html From source_changes at macosforge.org Mon Jan 22 11:43:32 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23014] trunk/launchd/src/launchctl.c Message-ID: <20070122194332.C1D4548915E@cvs.opensource.apple.com> Revision: 23014 http://trac.macosforge.org/projects/launchd/changeset/23014 Author: zarzycki@apple.com Date: 2007-01-22 11:43:32 -0800 (Mon, 22 Jan 2007) Log Message: ----------- 9A292: Bug: launchctl.c:2724 (22900):42: setsockopt(sfd, SOL_SOCKET, SO_EXECPATH, prog, strlen(prog) + 1) != -1 Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-01-18 20:37:42 UTC (rev 23013) +++ trunk/launchd/src/launchctl.c 2007-01-22 19:43:32 UTC (rev 23014) @@ -2752,7 +2752,8 @@ } if (assumes(prog != NULL)) { - assumes(setsockopt(sfd, SOL_SOCKET, SO_EXECPATH, prog, strlen(prog) + 1) != -1); + /* The networking team has asked us to ignore the failure of this API if errno == ENOPROTOOPT */ + assumes(setsockopt(sfd, SOL_SOCKET, SO_EXECPATH, prog, strlen(prog) + 1) != -1 || errno == ENOPROTOOPT); } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070122/9502b2ad/attachment.html From source_changes at macosforge.org Mon Jan 22 12:55:07 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23015] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070122205507.D35E1489206@cvs.opensource.apple.com> Revision: 23015 http://trac.macosforge.org/projects/launchd/changeset/23015 Author: zarzycki@apple.com Date: 2007-01-22 12:55:07 -0800 (Mon, 22 Jan 2007) Log Message: ----------- Nothing like writing code to track down bugs in other software. 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-01-22 19:43:32 UTC (rev 23014) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-22 20:55:07 UTC (rev 23015) @@ -291,6 +291,7 @@ static bool job_setup_machport(job_t j); static void job_setup_fd(job_t j, int target_fd, const char *path, int flags); 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_reparent_hack(job_t j, const char *where); static void job_callback(void *obj, struct kevent *kev); @@ -1953,6 +1954,36 @@ } void +job_find_and_blame_pids_with_weird_uids(job_t j) +{ + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL }; + size_t i, kp_cnt, len = 10*1024*1024; + struct kinfo_proc *kp = malloc(len); + uid_t u = j->mach_uid; + + if (!job_assumes(j, sysctl(mib, 3, kp, &len, NULL, 0) != -1)) { + return; + } + + kp_cnt = len / sizeof(struct kinfo_proc); + + for (i = 0; i <= kp_cnt; i++) { + uid_t i_euid = kp[i].kp_eproc.e_ucred.cr_uid; + uid_t i_uid = kp[i].kp_eproc.e_pcred.p_ruid; + uid_t i_svuid = kp[i].kp_eproc.e_pcred.p_svuid; + + if (i_euid != u && i_uid != u && i_svuid != u) { + continue; + } + + job_log(j, LOG_ERR, "PID %u (\"%s\") has no account to back it! (real/effective/saved UIDs: %u/%u/%u)", + kp[i].kp_proc.p_pid, kp[i].kp_proc.p_comm, i_uid, i_euid, i_svuid); + } + + free(kp); +} + +void job_postfork_become_user(job_t j) { char loginname[2000]; @@ -1974,6 +2005,7 @@ } else if (j->mach_uid) { if ((pwe = getpwuid(j->mach_uid)) == NULL) { job_log(j, LOG_ERR, "getpwuid(\"%u\") failed", j->mach_uid); + job_find_and_blame_pids_with_weird_uids(j); _exit(EXIT_FAILURE); } } else { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070122/d4453fcd/attachment.html From source_changes at macosforge.org Mon Jan 22 12:56:55 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23016] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070122205655.1AF6948921C@cvs.opensource.apple.com> Revision: 23016 http://trac.macosforge.org/projects/launchd/changeset/23016 Author: zarzycki@apple.com Date: 2007-01-22 12:56:54 -0800 (Mon, 22 Jan 2007) Log Message: ----------- Fix a small memory management related bug. 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-01-22 20:55:07 UTC (rev 23015) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-22 20:56:54 UTC (rev 23016) @@ -1961,9 +1961,12 @@ struct kinfo_proc *kp = malloc(len); uid_t u = j->mach_uid; - if (!job_assumes(j, sysctl(mib, 3, kp, &len, NULL, 0) != -1)) { + if (!job_assumes(j, kp != NULL)) { return; } + if (!job_assumes(j, sysctl(mib, 3, kp, &len, NULL, 0) != -1)) { + goto out; + } kp_cnt = len / sizeof(struct kinfo_proc); @@ -1980,6 +1983,7 @@ kp[i].kp_proc.p_pid, kp[i].kp_proc.p_comm, i_uid, i_euid, i_svuid); } +out: free(kp); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070122/62722741/attachment.html From source_changes at macosforge.org Mon Jan 22 13:19:15 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23017] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070122211915.EFE12489296@cvs.opensource.apple.com> Revision: 23017 http://trac.macosforge.org/projects/launchd/changeset/23017 Author: zarzycki@apple.com Date: 2007-01-22 13:19:15 -0800 (Mon, 22 Jan 2007) Log Message: ----------- Let's drop the parethesis. This function was, by the way, added as a part of: Report processes with bogus UIDs Which let us track down this: lsregister runs with seemingly random UID 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-01-22 20:56:54 UTC (rev 23016) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-22 21:19:15 UTC (rev 23017) @@ -1979,7 +1979,7 @@ continue; } - job_log(j, LOG_ERR, "PID %u (\"%s\") has no account to back it! (real/effective/saved UIDs: %u/%u/%u)", + job_log(j, LOG_ERR, "PID %u \"%s\" has no account to back it! Real/effective/saved UIDs: %u/%u/%u", kp[i].kp_proc.p_pid, kp[i].kp_proc.p_comm, i_uid, i_euid, i_svuid); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070122/3a26886d/attachment.html From source_changes at macosforge.org Mon Jan 22 13:23:40 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23018] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070122212340.82A074892AC@cvs.opensource.apple.com> Revision: 23018 http://trac.macosforge.org/projects/launchd/changeset/23018 Author: zarzycki@apple.com Date: 2007-01-22 13:23:40 -0800 (Mon, 22 Jan 2007) Log Message: ----------- Off by one error due to the original code that this was cribbed from. 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-01-22 21:19:15 UTC (rev 23017) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-22 21:23:40 UTC (rev 23018) @@ -1970,7 +1970,7 @@ kp_cnt = len / sizeof(struct kinfo_proc); - for (i = 0; i <= kp_cnt; i++) { + for (i = 0; i < kp_cnt; i++) { uid_t i_euid = kp[i].kp_eproc.e_ucred.cr_uid; uid_t i_uid = kp[i].kp_eproc.e_pcred.p_ruid; uid_t i_svuid = kp[i].kp_eproc.e_pcred.p_svuid; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070122/84557ba8/attachment.html From source_changes at macosforge.org Mon Jan 22 13:28:52 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23019] tags/launchd-189/ Message-ID: <20070122212852.A56824892CE@cvs.opensource.apple.com> Revision: 23019 http://trac.macosforge.org/projects/launchd/changeset/23019 Author: zarzycki@apple.com Date: 2007-01-22 13:28:52 -0800 (Mon, 22 Jan 2007) Log Message: ----------- "Tagging launchd-189 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-189/ Copied: tags/launchd-189 (from rev 23018, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070122/2d84740a/attachment.html From source_changes at macosforge.org Tue Jan 23 10:56:21 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23020] trunk/launchd/src/launchd.c Message-ID: <20070123185621.4059448A04E@cvs.opensource.apple.com> Revision: 23020 http://trac.macosforge.org/projects/launchd/changeset/23020 Author: zarzycki@apple.com Date: 2007-01-23 10:56:20 -0800 (Tue, 23 Jan 2007) Log Message: ----------- mount_smbfs hangs at login time Modified Paths: -------------- trunk/launchd/src/launchd.c Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-01-22 21:28:52 UTC (rev 23019) +++ trunk/launchd/src/launchd.c 2007-01-23 18:56:20 UTC (rev 23020) @@ -290,7 +290,16 @@ } } - if (stat(ldconf, &sb) == 0) { + /* + * We cannot stat() anything in the home directory right now. + * + * The per-user launchd can easily be demand launched by the tool doing + * the mount of the home directory. The result is an ugly deadlock. + * + * We hope to someday have a non-blocking stat(), but for now, we have + * to skip it. + */ + if (!h && stat(ldconf, &sb) == 0) { job_dispatch(rlcj, true); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070123/61cc2d9e/attachment.html From source_changes at macosforge.org Wed Jan 24 13:46:56 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23021] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070124214656.B581A48B6DB@cvs.opensource.apple.com> Revision: 23021 http://trac.macosforge.org/projects/launchd/changeset/23021 Author: zarzycki@apple.com Date: 2007-01-24 13:46:56 -0800 (Wed, 24 Jan 2007) Log Message: ----------- Nice values can be zero. 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-01-23 18:56:20 UTC (rev 23020) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-24 21:46:56 UTC (rev 23021) @@ -265,7 +265,7 @@ anonymous:1; mode_t mask; 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; + currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1; char label[0]; }; @@ -1168,6 +1168,7 @@ case 'N': if (strcasecmp(key, LAUNCH_JOBKEY_NICE) == 0) { j->nice = value; + j->setnice = true; } break; case 't': @@ -2080,7 +2081,9 @@ struct limititem *li; struct envitem *ei; - setpriority(PRIO_PROCESS, 0, j->nice); + if (j->setnice) { + job_assumes(j, setpriority(PRIO_PROCESS, 0, j->nice) != -1); + } SLIST_FOREACH(li, &j->limits, sle) { struct rlimit rl; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070124/6b057293/attachment.html From source_changes at macosforge.org Thu Jan 25 13:45:12 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23022] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070125214512.40F9C48E9DE@cvs.opensource.apple.com> Revision: 23022 http://trac.macosforge.org/projects/launchd/changeset/23022 Author: zarzycki@apple.com Date: 2007-01-25 13:45:11 -0800 (Thu, 25 Jan 2007) Log Message: ----------- Let's not drop errno on the floor in this function. 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-01-24 21:46:56 UTC (rev 23021) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-25 21:45:11 UTC (rev 23022) @@ -2912,6 +2912,7 @@ { mach_port_t p = jm->jm_port; pid_t r = -1; + int saved_errno; sigprocmask(SIG_BLOCK, &blocked_signals, NULL); @@ -2921,6 +2922,8 @@ r = fork(); + saved_errno = errno; + if (r != 0) { jobmgr_assumes(jm, launchd_set_bport(MACH_PORT_NULL) == KERN_SUCCESS); } else if (r == 0) { @@ -2935,6 +2938,7 @@ sigprocmask(SIG_UNBLOCK, &blocked_signals, NULL); + errno = saved_errno; return r; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070125/d43f92e3/attachment.html From source_changes at macosforge.org Thu Jan 25 13:46:03 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:38 2007 Subject: [launchd-changes] [23023] tags/launchd-190/ Message-ID: <20070125214603.B09A548E9E2@cvs.opensource.apple.com> Revision: 23023 http://trac.macosforge.org/projects/launchd/changeset/23023 Author: zarzycki@apple.com Date: 2007-01-25 13:46:03 -0800 (Thu, 25 Jan 2007) Log Message: ----------- "Tagging launchd-190 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-190/ Copied: tags/launchd-190 (from rev 23022, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070125/11a556ae/attachment.html From source_changes at macosforge.org Fri Jan 26 15:45:13 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23024] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070126234513.4F70F491AF9@cvs.opensource.apple.com> Revision: 23024 http://trac.macosforge.org/projects/launchd/changeset/23024 Author: zarzycki@apple.com Date: 2007-01-26 15:45:13 -0800 (Fri, 26 Jan 2007) Log Message: ----------- PIDs shouldn't be running around without user records to back the UIDs assigned to the process. 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-01-25 21:46:03 UTC (rev 23023) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-26 23:45:13 UTC (rev 23024) @@ -404,7 +404,7 @@ job_stop(job_t j) { if (j->p) { - kill(j->p, SIGTERM); + job_assumes(j, kill(j->p, SIGTERM) != -1); } } @@ -1975,13 +1975,17 @@ uid_t i_euid = kp[i].kp_eproc.e_ucred.cr_uid; uid_t i_uid = kp[i].kp_eproc.e_pcred.p_ruid; uid_t i_svuid = kp[i].kp_eproc.e_pcred.p_svuid; + pid_t i_pid = kp[i].kp_proc.p_pid; if (i_euid != u && i_uid != u && i_svuid != u) { continue; } job_log(j, LOG_ERR, "PID %u \"%s\" has no account to back it! Real/effective/saved UIDs: %u/%u/%u", - kp[i].kp_proc.p_pid, kp[i].kp_proc.p_comm, i_uid, i_euid, i_svuid); + i_pid, kp[i].kp_proc.p_comm, i_uid, i_euid, i_svuid); + + /* Ask the accountless process to exit. */ + job_assumes(j, kill(i_pid, SIGTERM) != -1); } out: -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070126/afff3f4e/attachment.html From source_changes at macosforge.org Sun Jan 28 13:15:54 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23025] trunk/launchd/src Message-ID: <20070128211554.4FCC5493300@cvs.opensource.apple.com> Revision: 23025 http://trac.macosforge.org/projects/launchd/changeset/23025 Author: zarzycki@apple.com Date: 2007-01-28 13:15:53 -0800 (Sun, 28 Jan 2007) Log Message: ----------- The last remaining customer (loginwindow) of /etc/ttys has switched to launchd. This is the easy part or removing init.c. The next stage will be to deal with single-user-mode in launchd proper and clean up launchd's self-bootstrap logic. Then we can finally delete init.c. Modified Paths: -------------- trunk/launchd/src/init.c trunk/launchd/src/launchctl.1 trunk/launchd/src/launchctl.c trunk/launchd/src/launchd.c trunk/launchd/src/launchd.h trunk/launchd/src/launchd_unix_ipc.c trunk/launchd/src/liblaunch_private.h Modified: trunk/launchd/src/init.c =================================================================== --- trunk/launchd/src/init.c 2007-01-26 23:45:13 UTC (rev 23024) +++ trunk/launchd/src/init.c 2007-01-28 21:15:53 UTC (rev 23025) @@ -55,10 +55,6 @@ static const char *const __rcs_file_version__ = "$Revision$"; -#include -#include -#include - #include #include #include @@ -91,14 +87,7 @@ #define _PATH_RUNCOM "/etc/rc" -/* - * Sleep times; used to prevent thrashing. - */ -#define GETTY_SPACING 5 /* N secs minimum getty spacing */ -#define GETTY_SLEEP 30 /* sleep N secs after spacing problem */ #define STALL_TIMEOUT 30 /* wait N secs after warning */ -#define DEATH_WATCH 10 /* wait N secs for procs to die */ -#define FAILED_HW_PASS 5 /* wait N secs before croaking user */ static void stall(char *, ...); @@ -117,58 +106,8 @@ static void setctty(const char *, int); -// gvdl@next.com 14 Aug 1995 -// - from ~apps/loginwindow_proj/loginwindow/common.h -#define REALLY_EXIT_TO_CONSOLE 229 - -// From old init.c -// These flags are used in the se_flags field of the init_session structure -#define SE_SHUTDOWN 0x1 /* session won't be restarted */ - -// The flags below control what sort of getty is launched. -#define SE_GETTY_LAUNCH 0x30 /* What type of getty to launch */ -#define SE_COMMON 0x00 /* Usual command that is run - getty */ -#define SE_ONERROR 0x10 /* Command to run if error condition occurs. - * This will almost always be the windowserver - * and loginwindow. This is so if the w.s. - * ever dies, that the naive user (stan) - * doesn't ever see the console window. */ -#define SE_ONOPTION 0x20 /* Command to run when loginwindow exits with - * special error code (229). This signifies - * that the user typed "console" at l.w. and - * l.w. wants to exit and have init run getty - * which will then put up a console window. */ - -typedef struct _se_command { - char *path; /* what to run on that port */ - char **argv; /* pre-parsed argument array */ -} se_cmd_t; - -typedef struct init_session { - kq_callback se_callback; /* run loop callback */ - int se_index; /* index of entry in ttys file */ - pid_t se_process; /* controlling process */ - time_t se_started; /* used to avoid thrashing */ - int se_flags; /* status of session */ - char *se_device; /* filename of port */ - se_cmd_t se_getty; /* what to run on that port */ - se_cmd_t se_onerror; /* See SE_ONERROR above */ - se_cmd_t se_onoption; /* See SE_ONOPTION above */ - TAILQ_ENTRY(init_session) tqe; -} *session_t; - -static TAILQ_HEAD(sessionshead, init_session) sessions = TAILQ_HEAD_INITIALIZER(sessions); - -static void session_new(int, struct ttyent *); -static void session_free(session_t); -static void session_launch(session_t); -static void session_reap(session_t); -static void session_callback(void *, struct kevent *); - -static char **construct_argv(char *); static void setsecuritylevel(int); static int getsecuritylevel(void); -static int setupargv(session_t, struct ttyent *); static bool should_fsck(void); void @@ -183,8 +122,6 @@ void init_pre_kevent(void) { - session_t s; - if (single_user_pid || runcom_pid) return; @@ -200,16 +137,12 @@ * mode, and the run script has not set a higher level of security * than level 1, then put the kernel into secure mode. */ - if (getsecuritylevel() == 0) + if (getsecuritylevel() == 0) { setsecuritylevel(1); - - TAILQ_FOREACH(s, &sessions, tqe) { - if (s->se_process == 0) - session_launch(s); } } -static void +void stall(char *message, ...) { va_list ap; @@ -220,7 +153,7 @@ sleep(STALL_TIMEOUT); } -static int +int getsecuritylevel(void) { int name[2], curlevel; @@ -236,7 +169,7 @@ return curlevel; } -static void +void setsecuritylevel(int newlevel) { int name[2], curlevel; @@ -259,7 +192,7 @@ * Start a session and allocate a controlling terminal. * Only called by children of init after forking. */ -static void +void setctty(const char *name, int flags) { int fd; @@ -275,7 +208,7 @@ } } -static void +void single_user(void) { bool runcom_fsck = should_fsck(); @@ -315,7 +248,7 @@ } } -static void +void single_user_callback(void *obj __attribute__((unused)), struct kevent *kev __attribute__((unused))) { int status; @@ -338,10 +271,11 @@ } static struct timeval runcom_start_tv = { 0, 0 }; + /* * Run the system startup script. */ -static void +void runcom(void) { char *argv[] = { "/bin/launchctl", "bootstrap", NULL }; @@ -389,7 +323,7 @@ exit(EXIT_FAILURE); } -static void +void runcom_callback(void *obj __attribute__((unused)), struct kevent *kev __attribute__((unused))) { int status; @@ -421,323 +355,9 @@ single_user_mode = true; } -/* - * Construct an argument vector from a command line. - */ -char ** -construct_argv(command) - char *command; +bool +init_check_pid(pid_t p) { - int argc = 0; - char **argv = (char **) malloc(((strlen(command) + 1) / 2 + 1) - * sizeof (char *)); - static const char separators[] = " \t"; - - if ((argv[argc++] = strtok(command, separators)) == 0) - return 0; - while ((argv[argc++] = strtok(NULL, separators))) - continue; - return argv; -} - -/* - * Deallocate a session descriptor. - */ - -static void free_command(se_cmd_t *se_cmd) -{ - if (se_cmd->path) { - free(se_cmd->path); - free(se_cmd->argv); - } -} - -void -session_free(session_t s) -{ - TAILQ_REMOVE(&sessions, s, tqe); - if (s->se_process) { - if (kevent_mod(s->se_process, EVFILT_PROC, EV_ADD, - NOTE_EXIT, 0, &kqsimple_zombie_reaper) == -1) - session_reap(s); - else - kill(s->se_process, SIGHUP); - } - free(s->se_device); - free_command(&s->se_getty); - free_command(&s->se_onerror); - free_command(&s->se_onoption); - free(s); -} - -static int setup_command(se_cmd_t *se_cmd, char *command, char *arg ) -{ - char *commandWithArg; - - asprintf(&commandWithArg, "%s %s", command, arg); - - free_command(se_cmd); - - se_cmd->path = commandWithArg; - se_cmd->argv = construct_argv(commandWithArg); - if (se_cmd->argv == NULL) { - free(se_cmd->path); - se_cmd->path = NULL; - return 0; - } - return 1; -} - -/* - * Calculate getty and if useful window argv vectors. - */ -static int -setupargv(sp, typ) - session_t sp; - struct ttyent *typ; -{ - char *type; - - if ( !setup_command(&sp->se_getty, typ->ty_getty, typ->ty_name) ) - { - type = "getty"; - goto bad_args; - } - - if (typ->ty_onerror - && !setup_command(&sp->se_onerror, typ->ty_onerror, typ->ty_name) ) - { - type = "onerror"; - goto bad_args; - } - - if (typ->ty_onoption - && !setup_command(&sp->se_onoption, typ->ty_onoption, typ->ty_name) ) - { - type = "onoption"; - goto bad_args; - } - - return 1; - -bad_args: - syslog(LOG_WARNING, "can't parse %s for port %s", type, sp->se_device); - return 0; -} - - -/* - * Allocate a new session descriptor. - */ -void -session_new(session_index, typ) - int session_index; - struct ttyent *typ; -{ - session_t s; - - if ((typ->ty_status & TTY_ON) == 0 || - typ->ty_name == 0 || - typ->ty_getty == 0) - return; - - s = calloc(1, sizeof(struct init_session)); - - s->se_callback = session_callback; - s->se_index = session_index; - - TAILQ_INSERT_TAIL(&sessions, s, tqe); - - asprintf(&s->se_device, "%s%s", _PATH_DEV, typ->ty_name); - - if (setupargv(s, typ) == 0) - session_free(s); -} - -static void -session_launch(session_t s) -{ - pid_t pid; - sigset_t mask; - se_cmd_t *se_cmd; - const char *session_type = NULL; - time_t current_time = time(NULL); - bool is_loginwindow = false; - - // Setup the default values; - switch (s->se_flags & SE_GETTY_LAUNCH) { - case SE_ONOPTION: - if (s->se_onoption.path) { - se_cmd = &s->se_onoption; - session_type = "onoption"; - break; - } - /* No break */ - case SE_ONERROR: - if (s->se_onerror.path) { - se_cmd = &s->se_onerror; - session_type = "onerror"; - break; - } - /* No break */ - case SE_COMMON: - default: - se_cmd = &s->se_getty; - session_type = "getty"; - break; - } - - if (strcmp(se_cmd->argv[0], "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow") == 0) - is_loginwindow = true; - - pid = launchd_fork(); - - if (pid == -1) { - syslog(LOG_ERR, "can't fork for %s on port %s: %m", - session_type, s->se_device); - return; - } - - if (pid) { - s->se_process = pid; - s->se_started = time(NULL); - s->se_flags &= ~SE_GETTY_LAUNCH; // clear down getty launch type - if (kevent_mod(pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, &s->se_callback) == -1) - session_reap(s); - return; - } - - if (current_time > s->se_started && - current_time - s->se_started < GETTY_SPACING) { - syslog(LOG_WARNING, "%s repeating too quickly on port %s, sleeping", - session_type, s->se_device); - sleep(GETTY_SLEEP); - } - - sigemptyset(&mask); - sigprocmask(SIG_SETMASK, &mask, NULL); - - - if (!is_loginwindow) - launchd_SessionCreate(); - - execv(se_cmd->argv[0], se_cmd->argv); - stall("can't exec %s '%s' for port %s: %m", session_type, - se_cmd->argv[0], s->se_device); - exit(EXIT_FAILURE); -} - -static void -session_callback(void *obj, struct kevent *kev __attribute__((unused))) -{ - session_t s = obj; - - session_reap(s); - if (s->se_flags & SE_SHUTDOWN) { - session_free(s); - } else { - session_launch(s); - } -} - -static void -session_reap(session_t s) -{ - char *line; - int status; - - if (!launchd_assumes(waitpid(s->se_process, &status, 0) == s->se_process)) - return; - - if (WIFSIGNALED(status)) { - syslog(LOG_WARNING, "%s port %s exited abnormally: %s", - s->se_getty.path, s->se_device, strsignal(WTERMSIG(status))); - s->se_flags |= SE_ONERROR; - } else if (WEXITSTATUS(status) == REALLY_EXIT_TO_CONSOLE) { - /* WIFEXITED(status) assumed */ - s->se_flags |= SE_ONOPTION; - } else { - s->se_flags |= SE_ONERROR; - } - - s->se_process = 0; - line = s->se_device + sizeof(_PATH_DEV) - 1; - - if (logout(line)) - logwtmp(line, "", ""); -} - -/* - * This is an n-squared algorithm. We hope it isn't run often... - */ -void -update_ttys(void) -{ - session_t sp; - struct ttyent *typ; - int session_index = 0; - int devlen; - - devlen = sizeof(_PATH_DEV) - 1; - while ((typ = getttyent())) { - ++session_index; - - TAILQ_FOREACH(sp, &sessions, tqe) { - if (strcmp(typ->ty_name, sp->se_device + devlen) == 0) - break; - } - - if (sp == NULL) { - session_new(session_index, typ); - continue; - } - - if (sp->se_index != session_index) { - syslog(LOG_INFO, "port %s changed utmp index from %d to %d", - sp->se_device, sp->se_index, - session_index); - sp->se_index = session_index; - } - - if ((typ->ty_status & TTY_ON) == 0 || - typ->ty_getty == 0) { - session_free(sp); - continue; - } - - sp->se_flags &= ~SE_SHUTDOWN; - - if (setupargv(sp, typ) == 0) { - syslog(LOG_WARNING, "can't parse getty for port %s", - sp->se_device); - session_free(sp); - } - } - - endttyent(); -} - -/* - * Block further logins. - */ -void -catatonia(void) -{ - session_t s; - - TAILQ_FOREACH(s, &sessions, tqe) - s->se_flags |= SE_SHUTDOWN; -} - -bool init_check_pid(pid_t p) -{ - session_t s; - - TAILQ_FOREACH(s, &sessions, tqe) { - if (s->se_process == p) - return true; - } - if (single_user_pid == p) return true; Modified: trunk/launchd/src/launchctl.1 =================================================================== --- trunk/launchd/src/launchctl.1 2007-01-26 23:45:13 UTC (rev 23024) +++ trunk/launchd/src/launchctl.1 2007-01-28 21:15:53 UTC (rev 23025) @@ -140,10 +140,6 @@ Tell .Nm launchd to prepare for shutdown by removing all jobs. -.It Ar reloadttys -Tell -.Nm launchd -to reread /etc/ttys. This option may go away in a future release. .It Ar umask Op Ar newmask Get or optionally set the .Xr umask 2 Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-01-26 23:45:13 UTC (rev 23024) +++ trunk/launchd/src/launchctl.c 2007-01-28 21:15:53 UTC (rev 23025) @@ -134,7 +134,6 @@ static void empty_dir(const char *thedir, struct stat *psb); static int touch_file(const char *path, mode_t m); static void do_sysversion_sysctl(void); -static void workaround4465949(void); static void do_application_firewall_magic(int sfd, launch_data_t thejob); static void preheat_page_cache_hack(void); static void do_bootroot_magic(void); @@ -185,7 +184,6 @@ { "stderr", stdio_cmd, "Redirect launchd's standard error to the given path" }, { "shutdown", fyi_cmd, "Prepare for system shutdown" }, { "singleuser", fyi_cmd, "Switch to single-user mode" }, - { "reloadttys", fyi_cmd, "Reload /etc/ttys" }, { "getrusage", getrusage_cmd, "Get resource usage statistics from launchd" }, { "log", logupdate_cmd, "Adjust the logging level or mask of launchd" }, { "umask", umask_cmd, "Change launchd's umask" }, @@ -1279,8 +1277,6 @@ const char *SystemStarter_tool[] = { "SystemStarter", NULL }; assumes(fwexec(SystemStarter_tool, false) != -1); - workaround4465949(); - if (path_check("/etc/rc.local")) { const char *rc_local_tool[] = { _PATH_BSHELL, "/etc/rc.local", NULL }; assumes(fwexec(rc_local_tool, false) != -1); @@ -1289,32 +1285,6 @@ return 0; } -void -workaround4465949(void) -{ - const char *pbs_tool[] = { "/System/Library/CoreServices/pbs", NULL }; - const char *lca_tool[] = { "/System/Library/CoreServices/Language Chooser.app/Contents/MacOS/Language Chooser", NULL}; - char *const reloadttys_argv[] = { "reloadttys", NULL }; - int wstatus; - pid_t pbs_p; - - if (path_check("/System/Library/LaunchDaemons/com.apple.loginwindow.plist")) { - return; - } - - if (path_check(pbs_tool[0]) && path_check(lca_tool[0]) && - !path_check("/var/db/.AppleSetupDone") && - path_check("/var/db/.RunLanguageChooserToo")) { - if (assumes((pbs_p = fwexec(pbs_tool, false)) != -1)) { - assumes(fwexec(lca_tool, true) != -1); - assumes(kill(pbs_p, SIGTERM) != -1); - assumes(waitpid(pbs_p, &wstatus, 0) != -1); - } - } - - assumes(fyi_cmd(1, reloadttys_argv) == 0); -} - int load_and_unload_cmd(int argc, char *const argv[]) { @@ -1763,7 +1733,7 @@ fyi_cmd(int argc, char *const argv[]) { launch_data_t resp, msg; - const char *lmsgk = LAUNCH_KEY_RELOADTTYS; + const char *lmsgk = NULL; int e, r = 0; if (argc != 1) { @@ -1775,6 +1745,8 @@ lmsgk = LAUNCH_KEY_SHUTDOWN; } else if (!strcmp(argv[0], "singleuser")) { lmsgk = LAUNCH_KEY_SINGLEUSER; + } else { + return 1; } msg = launch_data_new_string(lmsgk); Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-01-26 23:45:13 UTC (rev 23024) +++ trunk/launchd/src/launchd.c 2007-01-28 21:15:53 UTC (rev 23025) @@ -469,10 +469,6 @@ rlcj = NULL; jobmgr_remove_all_inactive(root_jobmgr); - - if (getpid() == 1) { - catatonia(); - } } void Modified: trunk/launchd/src/launchd.h =================================================================== --- trunk/launchd/src/launchd.h 2007-01-26 23:45:13 UTC (rev 23024) +++ trunk/launchd/src/launchd.h 2007-01-28 21:15:53 UTC (rev 23025) @@ -55,9 +55,6 @@ void init_boot(bool sflag); void init_pre_kevent(void); -void update_ttys(void); -void catatonia(void); - void mach_start_shutdown(void); void mach_init_init(mach_port_t); Modified: trunk/launchd/src/launchd_unix_ipc.c =================================================================== --- trunk/launchd/src/launchd_unix_ipc.c 2007-01-26 23:45:13 UTC (rev 23024) +++ trunk/launchd/src/launchd_unix_ipc.c 2007-01-28 21:15:53 UTC (rev 23025) @@ -352,9 +352,6 @@ } else { resp = launch_data_new_errno(EACCES); } - } else if (!strcmp(cmd, LAUNCH_KEY_RELOADTTYS)) { - update_ttys(); - resp = launch_data_new_errno(0); } else if (!strcmp(cmd, LAUNCH_KEY_SHUTDOWN)) { launchd_shutdown(); resp = launch_data_new_errno(0); Modified: trunk/launchd/src/liblaunch_private.h =================================================================== --- trunk/launchd/src/liblaunch_private.h 2007-01-26 23:45:13 UTC (rev 23024) +++ trunk/launchd/src/liblaunch_private.h 2007-01-28 21:15:53 UTC (rev 23025) @@ -37,7 +37,6 @@ #define LAUNCH_KEY_SINGLEUSER "SingleUser" #define LAUNCH_KEY_GETRESOURCELIMITS "GetResourceLimits" #define LAUNCH_KEY_SETRESOURCELIMITS "SetResourceLimits" -#define LAUNCH_KEY_RELOADTTYS "ReloadTTYS" #define LAUNCH_KEY_SETLOGMASK "SetLogMask" #define LAUNCH_KEY_GETLOGMASK "GetLogMask" #define LAUNCH_KEY_SETUMASK "SetUmask" -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070128/83f80ca6/attachment.html From source_changes at macosforge.org Tue Jan 30 13:32:41 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23026] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070130213241.E470F4959C6@cvs.opensource.apple.com> Revision: 23026 http://trac.macosforge.org/projects/launchd/changeset/23026 Author: zarzycki@apple.com Date: 2007-01-30 13:32:41 -0800 (Tue, 30 Jan 2007) Log Message: ----------- 'launchd' leaks memory over login/logout cycling 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-01-28 21:15:53 UTC (rev 23025) +++ trunk/launchd/src/launchd_core_logic.c 2007-01-30 21:32:41 UTC (rev 23026) @@ -4546,6 +4546,8 @@ *child_pid = job_get_pid(jr); *obsvr_port = jr->j_port; + mig_deallocate((vm_address_t)charbuf, charbuf_cnt); + return BOOTSTRAP_SUCCESS; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070130/feb0e70d/attachment.html From source_changes at macosforge.org Wed Jan 31 15:19:40 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23027] tags/launchd-191/ Message-ID: <20070131231940.04D0B4972AD@cvs.opensource.apple.com> Revision: 23027 http://trac.macosforge.org/projects/launchd/changeset/23027 Author: zarzycki@apple.com Date: 2007-01-31 15:19:40 -0800 (Wed, 31 Jan 2007) Log Message: ----------- "Tagging launchd-191 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-191/ Copied: tags/launchd-191 (from rev 23026, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070131/bed6b528/attachment.html