From source_changes at macosforge.org Mon Feb 5 13:35:42 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23028] trunk/launchd/src/launchctl.c Message-ID: <20070205213542.95D7149BB46@cvs.opensource.apple.com> Revision: 23028 http://trac.macosforge.org/projects/launchd/changeset/23028 Author: zarzycki@apple.com Date: 2007-02-05 13:35:42 -0800 (Mon, 05 Feb 2007) Log Message: ----------- leopard: regression: rc.local not supported Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-01-31 23:19:40 UTC (rev 23027) +++ trunk/launchd/src/launchctl.c 2007-02-05 21:35:42 UTC (rev 23028) @@ -1279,7 +1279,7 @@ if (path_check("/etc/rc.local")) { const char *rc_local_tool[] = { _PATH_BSHELL, "/etc/rc.local", NULL }; - assumes(fwexec(rc_local_tool, false) != -1); + assumes(fwexec(rc_local_tool, true) != -1); } return 0; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070205/4c341600/attachment.html From source_changes at macosforge.org Mon Feb 5 14:11:17 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23029] trunk/launchd/src Message-ID: <20070205221117.3FCC749BC3F@cvs.opensource.apple.com> Revision: 23029 http://trac.macosforge.org/projects/launchd/changeset/23029 Author: zarzycki@apple.com Date: 2007-02-05 14:11:16 -0800 (Mon, 05 Feb 2007) Log Message: ----------- turn SystemStarter into a launchd job Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/SystemStarter.c trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-02-05 21:35:42 UTC (rev 23028) +++ trunk/launchd/src/Makefile.am 2007-02-05 22:11:16 UTC (rev 23029) @@ -93,7 +93,8 @@ mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init_per_user.d mkdir -p $(DESTDIR)/Library/LaunchDaemons mkdir -p $(DESTDIR)/Library/LaunchAgents + mkdir -p $(DESTDIR)/System/Library/LaunchAgents mkdir -p $(DESTDIR)/System/Library/LaunchDaemons - mkdir -p $(DESTDIR)/System/Library/LaunchAgents + cp $(srcdir)/com.apple.SystemStarter.plist $(DESTDIR)/System/Library/LaunchDaemons endif Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-02-05 21:35:42 UTC (rev 23028) +++ trunk/launchd/src/Makefile.in 2007-02-05 22:11:16 UTC (rev 23029) @@ -1107,8 +1107,9 @@ @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init_per_user.d @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/Library/LaunchDaemons @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/Library/LaunchAgents +@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/System/Library/LaunchAgents @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/System/Library/LaunchDaemons -@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/System/Library/LaunchAgents +@LIBS_ONLY_FALSE@ cp $(srcdir)/com.apple.SystemStarter.plist $(DESTDIR)/System/Library/LaunchDaemons # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: Modified: trunk/launchd/src/SystemStarter.c =================================================================== --- trunk/launchd/src/SystemStarter.c 2007-02-05 21:35:42 UTC (rev 23028) +++ trunk/launchd/src/SystemStarter.c 2007-02-05 22:11:16 UTC (rev 23029) @@ -22,6 +22,9 @@ * @APPLE_APACHE_LICENSE_HEADER_END@ **/ +#include +#include +#include #include #include #include @@ -147,7 +150,27 @@ } } - exit(system_starter(anAction, aService)); + int ssec = system_starter(anAction, aService); + struct stat sb; + + if (anAction == kActionStart && stat("/etc/rc.local", &sb) != -1) { + int wstatus; + pid_t rclp; + + switch ((rclp = fork())) { + case -1: + break; + case 0: + execlp(_PATH_BSHELL, _PATH_BSHELL, "/etc/rc.local", NULL); + _exit(EXIT_FAILURE); + break; + default: + waitpid(rclp, &wstatus, 0); + break; + } + } + + exit(ssec); } Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-02-05 21:35:42 UTC (rev 23028) +++ trunk/launchd/src/launchctl.c 2007-02-05 22:11:16 UTC (rev 23029) @@ -1274,14 +1274,6 @@ _vproc_set_global_on_demand(false); - const char *SystemStarter_tool[] = { "SystemStarter", NULL }; - assumes(fwexec(SystemStarter_tool, false) != -1); - - if (path_check("/etc/rc.local")) { - const char *rc_local_tool[] = { _PATH_BSHELL, "/etc/rc.local", NULL }; - assumes(fwexec(rc_local_tool, true) != -1); - } - return 0; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070205/449c1acf/attachment.html From source_changes at macosforge.org Mon Feb 5 14:11:46 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23030] trunk/launchd/src/com.apple.SystemStarter.plist Message-ID: <20070205221146.D34C249BC4F@cvs.opensource.apple.com> Revision: 23030 http://trac.macosforge.org/projects/launchd/changeset/23030 Author: zarzycki@apple.com Date: 2007-02-05 14:11:46 -0800 (Mon, 05 Feb 2007) Log Message: ----------- turn SystemStarter into a launchd job Added Paths: ----------- trunk/launchd/src/com.apple.SystemStarter.plist Added: trunk/launchd/src/com.apple.SystemStarter.plist =================================================================== --- trunk/launchd/src/com.apple.SystemStarter.plist (rev 0) +++ trunk/launchd/src/com.apple.SystemStarter.plist 2007-02-05 22:11:46 UTC (rev 23030) @@ -0,0 +1,12 @@ + + + + + Label + com.apple.SystemStarter + Program + /sbin/SystemStarter + RunAtLoad + + + -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070205/02d57926/attachment.html From source_changes at macosforge.org Tue Feb 6 09:50:05 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23031] trunk/launchd/src/launchd_runtime.c Message-ID: <20070206175005.4A9BF49CB9A@cvs.opensource.apple.com> Revision: 23031 http://trac.macosforge.org/projects/launchd/changeset/23031 Author: zarzycki@apple.com Date: 2007-02-06 09:50:05 -0800 (Tue, 06 Feb 2007) Log Message: ----------- Code to help track down an elusive crash Modified Paths: -------------- trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-05 22:11:46 UTC (rev 23030) +++ trunk/launchd/src/launchd_runtime.c 2007-02-06 17:50:05 UTC (rev 23031) @@ -34,12 +34,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -190,6 +192,36 @@ return NULL; } +static bool +ptr_is_in_exe(void *ptr) +{ + uint32_t i, count = _dyld_image_count(); + + for (i = 0; i < count; i++) { + const struct mach_header *header = _dyld_get_image_header(i); + uint32_t j, offset = _dyld_get_image_vmaddr_slide(i); + struct segment_command *seg; + struct load_command *cmd; + + j = 0; + cmd = (struct load_command*)((char *)header + sizeof(struct mach_header)); + + while (j < header->ncmds) { + if (cmd->cmd == LC_SEGMENT) { + seg = (struct segment_command*)cmd; + if (((uint32_t)ptr >= (seg->vmaddr + offset)) && ((uint32_t)ptr < (seg->vmaddr + offset + seg->vmsize))) { + return true; + } + } + + j++; + cmd = (struct load_command*)((char*)cmd + cmd->cmdsize); + } + } + + return false; +} + kern_return_t x_handle_kqueue(mach_port_t junk __attribute__((unused)), integer_t fd) { @@ -200,7 +232,12 @@ launchd_assumes((kevr = kevent(fd, NULL, 0, &kev, 1, &ts)) != -1); if (kevr == 1) { - (*((kq_callback *)kev.udata))(kev.udata, &kev); + if (launchd_assumes(malloc_size(kev.udata) || ptr_is_in_exe(kev.udata))) { + (*((kq_callback *)kev.udata))(kev.udata, &kev); + } else { + syslog(LOG_ERR, "kev.ident == 0x%x kev.filter == 0x%x kev.fflags = 0x%x kev.udata = 0x%x", + kev.ident, kev.filter, kev.fflags, kev.udata); + } } launchd_post_kevent(); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070206/aeb9db8b/attachment.html From source_changes at macosforge.org Tue Feb 6 11:16:25 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23032] trunk/launchd/src/launchd_runtime.c Message-ID: <20070206191625.E5C3549CCD8@cvs.opensource.apple.com> Revision: 23032 http://trac.macosforge.org/projects/launchd/changeset/23032 Author: zarzycki@apple.com Date: 2007-02-06 11:16:25 -0800 (Tue, 06 Feb 2007) Log Message: ----------- I just got off the phone with our dynamic linker engineer. This should work just as well, but with less code. Modified Paths: -------------- trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-06 17:50:05 UTC (rev 23031) +++ trunk/launchd/src/launchd_runtime.c 2007-02-06 19:16:25 UTC (rev 23032) @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -51,6 +50,7 @@ #include #include #include +#include #include "launchd_internalServer.h" #include "launchd_internal.h" @@ -192,47 +192,18 @@ return NULL; } -static bool -ptr_is_in_exe(void *ptr) -{ - uint32_t i, count = _dyld_image_count(); - - for (i = 0; i < count; i++) { - const struct mach_header *header = _dyld_get_image_header(i); - uint32_t j, offset = _dyld_get_image_vmaddr_slide(i); - struct segment_command *seg; - struct load_command *cmd; - - j = 0; - cmd = (struct load_command*)((char *)header + sizeof(struct mach_header)); - - while (j < header->ncmds) { - if (cmd->cmd == LC_SEGMENT) { - seg = (struct segment_command*)cmd; - if (((uint32_t)ptr >= (seg->vmaddr + offset)) && ((uint32_t)ptr < (seg->vmaddr + offset + seg->vmsize))) { - return true; - } - } - - j++; - cmd = (struct load_command*)((char*)cmd + cmd->cmdsize); - } - } - - return false; -} - kern_return_t x_handle_kqueue(mach_port_t junk __attribute__((unused)), integer_t fd) { struct timespec ts = { 0, 0 }; struct kevent kev; + Dl_info dli; int kevr; launchd_assumes((kevr = kevent(fd, NULL, 0, &kev, 1, &ts)) != -1); if (kevr == 1) { - if (launchd_assumes(malloc_size(kev.udata) || ptr_is_in_exe(kev.udata))) { + if (launchd_assumes(malloc_size(kev.udata) || dladdr(kev.udata, &dli))) { (*((kq_callback *)kev.udata))(kev.udata, &kev); } else { syslog(LOG_ERR, "kev.ident == 0x%x kev.filter == 0x%x kev.fflags = 0x%x kev.udata = 0x%x", -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070206/52182454/attachment.html From source_changes at macosforge.org Tue Feb 6 14:09:40 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23033] trunk/launchd/src/launchd.plist.5 Message-ID: <20070206220940.AC51649D133@cvs.opensource.apple.com> Revision: 23033 http://trac.macosforge.org/projects/launchd/changeset/23033 Author: zarzycki@apple.com Date: 2007-02-06 14:09:40 -0800 (Tue, 06 Feb 2007) Log Message: ----------- Errors in "man launchd.plist" Modified Paths: -------------- trunk/launchd/src/launchd.plist.5 Modified: trunk/launchd/src/launchd.plist.5 =================================================================== --- trunk/launchd/src/launchd.plist.5 2007-02-06 19:16:25 UTC (rev 23032) +++ trunk/launchd/src/launchd.plist.5 2007-02-06 22:09:40 UTC (rev 23033) @@ -180,7 +180,7 @@ This key lets one override the default throttling policy imposed on jobs by .Nm launchd . The value is in seconds, and by default, jobs will not be spawned more than once every 10 seconds. -The principle behind this is that jobs should linger around just in case their needed again in the near future. This not only +The principle behind this is that jobs should linger around just in case they are needed again in the near future. This not only reduces the latency of responses, but it encourages developers to amortize the cost of program invocation. .It Sy InitGroups This optional key specifies whether the job should have -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070206/f78e0ddd/attachment.html From source_changes at macosforge.org Tue Feb 6 14:10:42 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23034] tags/launchd-192/ Message-ID: <20070206221042.528C149D180@cvs.opensource.apple.com> Revision: 23034 http://trac.macosforge.org/projects/launchd/changeset/23034 Author: zarzycki@apple.com Date: 2007-02-06 14:10:42 -0800 (Tue, 06 Feb 2007) Log Message: ----------- "Tagging launchd-192 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-192/ Copied: tags/launchd-192 (from rev 23033, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070206/1be386e3/attachment.html From source_changes at macosforge.org Wed Feb 7 08:34:09 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23035] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070207163409.A35C249E0B4@cvs.opensource.apple.com> Revision: 23035 http://trac.macosforge.org/projects/launchd/changeset/23035 Author: zarzycki@apple.com Date: 2007-02-07 08:34:09 -0800 (Wed, 07 Feb 2007) Log Message: ----------- spurious logging from the libraries used by the various importers 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-02-06 22:10:42 UTC (rev 23034) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-07 16:34:09 UTC (rev 23035) @@ -1803,7 +1803,7 @@ job_assumes(j, socketpair(AF_UNIX, SOCK_STREAM, 0, execspair) != -1); - if (job_assumes(j, pipe(oepair) != -1)) { + if (!j->legacy_mach_job && job_assumes(j, pipe(oepair) != -1)) { j->log_redirect_fd = _fd(oepair[0]); job_assumes(j, fcntl(j->log_redirect_fd, F_SETFL, O_NONBLOCK) != -1); job_assumes(j, kevent_mod(j->log_redirect_fd, EVFILT_READ, EV_ADD, 0, 0, j) != -1); @@ -1822,9 +1822,11 @@ } 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); + if (!j->legacy_mach_job) { + 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)); @@ -1845,7 +1847,9 @@ job_start_child(j); break; default: - job_assumes(j, close(oepair[1]) != -1); + if (!j->legacy_mach_job) { + job_assumes(j, close(oepair[1]) != -1); + } j->p = c; j->forkfd = _fd(execspair[0]); job_assumes(j, close(execspair[1]) == 0); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070207/0bcd87af/attachment.html From source_changes at macosforge.org Wed Feb 7 09:39:53 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23036] trunk/launchd/src/StartupItems Message-ID: <20070207173953.0491F49E19B@cvs.opensource.apple.com> Revision: 23036 http://trac.macosforge.org/projects/launchd/changeset/23036 Author: zarzycki@apple.com Date: 2007-02-07 09:39:53 -0800 (Wed, 07 Feb 2007) Log Message: ----------- Remove the IPServices StartupItem Removed Paths: ------------- trunk/launchd/src/StartupItems/IPServices trunk/launchd/src/StartupItems/IPServices.plist Deleted: trunk/launchd/src/StartupItems/IPServices =================================================================== --- trunk/launchd/src/StartupItems/IPServices 2007-02-07 16:34:09 UTC (rev 23035) +++ trunk/launchd/src/StartupItems/IPServices 2007-02-07 17:39:53 UTC (rev 23036) @@ -1,30 +0,0 @@ -#!/bin/sh - -## -# IP Services -## - -[ -f /System/Library/LaunchDaemons/com.apache.httpd.plist ] && exit 0 - -. /etc/rc.common - -StartService () -{ - if [ -a /etc/com.apple.named.conf.proxy ] - then - echo "Starting Internet address sharing" - /usr/libexec/InternetSharing - fi -} - -StopService () -{ - return 0 -} - -RestartService () -{ - return 0 -} - -RunService "$1" Deleted: trunk/launchd/src/StartupItems/IPServices.plist =================================================================== --- trunk/launchd/src/StartupItems/IPServices.plist 2007-02-07 16:34:09 UTC (rev 23035) +++ trunk/launchd/src/StartupItems/IPServices.plist 2007-02-07 17:39:53 UTC (rev 23036) @@ -1,5 +0,0 @@ -{ - Description = "Internet services"; - Provides = ("Super Server", "Config Server"); - Uses = ("mDNSResponder", "Portmap"); -} -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070207/2b38817e/attachment.html From source_changes at macosforge.org Wed Feb 7 10:26:57 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23037] trunk/launchd/src Message-ID: <20070207182657.8892E49E1E3@cvs.opensource.apple.com> Revision: 23037 http://trac.macosforge.org/projects/launchd/changeset/23037 Author: zarzycki@apple.com Date: 2007-02-07 10:26:57 -0800 (Wed, 07 Feb 2007) Log Message: ----------- job_export_all() crash via launchd's Unix IPC Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_core_logic.h Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-07 17:39:53 UTC (rev 23036) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-07 18:26:57 UTC (rev 23037) @@ -976,9 +976,7 @@ return NULL; } - job_dispatch(j, false); - - return j; + return job_dispatch(j, false); } launch_data_t @@ -1641,19 +1639,19 @@ void jobmgr_dispatch_all(jobmgr_t jm) { - jobmgr_t jmi; - job_t ji; + jobmgr_t jmi, jmn; + job_t ji, jn; - SLIST_FOREACH(jmi, &jm->submgrs, sle) { + SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { jobmgr_dispatch_all(jmi); } - SLIST_FOREACH(ji, &jm->jobs, sle) { + SLIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { job_dispatch(ji, false); } } -void +job_t job_dispatch(job_t j, bool kickstart) { /* @@ -1664,15 +1662,18 @@ * * This is a classic example. The act of dispatching a job may delete it. */ - if (job_active(j)) { - return; - } else if (job_useless(j)) { - job_remove(j); - } else if (kickstart || job_keepalive(j)) { - job_start(j); - } else { - job_watch(j); + if (!job_active(j)) { + if (job_useless(j)) { + job_remove(j); + return NULL; + } else if (kickstart || job_keepalive(j)) { + job_start(j); + } else { + job_watch(j); + } } + + return j; } void @@ -3468,6 +3469,7 @@ } } + /* We don't need the _SAFE version because we return after the job_dispatch() */ SLIST_FOREACH(ji, &jm->jobs, sle) { SLIST_FOREACH(ms, &ji->machservices, sle) { if (ms->port != p) { @@ -3613,11 +3615,11 @@ void jobmgr_dispatch_all_semaphores(jobmgr_t jm) { - jobmgr_t jmi; + jobmgr_t jmi, jmn; job_t ji, jn; - SLIST_FOREACH(jmi, &jm->submgrs, sle) { + SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { jobmgr_dispatch_all_semaphores(jmi); } @@ -3979,10 +3981,12 @@ ms->must_match_uid = true; ms->hide = true; - job_dispatch(ji, false); + ji = job_dispatch(ji, false); } - *up_cont = machservice_port(SLIST_FIRST(&ji->machservices)); + if (job_assumes(j, ji != NULL)) { + *up_cont = machservice_port(SLIST_FIRST(&ji->machservices)); + } return 0; } @@ -4538,8 +4542,12 @@ memcpy(jr->j_binpref, bin_pref, sizeof(jr->j_binpref)); jr->j_binpref_cnt = binpref_cnt; - job_dispatch(jr, true); + jr = job_dispatch(jr, true); + if (!job_assumes(j, jr != NULL)) { + return BOOTSTRAP_NO_MEMORY; + } + if (!job_setup_machport(jr)) { job_remove(jr); return BOOTSTRAP_NO_MEMORY; Modified: trunk/launchd/src/launchd_core_logic.h =================================================================== --- trunk/launchd/src/launchd_core_logic.h 2007-02-07 17:39:53 UTC (rev 23036) +++ trunk/launchd/src/launchd_core_logic.h 2007-02-07 18:26:57 UTC (rev 23037) @@ -43,7 +43,7 @@ launch_data_t job_export_all(void); job_t job_new(jobmgr_t jm, const char *label, const char *prog, const char *const *argv, const char *stdinpath); -void job_dispatch(job_t j, bool kickstart); +job_t job_dispatch(job_t j, bool kickstart); /* returns j on success, NULL on job removal */ bool job_active(job_t j); launch_data_t job_export(job_t j); void job_stop(job_t j); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070207/a531c817/attachment.html From source_changes at macosforge.org Wed Feb 7 12:19:37 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23038] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070207201937.2E1D149E453@cvs.opensource.apple.com> Revision: 23038 http://trac.macosforge.org/projects/launchd/changeset/23038 Author: zarzycki@apple.com Date: 2007-02-07 12:19:36 -0800 (Wed, 07 Feb 2007) Log Message: ----------- posix_spawn() isn't like the rest of the Unix APIs when it comes to errno. 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-02-07 18:26:57 UTC (rev 23037) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-07 20:19:36 UTC (rev 23038) @@ -1933,10 +1933,10 @@ } if (j->prog) { - posix_spawn(&junk_pid, j->inetcompat ? file2exec : j->prog, NULL, &spattr, (char *const*)argv, environ); + errno = posix_spawn(&junk_pid, j->inetcompat ? file2exec : j->prog, NULL, &spattr, (char *const*)argv, environ); job_log_error(j, LOG_ERR, "posix_spawn(\"%s\", ...)", j->prog); } else { - posix_spawnp(&junk_pid, j->inetcompat ? file2exec : argv[0], NULL, &spattr, (char *const*)argv, environ); + errno = posix_spawnp(&junk_pid, j->inetcompat ? file2exec : argv[0], NULL, &spattr, (char *const*)argv, environ); job_log_error(j, LOG_ERR, "posix_spawnp(\"%s\", ...)", argv[0]); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070207/0829ef5c/attachment.html From source_changes at macosforge.org Wed Feb 7 13:07:49 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23039] trunk/launchd/src/launchd.c Message-ID: <20070207210749.DE2D649E4E8@cvs.opensource.apple.com> Revision: 23039 http://trac.macosforge.org/projects/launchd/changeset/23039 Author: zarzycki@apple.com Date: 2007-02-07 13:07:49 -0800 (Wed, 07 Feb 2007) Log Message: ----------- Clean up. Now if we can properly make our reflector threads go away, we should be able to go to single user mode again. :-) Modified Paths: -------------- trunk/launchd/src/launchd.c Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-02-07 20:19:36 UTC (rev 23038) +++ trunk/launchd/src/launchd.c 2007-02-07 21:07:49 UTC (rev 23039) @@ -300,11 +300,11 @@ * to skip it. */ if (!h && stat(ldconf, &sb) == 0) { - job_dispatch(rlcj, true); + rlcj = job_dispatch(rlcj, true); } if (fbj) { - job_dispatch(fbj, true); + fbj = job_dispatch(fbj, true); } char *doom_why = "at instruction"; @@ -474,24 +474,15 @@ void launchd_single_user(void) { - int tries; + syslog(LOG_NOTICE, "Going to single-user mode"); + re_exec_in_single_user_mode = true; + launchd_shutdown(); - kill(-1, SIGTERM); + sleep(3); - for (tries = 0; tries < 10; tries++) { - sleep(1); - if (kill(-1, 0) == -1 && errno == ESRCH) { - goto out; - } - } - - syslog(LOG_WARNING, "Gave up waiting for processes to exit while going to single user mode, sending SIGKILL"); kill(-1, SIGKILL); - -out: - re_exec_in_single_user_mode = true; } static void signal_callback(void *obj __attribute__((unused)), struct kevent *kev) @@ -501,7 +492,7 @@ switch (kev->ident) { case SIGHUP: if (rlcj) { - job_dispatch(rlcj, true); + rlcj = job_dispatch(rlcj, true); } break; case SIGTERM: @@ -691,6 +682,7 @@ exit(EXIT_SUCCESS); } else if (re_exec_in_single_user_mode) { re_exec_in_single_user_mode = false; + kill(-1, SIGKILL); /* One last time, just to clear the room */ launchd_assumes(execl("/sbin/launchd", "/sbin/launchd", "-s", NULL) != -1); } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070207/7917bf4a/attachment.html From source_changes at macosforge.org Wed Feb 7 15:39:59 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23040] trunk/launchd/src Message-ID: <20070207233959.050CC49E7EA@cvs.opensource.apple.com> Revision: 23040 http://trac.macosforge.org/projects/launchd/changeset/23040 Author: zarzycki@apple.com Date: 2007-02-07 15:39:58 -0800 (Wed, 07 Feb 2007) Log Message: ----------- Add a per job exit timeout. 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-02-07 21:07:49 UTC (rev 23039) +++ trunk/launchd/src/launchd.plist.5 2007-02-07 23:39:58 UTC (rev 23040) @@ -176,6 +176,10 @@ The recommended idle time out (in seconds) to pass to the job. If no value is specified, a default time out will be supplied by .Nm launchd for use by the job at check in time. +.It Sy ExitTimeOut +The amount of time +.Nm launchd +waits before sending a SIGKILL signal. The default value is 20 seconds. The value zero is interpreted as infinity. .It Sy ThrottleInterval This key lets one override the default throttling policy imposed on jobs by .Nm launchd . Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-07 21:07:49 UTC (rev 23039) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-07 23:39:58 UTC (rev 23040) @@ -87,6 +87,7 @@ #define LAUNCHD_MIN_JOB_RUN_TIME 10 #define LAUNCHD_ADVISABLE_IDLE_TIMEOUT 30 +#define LAUNCHD_DEFAULT_EXIT_TIMEOUT 20 extern char **environ; @@ -254,8 +255,10 @@ int forkfd; int log_redirect_fd; int nice; - int timeout; + unsigned int timeout; + unsigned int exit_timeout; int stdout_err_fd; + struct timeval sent_sigterm_time; time_t start_time; time_t min_run_time; unsigned int start_interval; @@ -405,6 +408,11 @@ { if (j->p) { job_assumes(j, kill(j->p, SIGTERM) != -1); + job_assumes(j, gettimeofday(&j->sent_sigterm_time, NULL) != -1); + if (j->exit_timeout) { + job_assumes(j, kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, + EV_ADD|EV_ONESHOT, NOTE_SECONDS, j->exit_timeout, j) != -1); + } } } @@ -516,9 +524,6 @@ if (!job_active(ji)) { job_remove(ji); } else { - if (debug_shutdown_hangs) { - job_assumes(ji, kevent_mod((uintptr_t)ji, EVFILT_TIMER, EV_ADD|EV_ONESHOT, NOTE_SECONDS, 8, ji) != -1); - } job_stop(ji); } } @@ -662,6 +667,9 @@ if (j->start_interval) { job_assumes(j, kevent_mod((uintptr_t)&j->start_interval, EVFILT_TIMER, EV_DELETE, 0, 0, NULL) != -1); } + if (j->exit_timeout) { + kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); + } kevent_mod((uintptr_t)j, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); free(j); @@ -907,6 +915,7 @@ j->mgr = jm; j->min_run_time = LAUNCHD_MIN_JOB_RUN_TIME; j->timeout = LAUNCHD_ADVISABLE_IDLE_TIMEOUT; + j->exit_timeout = LAUNCHD_DEFAULT_EXIT_TIMEOUT; j->currently_ignored = true; j->ondemand = true; j->checkedin = true; @@ -1162,6 +1171,16 @@ job_import_integer(job_t j, const char *key, long long value) { switch (key[0]) { + case 'e': + case 'E': + if (strcasecmp(key, LAUNCH_JOBKEY_EXITTIMEOUT) == 0) { + if (value < 0) { + job_log(j, LOG_WARNING, "Exit timeout less zero. Ignoring."); + } else { + j->exit_timeout = value; + } + } + break; case 'n': case 'N': if (strcasecmp(key, LAUNCH_JOBKEY_NICE) == 0) { @@ -1577,6 +1596,7 @@ void job_reap(job_t j) { + struct timeval tve, tvd; struct rusage ru; int status; @@ -1596,12 +1616,24 @@ return; } + job_assumes(j, gettimeofday(&tve, NULL) != -1); + if (j->wait_reply_port) { job_log(j, LOG_DEBUG, "MPM wait reply being sent"); job_assumes(j, job_mig_wait_reply(j->wait_reply_port, 0, status) == 0); j->wait_reply_port = MACH_PORT_NULL; } + if (j->sent_sigterm_time.tv_sec) { + double delta; + + timersub(&tve, &j->sent_sigterm_time, &tvd); + + delta = (double)tvd.tv_sec + (double)tvd.tv_usec / (double)1000000; + + job_log(j, tvd.tv_sec ? LOG_NOTICE : LOG_INFO, "Exited %f seconds after SIGTERM was sent", delta); + } + timeradd(&ru.ru_utime, &j->ru.ru_utime, &j->ru.ru_utime); timeradd(&ru.ru_stime, &j->ru.ru_stime, &j->ru.ru_stime); j->ru.ru_maxrss += ru.ru_maxrss; @@ -1724,14 +1756,14 @@ } break; case EVFILT_TIMER: - if ((uintptr_t)j == kev->ident) { - if (j->p && job_assumes(j, debug_shutdown_hangs)) { + if ((uintptr_t)j == kev->ident || (uintptr_t)&j->start_interval == kev->ident) { + job_dispatch(j, true); + } else if ((uintptr_t)&j->exit_timeout == kev->ident) { + if (debug_shutdown_hangs) { job_force_sampletool(j); - } else { - job_dispatch(j, true); } - } else if ((uintptr_t)&j->start_interval == kev->ident) { - job_dispatch(j, true); + job_log(j, LOG_WARNING, "Exit timeout elapsed (%u seconds). Killing.", j->exit_timeout); + job_assumes(j, kill(j->p, SIGKILL) != -1); } else { calendarinterval_callback(j, kev); } @@ -1788,6 +1820,9 @@ job_log(j, LOG_DEBUG, "Starting"); + j->sent_sigterm_time.tv_sec = 0; + j->sent_sigterm_time.tv_usec = 0; + /* FIXME, using stdinpath is a hack for re-reading the conf file */ if (j->stdinpath) { sipc = true; Modified: trunk/launchd/src/liblaunch_public.h =================================================================== --- trunk/launchd/src/liblaunch_public.h 2007-02-07 21:07:49 UTC (rev 23039) +++ trunk/launchd/src/liblaunch_public.h 2007-02-07 23:39:58 UTC (rev 23040) @@ -58,6 +58,7 @@ #define LAUNCH_JOBKEY_USERNAME "UserName" #define LAUNCH_JOBKEY_GROUPNAME "GroupName" #define LAUNCH_JOBKEY_TIMEOUT "TimeOut" +#define LAUNCH_JOBKEY_EXITTIMEOUT "ExitTimeOut" #define LAUNCH_JOBKEY_INITGROUPS "InitGroups" #define LAUNCH_JOBKEY_SOCKETS "Sockets" #define LAUNCH_JOBKEY_MACHSERVICES "MachServices" -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070207/270c1b4a/attachment.html From source_changes at macosforge.org Wed Feb 7 17:28:03 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23041] trunk/launchd/src/launchd.c Message-ID: <20070208012803.9428049EA19@cvs.opensource.apple.com> Revision: 23041 http://trac.macosforge.org/projects/launchd/changeset/23041 Author: zarzycki@apple.com Date: 2007-02-07 17:28:03 -0800 (Wed, 07 Feb 2007) Log Message: ----------- With this change, you can now: "sudo kill -TERM 1" and the machine will gracefully power off. Modified Paths: -------------- trunk/launchd/src/launchd.c Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-02-07 23:39:58 UTC (rev 23040) +++ trunk/launchd/src/launchd.c 2007-02-08 01:28:03 UTC (rev 23041) @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -678,12 +679,14 @@ if (shutdown_in_progress && jobmgr_is_idle(root_jobmgr)) { shutdown_in_progress = false; - if (getpid() != 1) { + if (getpid() == 1) { + if (re_exec_in_single_user_mode) { + kill(-1, SIGKILL); /* One last time, just to clear the room */ + launchd_assumes(execl("/sbin/launchd", "/sbin/launchd", "-s", NULL) != -1); + } + launchd_assumes(reboot(RB_HALT) != -1); + } else { exit(EXIT_SUCCESS); - } else if (re_exec_in_single_user_mode) { - re_exec_in_single_user_mode = false; - kill(-1, SIGKILL); /* One last time, just to clear the room */ - launchd_assumes(execl("/sbin/launchd", "/sbin/launchd", "-s", NULL) != -1); } } if (getpid() == 1) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070207/0ce0a957/attachment.html From source_changes at macosforge.org Thu Feb 8 07:21:27 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23042] trunk/launchd/src Message-ID: <20070208152127.67EE949F223@cvs.opensource.apple.com> Revision: 23042 http://trac.macosforge.org/projects/launchd/changeset/23042 Author: zarzycki@apple.com Date: 2007-02-08 07:21:26 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Add plist option to mimic the kernel's KERN_PROCDELAYTERM Modified Paths: -------------- trunk/launchd/src/launchd.c trunk/launchd/src/launchd.h trunk/launchd/src/launchd.plist.5 trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_core_logic.h trunk/launchd/src/liblaunch_public.h Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-02-08 01:28:03 UTC (rev 23041) +++ trunk/launchd/src/launchd.c 2007-02-08 15:21:26 UTC (rev 23042) @@ -110,7 +110,7 @@ static const char *launchctl_bootstrap_tool[] = { "/bin/launchctl", /* "bootstrap", */ NULL }; sigset_t blocked_signals = 0; -bool shutdown_in_progress = false; +static bool shutdown_in_progress = false; bool debug_shutdown_hangs = false; bool network_up = false; int batch_disabler_count = 0; @@ -469,7 +469,7 @@ rlcj = NULL; - jobmgr_remove_all_inactive(root_jobmgr); + root_jobmgr = jobmgr_shutdown(root_jobmgr); } void @@ -676,7 +676,7 @@ void launchd_post_kevent(void) { - if (shutdown_in_progress && jobmgr_is_idle(root_jobmgr)) { + if (shutdown_in_progress && (!root_jobmgr || jobmgr_is_idle(root_jobmgr))) { shutdown_in_progress = false; if (getpid() == 1) { Modified: trunk/launchd/src/launchd.h =================================================================== --- trunk/launchd/src/launchd.h 2007-02-08 01:28:03 UTC (rev 23041) +++ trunk/launchd/src/launchd.h 2007-02-08 15:21:26 UTC (rev 23042) @@ -34,7 +34,6 @@ extern kq_callback kqsimple_zombie_reaper; extern sigset_t blocked_signals; -extern bool shutdown_in_progress; extern bool debug_shutdown_hangs; extern bool network_up; extern int batch_disabler_count; Modified: trunk/launchd/src/launchd.plist.5 =================================================================== --- trunk/launchd/src/launchd.plist.5 2007-02-08 01:28:03 UTC (rev 23041) +++ trunk/launchd/src/launchd.plist.5 2007-02-08 15:21:26 UTC (rev 23042) @@ -271,6 +271,12 @@ This optional key specifies what .Xr nice 3 value should be applied to the daemon. +.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. .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-02-08 01:28:03 UTC (rev 23041) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-08 15:21:26 UTC (rev 23042) @@ -199,7 +199,7 @@ char *jm_stdout; char *jm_stderr; unsigned int global_on_demand_cnt; - unsigned int transfer_bstrap:1; + unsigned int transfer_bstrap:1, sent_stop_to_hopeful_jobs:1, shutting_down:1; char name[0]; }; @@ -208,6 +208,7 @@ static jobmgr_t jobmgr_new(jobmgr_t jm, mach_port_t requestorport, mach_port_t checkin_port); static jobmgr_t jobmgr_parent(jobmgr_t jm); +static jobmgr_t jobmgr_tickle(jobmgr_t jm); static void jobmgr_dispatch_all(jobmgr_t jm); static job_t jobmgr_new_anonymous(jobmgr_t jm); static job_t job_mig_intran2(jobmgr_t jm, mach_port_t p); @@ -268,7 +269,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, setnice:1; + currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1, hopefully_exits_last:1; char label[0]; }; @@ -510,23 +511,27 @@ return r; } -void -jobmgr_remove_all_inactive(jobmgr_t jm) +jobmgr_t +jobmgr_shutdown(jobmgr_t jm) { jobmgr_t jmi, jmn; job_t ji, jn; SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { - jobmgr_remove_all_inactive(jmi); + jobmgr_shutdown(jmi); } SLIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { if (!job_active(ji)) { job_remove(ji); - } else { + } else if (!ji->hopefully_exits_last) { job_stop(ji); } } + + jm->shutting_down = true; + + return jobmgr_tickle(jm); } void @@ -595,10 +600,6 @@ } } - if (job_assumes(j, j->mgr)) { - SLIST_REMOVE(&j->mgr->jobs, j, job_s, sle); - } - if (j->forkfd) { job_assumes(j, close(j->forkfd) != -1); } @@ -672,6 +673,12 @@ } kevent_mod((uintptr_t)j, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); + + if (job_assumes(j, j->mgr)) { + SLIST_REMOVE(&j->mgr->jobs, j, job_s, sle); + jobmgr_tickle(j->mgr); + } + free(j); } @@ -894,7 +901,7 @@ int i, cc = 0; job_t j; - if (shutdown_in_progress) { + if (jm->shutting_down) { errno = EINVAL; return NULL; } @@ -1036,6 +1043,12 @@ j->debug = value; } break; + case 'h': + case 'H': + if (strcasecmp(key, LAUNCH_JOBKEY_HOPEFULLYEXITSLAST) == 0) { + j->hopefully_exits_last = value; + } + break; case 's': case 'S': if (strcasecmp(key, LAUNCH_JOBKEY_SESSIONCREATE) == 0) { @@ -2805,7 +2818,7 @@ } job_log(j, LOG_INFO, "Exited. Was only configured to run once."); return true; - } else if (shutdown_in_progress) { + } else if (j->mgr->shutting_down) { job_log(j, LOG_INFO, "Exited while shutdown in progress."); return true; } else if (!j->checkedin && (!SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices))) { @@ -3162,6 +3175,35 @@ } } +jobmgr_t +jobmgr_tickle(jobmgr_t jm) +{ + job_t ji; + + if (jm->sent_stop_to_hopeful_jobs || !jm->shutting_down) { + return jm; + } + + SLIST_FOREACH(ji, &jm->jobs, sle) { + if (ji->p && !ji->hopefully_exits_last) { + return jm; + } + } + + SLIST_FOREACH(ji, &jm->jobs, sle) { + job_stop(ji); + } + + jm->sent_stop_to_hopeful_jobs = true; + + if (jobmgr_is_idle(jm)) { + jobmgr_remove(jm); + return NULL; + } + + return jm; +} + bool jobmgr_is_idle(jobmgr_t jm) { @@ -3321,11 +3363,7 @@ */ if (jm->req_port == port) { - if (jm == root_jobmgr) { - launchd_shutdown(); - } else { - return jobmgr_remove(jm); - } + jobmgr_shutdown(jm); } SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { Modified: trunk/launchd/src/launchd_core_logic.h =================================================================== --- trunk/launchd/src/launchd_core_logic.h 2007-02-08 01:28:03 UTC (rev 23041) +++ trunk/launchd/src/launchd_core_logic.h 2007-02-08 15:21:26 UTC (rev 23042) @@ -32,7 +32,7 @@ void jobmgr_set_stdout(jobmgr_t jm, const char *what); 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); +jobmgr_t jobmgr_shutdown(jobmgr_t jm); 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); Modified: trunk/launchd/src/liblaunch_public.h =================================================================== --- trunk/launchd/src/liblaunch_public.h 2007-02-08 01:28:03 UTC (rev 23041) +++ trunk/launchd/src/liblaunch_public.h 2007-02-08 15:21:26 UTC (rev 23042) @@ -78,6 +78,7 @@ #define LAUNCH_JOBKEY_USERENVIRONMENTVARIABLES "UserEnvironmentVariables" #define LAUNCH_JOBKEY_UMASK "Umask" #define LAUNCH_JOBKEY_NICE "Nice" +#define LAUNCH_JOBKEY_HOPEFULLYEXITSLAST "HopefullyExitsLast" #define LAUNCH_JOBKEY_LOWPRIORITYIO "LowPriorityIO" #define LAUNCH_JOBKEY_SESSIONCREATE "SessionCreate" #define LAUNCH_JOBKEY_SOFTRESOURCELIMITS "SoftResourceLimits" -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070208/e8ef388f/attachment.html From source_changes at macosforge.org Thu Feb 8 07:34:55 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23043] trunk/launchd/src/shutdown_debugger.c Message-ID: <20070208153455.2EA3049F235@cvs.opensource.apple.com> Revision: 23043 http://trac.macosforge.org/projects/launchd/changeset/23043 Author: zarzycki@apple.com Date: 2007-02-08 07:34:54 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Shutdown sampling is holding up system shutdown Modified Paths: -------------- trunk/launchd/src/shutdown_debugger.c Modified: trunk/launchd/src/shutdown_debugger.c =================================================================== --- trunk/launchd/src/shutdown_debugger.c 2007-02-08 15:21:26 UTC (rev 23042) +++ trunk/launchd/src/shutdown_debugger.c 2007-02-08 15:34:54 UTC (rev 23043) @@ -33,6 +33,7 @@ static void populate_proc_list(void); static void debug_machports(pid_t pid, const char *pname); static void debug_machports2(pid_t pid, FILE *where); +static void do_stackshot(void); static int kq; @@ -70,6 +71,8 @@ closedir(thedir); + do_stackshot(); + assert((kq = kqueue()) != -1); debug_machports(1, "launchd"); @@ -524,3 +527,11 @@ fprintf(where, "Finished.\n"); return; } + +void +do_stackshot(void) +{ + /* yes, we really mean to exec without fork at this point in time */ + execl("/usr/libexec/stackshot", "/usr/libexec/stackshot", "-i", "-f", "./shutdown-stackshot.log", NULL); + _exit(EXIT_FAILURE); +} -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070208/e0ed04df/attachment.html From source_changes at macosforge.org Thu Feb 8 09:26:17 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23044] trunk/launchd/src/StartupItems Message-ID: <20070208172617.AF54049F2B6@cvs.opensource.apple.com> Revision: 23044 http://trac.macosforge.org/projects/launchd/changeset/23044 Author: zarzycki@apple.com Date: 2007-02-08 09:26:17 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Christopher Ryan says that I can remove this right away. Removed Paths: ------------- trunk/launchd/src/StartupItems/AppleShare trunk/launchd/src/StartupItems/AppleShare.plist Deleted: trunk/launchd/src/StartupItems/AppleShare =================================================================== --- trunk/launchd/src/StartupItems/AppleShare 2007-02-08 15:34:54 UTC (rev 23043) +++ trunk/launchd/src/StartupItems/AppleShare 2007-02-08 17:26:17 UTC (rev 23044) @@ -1,29 +0,0 @@ -#!/bin/sh - -## -# Apple File Protocol -## - -[ -f /System/Library/LaunchDaemons/com.apple.AppleFileServer.plist ] && exit 0 - -. /etc/rc.common - -StartService () -{ - if [ "${AFPSERVER:=-NO-}" = "-YES-" ]; then - echo "Starting Apple File Service" - /usr/sbin/AppleFileServer - fi -} - -StopService () -{ - return 0 -} - -RestartService () -{ - return 0 -} - -RunService "$1" Deleted: trunk/launchd/src/StartupItems/AppleShare.plist =================================================================== --- trunk/launchd/src/StartupItems/AppleShare.plist 2007-02-08 15:34:54 UTC (rev 23043) +++ trunk/launchd/src/StartupItems/AppleShare.plist 2007-02-08 17:26:17 UTC (rev 23044) @@ -1,5 +0,0 @@ -{ - Description = "Apple File Service"; - Provides = ("Apple File Service"); - Requires = ("Disks"); -} -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070208/76c1b97d/attachment.html From source_changes at macosforge.org Thu Feb 8 10:04:07 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23045] trunk/launchd/src Message-ID: <20070208180407.8B82049F2F5@cvs.opensource.apple.com> Revision: 23045 http://trac.macosforge.org/projects/launchd/changeset/23045 Author: zarzycki@apple.com Date: 2007-02-08 10:04:06 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Dead code deletion. Modified Paths: -------------- trunk/launchd/src/launchd.8 trunk/launchd/src/launchd.c trunk/launchd/src/launchd.h trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd.8 =================================================================== --- trunk/launchd/src/launchd.8 2007-02-08 17:26:17 UTC (rev 23044) +++ trunk/launchd/src/launchd.8 2007-02-08 18:04:06 UTC (rev 23045) @@ -37,14 +37,10 @@ is invoked by the kernel to run as the first process on the system and to further bootstrap the rest of the system. .Sh OPTIONS .Bl -tag -width -indent -.It Fl d -Daemonize. Useful when passing a command to launchd on the command line. .It Fl D Debug. Prints syslog messages to stderr and adjusts logging via .Xr syslog 3 to LOG_DEBUG. -.It Fl S Ar SessionType -Instruct launchd to which session type it is. .El .Sh OPTIONS WHEN RUN AS PID 1 .Bl -tag -width -indent Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-02-08 17:26:17 UTC (rev 23044) +++ trunk/launchd/src/launchd.c 2007-02-08 18:04:06 UTC (rev 23045) @@ -83,12 +83,10 @@ extern char **environ; static void signal_callback(void *, struct kevent *); -static void ppidexit_callback(void); static void debugshutdown_callback(void); static void pfsystem_callback(void *, struct kevent *); static kq_callback kqsignal_callback = signal_callback; -static kq_callback kqppidexit_callback = (kq_callback)ppidexit_callback; static kq_callback kqdebugshutdown_callback = (kq_callback)debugshutdown_callback; static kq_callback kqpfsystem_callback = pfsystem_callback; @@ -123,17 +121,15 @@ SIGTTIN, SIGTTOU, SIGIO, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, SIGWINCH, SIGINFO, SIGUSR1, SIGUSR2 }; - bool sflag = false, dflag = false, Dflag = false; + bool sflag = false, Dflag = false; char ldconf[PATH_MAX] = PID1LAUNCHD_CONF; const char *h = getenv("HOME"); - const char *session_type = NULL; const char *optargs = NULL; - job_t fbj = NULL; struct stat sb; size_t i, checkin_fdcnt = 0; int *checkin_fds = NULL; mach_port_t checkin_mport = MACH_PORT_NULL; - int ch, ker, logopts; + int ch, logopts; testfd_or_openfd(STDIN_FILENO, _PATH_DEVNULL, O_RDONLY); testfd_or_openfd(STDOUT_FILENO, _PATH_DEVNULL, O_WRONLY); @@ -200,14 +196,12 @@ if (getpid() == 1) { optargs = "s"; } else { - optargs = "DS:dh"; + optargs = "Dh"; } while ((ch = getopt(argc, argv, optargs)) != -1) { switch (ch) { - case 'S': session_type = optarg; break; /* what type of session we're creating */ case 'D': Dflag = true; break; /* debug */ - case 'd': dflag = true; break; /* daemonize */ case 's': sflag = true; break; /* single user */ case 'h': usage(stdout); break; /* help */ case '?': /* we should do something with the global optopt variable here */ @@ -222,10 +216,6 @@ /* main phase three: get the party started */ - if (dflag) { - launchd_assumes(daemon(0, 0) == 0); - } - logopts = LOG_PID|LOG_CONS; if (Dflag) { logopts |= LOG_PERROR; @@ -254,10 +244,6 @@ rlcj = job_new(root_jobmgr, READCONF_LABEL, NULL, launchctl_bootstrap_tool, ldconf); launchd_assert(rlcj != NULL); - if (argv[0]) { - fbj = job_new(root_jobmgr, FIRSTBORN_LABEL, NULL, (const char *const *)argv, NULL); - } - if (NULL == getenv("PATH")) { setenv("PATH", _PATH_STDPATH, 1); } @@ -270,27 +256,6 @@ monitor_networking_state(); - if (session_type) { - pid_t pp = getppid(); - - /* As a per session launchd, we need to exit if our parent dies. - * - * Normally, in Unix, SIGHUP would cause us to exit, but we're a - * daemon, and daemons use SIGHUP to signal the need to reread - * configuration files. "Weee." - */ - - if (pp == 1) { - exit(EXIT_SUCCESS); - } - - ker = kevent_mod(pp, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, &kqppidexit_callback); - - if (ker == -1) { - exit(launchd_assumes(errno == ESRCH) ? EXIT_SUCCESS : EXIT_FAILURE); - } - } - /* * We cannot stat() anything in the home directory right now. * @@ -304,10 +269,6 @@ rlcj = job_dispatch(rlcj, true); } - if (fbj) { - fbj = job_dispatch(fbj, true); - } - char *doom_why = "at instruction"; switch (setjmp(doom_doom_doom)) { case 0: @@ -431,17 +392,6 @@ } void -ppidexit_callback(void) -{ - syslog(LOG_INFO, "Parent process exited"); - - launchd_shutdown(); - - /* Let's just bail for now. We should really try to wait for jobs to exit first. */ - exit(EXIT_SUCCESS); -} - -void launchd_shutdown(void) { if (shutdown_in_progress) { Modified: trunk/launchd/src/launchd.h =================================================================== --- trunk/launchd/src/launchd.h 2007-02-08 17:26:17 UTC (rev 23044) +++ trunk/launchd/src/launchd.h 2007-02-08 18:04:06 UTC (rev 23045) @@ -26,7 +26,6 @@ #include "libbootstrap_public.h" #include "launchd_runtime.h" -#define FIRSTBORN_LABEL "com.apple.launchd.firstborn" #define READCONF_LABEL "com.apple.launchd.readconfig" struct kevent; Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-08 17:26:17 UTC (rev 23044) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-08 18:04:06 UTC (rev 23045) @@ -263,10 +263,9 @@ time_t start_time; time_t min_run_time; unsigned int start_interval; - unsigned int checkedin:1, firstborn:1, debug:1, inetcompat:1, inetcompat_wait:1, + unsigned int checkedin:1, anonymous:1, debug:1, inetcompat:1, inetcompat_wait:1, ondemand:1, session_create:1, low_pri_io:1, no_init_groups:1, priv_port_has_senders:1, - importing_global_env:1, importing_hard_limits:1, setmask:1, legacy_mach_job:1, runatload:1, - anonymous:1; + importing_global_env:1, importing_hard_limits:1, setmask:1, legacy_mach_job:1, runatload: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, setnice:1, hopefully_exits_last:1; @@ -926,7 +925,6 @@ j->currently_ignored = true; j->ondemand = true; j->checkedin = true; - j->firstborn = (strcmp(label, FIRSTBORN_LABEL) == 0); if (prog) { j->prog = strdup(prog); @@ -1760,13 +1758,7 @@ switch (kev->filter) { case EVFILT_PROC: job_reap(j); - - if (j->firstborn) { - job_log(j, LOG_DEBUG, "first born died, begin shutdown"); - launchd_shutdown(); - } else { - job_dispatch(j, false); - } + job_dispatch(j, false); break; case EVFILT_TIMER: if ((uintptr_t)j == kev->ident || (uintptr_t)&j->start_interval == kev->ident) { @@ -1879,14 +1871,6 @@ 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)); - if (j->firstborn) { - setpgid(getpid(), getpid()); - if (isatty(STDIN_FILENO)) { - if (tcsetpgrp(STDIN_FILENO, getpid()) == -1) { - job_log_error(j, LOG_WARNING, "tcsetpgrp()"); - } - } - } if (sipc) { job_assumes(j, close(spair[0]) == 0); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070208/780106ff/attachment.html From source_changes at macosforge.org Thu Feb 8 14:39:50 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:39 2007 Subject: [launchd-changes] [23046] trunk/launchd/src Message-ID: <20070208223950.B40FC49F7C0@cvs.opensource.apple.com> Revision: 23046 http://trac.macosforge.org/projects/launchd/changeset/23046 Author: zarzycki@apple.com Date: 2007-02-08 14:39:50 -0800 (Thu, 08 Feb 2007) Log Message: ----------- More shutdown logic clean up and sanity checking. 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-02-08 18:04:06 UTC (rev 23045) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-08 22:39:50 UTC (rev 23046) @@ -516,6 +516,8 @@ jobmgr_t jmi, jmn; job_t ji, jn; + jobmgr_log(jm, LOG_DEBUG, "Beginning job manager shutdown"); + SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { jobmgr_shutdown(jmi); } @@ -539,18 +541,22 @@ jobmgr_t jmi; job_t ji; - while ((jmi = SLIST_FIRST(&jm->submgrs))) { - jobmgr_remove(jmi); + jobmgr_log(jm, LOG_DEBUG, "Removed job manager"); + + if (!jobmgr_assumes(jm, SLIST_EMPTY(&jm->submgrs))) { + while ((jmi = SLIST_FIRST(&jm->submgrs))) { + jobmgr_remove(jmi); + } } + /* We should have one job left and it should be the anonymous job */ + ji = SLIST_FIRST(&jm->jobs); + jobmgr_assumes(jm, ji && ji == jm->anonj && (SLIST_NEXT(ji, sle) == NULL)); + while ((ji = SLIST_FIRST(&jm->jobs))) { job_remove(ji); } - if (jm->parentmgr) { - SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); - } - if (jm->req_port) { jobmgr_assumes(jm, launchd_mport_deallocate(jm->req_port) == KERN_SUCCESS); } @@ -570,6 +576,11 @@ if (jm->jm_stderr) { free(jm->jm_stderr); } + + if (jm->parentmgr) { + SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); + jobmgr_tickle(jm->parentmgr); + } free(jm); } @@ -590,20 +601,16 @@ job_set_global_on_demand(j, false); } - if (j->p && !j->anonymous) { - if (kevent_mod(j->p, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, &kqsimple_zombie_reaper) == -1) { - job_reap(j); - } else { - /* we've attached the simple zombie reaper, we're going to delete the job before it is dead */ - job_stop(j); - } + if (!job_assumes(j, j->p == 0)) { + job_assumes(j, kill(j->p, SIGKILL) != -1); + job_reap(j); } - if (j->forkfd) { + if (!job_assumes(j, j->forkfd == 0)) { job_assumes(j, close(j->forkfd) != -1); } - if (j->log_redirect_fd) { + if (!job_assumes(j, j->log_redirect_fd == 0)) { job_assumes(j, close(j->log_redirect_fd) != -1); } @@ -2803,7 +2810,16 @@ job_log(j, LOG_INFO, "Exited. Was only configured to run once."); return true; } else if (j->mgr->shutting_down) { - job_log(j, LOG_INFO, "Exited while shutdown in progress."); + unsigned int cnt = 0; + job_t ji; + + SLIST_FOREACH(ji, &j->mgr->jobs, sle) { + if (ji->p) { + cnt++; + } + } + + job_log(j, LOG_INFO, "Exited while shutdown in progress. Processes remaining: %u", cnt); return true; } else if (!j->checkedin && (!SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices))) { job_log(j, LOG_WARNING, "Failed to check-in!"); @@ -3193,6 +3209,10 @@ { job_t ji; + if (!SLIST_EMPTY(&jm->submgrs)) { + return false; + } + SLIST_FOREACH(ji, &jm->jobs, sle) { if (ji->p) { return false; @@ -3320,6 +3340,8 @@ jobmgr_assumes(jmr, jmr->anonj != NULL); + jobmgr_log(jmr, LOG_DEBUG, "Created job manager"); + return jmr; out_bad: Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-08 18:04:06 UTC (rev 23045) +++ trunk/launchd/src/launchd_runtime.c 2007-02-08 22:39:50 UTC (rev 23046) @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -578,7 +579,7 @@ /* XXX - So very gross */ if (gc_this_jobmgr) { - jobmgr_remove(gc_this_jobmgr); + jobmgr_shutdown(gc_this_jobmgr); gc_this_jobmgr = NULL; } @@ -674,7 +675,9 @@ pthread_mutex_lock(&ourlock); if (ourlogfile == NULL) { + rename("/var/log/launchd_raw.log", "/var/log/launchd_raw-old.log"); ourlogfile = fopen("/var/log/launchd_raw.log", "a"); + chmod("/var/log/launchd_raw.log", DEFFILEMODE); } pthread_mutex_unlock(&ourlock); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070208/d62095a8/attachment.html From source_changes at macosforge.org Thu Feb 8 14:43:27 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23047] tags/launchd-193/ Message-ID: <20070208224327.DB01049F7C6@cvs.opensource.apple.com> Revision: 23047 http://trac.macosforge.org/projects/launchd/changeset/23047 Author: zarzycki@apple.com Date: 2007-02-08 14:43:27 -0800 (Thu, 08 Feb 2007) Log Message: ----------- "Tagging launchd-193 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-193/ Copied: tags/launchd-193 (from rev 23046, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070208/3e686ac6/attachment.html From source_changes at macosforge.org Thu Feb 8 14:48:29 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23048] trunk/launchd/src Message-ID: <20070208224829.6077349F7E0@cvs.opensource.apple.com> Revision: 23048 http://trac.macosforge.org/projects/launchd/changeset/23048 Author: zarzycki@apple.com Date: 2007-02-08 14:48:29 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Symbol clean up. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_core_logic.h Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-08 22:43:27 UTC (rev 23047) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-08 22:48:29 UTC (rev 23048) @@ -209,6 +209,7 @@ static jobmgr_t jobmgr_new(jobmgr_t jm, mach_port_t requestorport, mach_port_t checkin_port); static jobmgr_t jobmgr_parent(jobmgr_t jm); static jobmgr_t jobmgr_tickle(jobmgr_t jm); +static void jobmgr_remove(jobmgr_t jm); static void jobmgr_dispatch_all(jobmgr_t jm); static job_t jobmgr_new_anonymous(jobmgr_t jm); static job_t job_mig_intran2(jobmgr_t jm, mach_port_t p); Modified: trunk/launchd/src/launchd_core_logic.h =================================================================== --- trunk/launchd/src/launchd_core_logic.h 2007-02-08 22:43:27 UTC (rev 23047) +++ trunk/launchd/src/launchd_core_logic.h 2007-02-08 22:48:29 UTC (rev 23048) @@ -37,7 +37,6 @@ 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); -void jobmgr_remove(jobmgr_t jm); job_t jobmgr_find_by_service_port(jobmgr_t jm, mach_port_t p); launch_data_t job_export_all(void); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070208/e244cc65/attachment.html From source_changes at macosforge.org Thu Feb 8 15:44:36 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23049] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070208234436.67D5D49F8FF@cvs.opensource.apple.com> Revision: 23049 http://trac.macosforge.org/projects/launchd/changeset/23049 Author: zarzycki@apple.com Date: 2007-02-08 15:44:35 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Get rid of a false 'Bug' log message. 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-02-08 22:48:29 UTC (rev 23048) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-08 23:44:35 UTC (rev 23049) @@ -789,7 +789,8 @@ free(argv); - if (!job_assumes(j, jr != NULL)) { + /* jobs can easily be denied creation during shutdown */ + if (!jr) { goto out_bad; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070208/18191aba/attachment.html From source_changes at macosforge.org Thu Feb 8 17:51:31 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23050] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070209015131.A392E49FA99@cvs.opensource.apple.com> Revision: 23050 http://trac.macosforge.org/projects/launchd/changeset/23050 Author: zarzycki@apple.com Date: 2007-02-08 17:51:31 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Performance hack. We really ought to switch to hashes at some point. 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-02-08 23:44:35 UTC (rev 23049) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-09 01:51:31 UTC (rev 23050) @@ -191,7 +191,7 @@ struct jobmgr_s { SLIST_ENTRY(jobmgr_s) sle; SLIST_HEAD(, jobmgr_s) submgrs; - SLIST_HEAD(, job_s) jobs; + TAILQ_HEAD(, job_s) jobs; mach_port_t jm_port; mach_port_t req_port; jobmgr_t parentmgr; @@ -227,7 +227,7 @@ struct job_s { kq_callback kqjob_callback; - SLIST_ENTRY(job_s) sle; + TAILQ_ENTRY(job_s) sle; SLIST_HEAD(, socketgroup) sockets; SLIST_HEAD(, calendarinterval) cal_intervals; SLIST_HEAD(, envitem) global_env; @@ -523,7 +523,7 @@ jobmgr_shutdown(jmi); } - SLIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { + TAILQ_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { if (!job_active(ji)) { job_remove(ji); } else if (!ji->hopefully_exits_last) { @@ -551,10 +551,10 @@ } /* We should have one job left and it should be the anonymous job */ - ji = SLIST_FIRST(&jm->jobs); - jobmgr_assumes(jm, ji && ji == jm->anonj && (SLIST_NEXT(ji, sle) == NULL)); + ji = TAILQ_FIRST(&jm->jobs); + jobmgr_assumes(jm, ji && ji == jm->anonj && (TAILQ_NEXT(ji, sle) == NULL)); - while ((ji = SLIST_FIRST(&jm->jobs))) { + while ((ji = TAILQ_FIRST(&jm->jobs))) { job_remove(ji); } @@ -682,7 +682,7 @@ kevent_mod((uintptr_t)j, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); if (job_assumes(j, j->mgr)) { - SLIST_REMOVE(&j->mgr->jobs, j, job_s, sle); + TAILQ_REMOVE(&j->mgr->jobs, j, sle); jobmgr_tickle(j->mgr); } @@ -972,7 +972,7 @@ j->argv[i] = NULL; } - SLIST_INSERT_HEAD(&jm->jobs, j, sle); + TAILQ_INSERT_TAIL(&jm->jobs, j, sle); job_log(j, LOG_DEBUG, "Conceived"); @@ -1493,7 +1493,7 @@ } } - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { if (strcmp(ji->label, label) == 0) { return ji; } @@ -1514,15 +1514,17 @@ runtime_get_caller_creds(&ldc); - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { if (ji->p == ldc.pid) { /* This is just a MRU perfomance hack */ - SLIST_REMOVE(&jm->jobs, ji, job_s, sle); - SLIST_INSERT_HEAD(&jm->jobs, ji, sle); + TAILQ_REMOVE(&jm->jobs, ji, sle); + TAILQ_INSERT_HEAD(&jm->jobs, ji, sle); return ji; + } else if (ji->p == 0) { + /* All the PIDs are at the front of the list */ + break; } } - return jm->anonj; } @@ -1534,7 +1536,7 @@ } } - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { if (ji->j_port == p) { return ji; } @@ -1566,7 +1568,7 @@ } } - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { SLIST_FOREACH(ms, &ji->machservices, sle) { if (ms->port == p) { return ji; @@ -1592,7 +1594,7 @@ job_export_all2(jmi, where); } - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { launch_data_t tmp; if (jobmgr_assumes(jm, (tmp = job_export2(ji, false)) != NULL)) { @@ -1636,6 +1638,10 @@ return; } + /* Performance hack */ + TAILQ_REMOVE(&j->mgr->jobs, j, sle); + TAILQ_INSERT_TAIL(&j->mgr->jobs, j, sle); + job_assumes(j, gettimeofday(&tve, NULL) != -1); if (j->wait_reply_port) { @@ -1698,7 +1704,7 @@ jobmgr_dispatch_all(jmi); } - SLIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { + TAILQ_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { job_dispatch(ji, false); } } @@ -1889,6 +1895,10 @@ job_start_child(j); break; default: + /* Performance hack */ + TAILQ_REMOVE(&j->mgr->jobs, j, sle); + TAILQ_INSERT_HEAD(&j->mgr->jobs, j, sle); + if (!j->legacy_mach_job) { job_assumes(j, close(oepair[1]) != -1); } @@ -1993,7 +2003,7 @@ jobmgr_setup_env_from_other_jobs(jm->parentmgr); } - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { SLIST_FOREACH(ei, &ji->global_env, sle) { setenv(ei->key, ei->value, 1); } @@ -2815,7 +2825,7 @@ unsigned int cnt = 0; job_t ji; - SLIST_FOREACH(ji, &j->mgr->jobs, sle) { + TAILQ_FOREACH(ji, &j->mgr->jobs, sle) { if (ji->p) { cnt++; } @@ -3186,13 +3196,13 @@ return jm; } - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { if (ji->p && !ji->hopefully_exits_last) { return jm; } } - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { job_stop(ji); } @@ -3215,7 +3225,7 @@ return false; } - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { if (ji->p) { return false; } @@ -3306,6 +3316,8 @@ return NULL; } + TAILQ_INIT(&jmr->jobs); + jmr->req_port = requestorport; if ((jmr->parentmgr = jm)) { @@ -3378,7 +3390,7 @@ jobmgr_delete_anything_with_port(jmi, port); } - SLIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { + TAILQ_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { SLIST_FOREACH_SAFE(ms, &ji->machservices, sle, next_ms) { if (ms->port == port) { machservice_delete(ms); @@ -3393,7 +3405,7 @@ struct machservice *ms; job_t ji; - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { SLIST_FOREACH(ms, &ji->machservices, sle) { if (strcmp(name, ms->name) == 0) { return ms; @@ -3551,7 +3563,7 @@ } /* We don't need the _SAFE version because we return after the job_dispatch() */ - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { SLIST_FOREACH(ms, &ji->machservices, sle) { if (ms->port != p) { continue; @@ -3704,7 +3716,7 @@ jobmgr_dispatch_all_semaphores(jmi); } - SLIST_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { + TAILQ_FOREACH_SAFE(ji, &jm->jobs, sle, jn) { if (!SLIST_EMPTY(&ji->semaphores)) { job_dispatch(ji, false); } @@ -4027,7 +4039,7 @@ *up_cont = MACH_PORT_NULL; - SLIST_FOREACH(ji, &root_jobmgr->jobs, sle) { + TAILQ_FOREACH(ji, &root_jobmgr->jobs, sle) { if (ji->mach_uid != which_user) { continue; } @@ -4248,7 +4260,7 @@ jm = j->mgr; - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { SLIST_FOREACH(ms, &ji->machservices, sle) { cnt++; } @@ -4268,7 +4280,7 @@ goto out_bad; } - SLIST_FOREACH(ji, &jm->jobs, sle) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { SLIST_FOREACH(ms, &ji->machservices, sle) { strlcpy(service_names[cnt2], machservice_name(ms), sizeof(service_names[0])); service_actives[cnt2] = machservice_status(ms); @@ -4312,8 +4324,8 @@ } if (job_assumes(j, jmi != NULL)) { - SLIST_REMOVE(&j->mgr->jobs, j, job_s, sle); - SLIST_INSERT_HEAD(&jmi->jobs, j, sle); + TAILQ_REMOVE(&j->mgr->jobs, j, sle); + TAILQ_INSERT_TAIL(&jmi->jobs, j, sle); j->mgr = jmi; } } @@ -4651,7 +4663,7 @@ launchd_assert((root_jobmgr = jobmgr_new(NULL, mach_task_self(), checkin_port)) != NULL); - SLIST_FOREACH(ji, &root_jobmgr->jobs, sle) { + TAILQ_FOREACH(ji, &root_jobmgr->jobs, sle) { if (ji->anonymous) { anon_job = ji; break; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070208/727aea33/attachment.html From source_changes at macosforge.org Fri Feb 9 09:56:22 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23051] trunk/launchd/src Message-ID: <20070209175622.49A1B4A02DF@cvs.opensource.apple.com> Revision: 23051 http://trac.macosforge.org/projects/launchd/changeset/23051 Author: zarzycki@apple.com Date: 2007-02-09 09:56:21 -0800 (Fri, 09 Feb 2007) Log Message: ----------- Better shutdown debugging. Modified Paths: -------------- trunk/launchd/src/launchd.c trunk/launchd/src/launchd.h trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-02-09 01:51:31 UTC (rev 23050) +++ trunk/launchd/src/launchd.c 2007-02-09 17:56:21 UTC (rev 23051) @@ -394,28 +394,26 @@ void launchd_shutdown(void) { + struct stat sb; + if (shutdown_in_progress) { return; } shutdown_in_progress = true; -#if 0 - struct stat sb; + if (getpid() == 1) { + if (stat("/var/db/debugShutdownHangs", &sb) != -1) { + /* + * When this changes to a more sustainable API, update this: + * http://howto.apple.com/db.cgi?Debugging_Apps_Non-Responsive_At_Shutdown + */ + debug_shutdown_hangs = true; + } - if (stat("/var/db/debugShutdownHangs", &sb) != -1) { - /* - * When this changes to a more sustainable API, update this: - * http://howto.apple.com/db.cgi?Debugging_Apps_Non-Responsive_At_Shutdown - */ - debug_shutdown_hangs = true; - } -#else - if (getpid() == 1) { launchd_assumes(kevent_mod((uintptr_t)debugshutdown_callback, EVFILT_TIMER, EV_ADD|EV_ONESHOT, NOTE_SECONDS, 5, &kqdebugshutdown_callback) != -1); } -#endif rlcj = NULL; @@ -654,6 +652,9 @@ pid_t sddp; if (launchd_assumes(posix_spawn(&sddp, sdd_args[0], NULL, NULL, sdd_args, environ) == 0)) { - launchd_assumes(kevent_mod(sddp, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, &kqsimple_zombie_reaper) != -1); + int wstatus; + + /* No bootstrap port was given. It is safe to block. */ + launchd_assumes(waitpid(sddp, &wstatus, 0) != -1); } } Modified: trunk/launchd/src/launchd.h =================================================================== --- trunk/launchd/src/launchd.h 2007-02-09 01:51:31 UTC (rev 23050) +++ trunk/launchd/src/launchd.h 2007-02-09 17:56:21 UTC (rev 23051) @@ -31,7 +31,6 @@ struct kevent; struct conncb; -extern kq_callback kqsimple_zombie_reaper; extern sigset_t blocked_signals; extern bool debug_shutdown_hangs; extern bool network_up; Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-09 01:51:31 UTC (rev 23050) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-09 17:56:21 UTC (rev 23051) @@ -337,22 +337,12 @@ static bool cronemu_hour(struct tm *wtm, int hour, int min); static bool cronemu_min(struct tm *wtm, int min); -static void simple_zombie_reaper(void *, struct kevent *); - -kq_callback kqsimple_zombie_reaper = simple_zombie_reaper; - static int dir_has_files(job_t j, const char *path); static char **mach_cmd2argv(const char *string); jobmgr_t root_jobmgr; jobmgr_t gc_this_jobmgr; void -simple_zombie_reaper(void *obj __attribute__((unused)), struct kevent *kev) -{ - waitpid(kev->ident, NULL, 0); -} - -void job_ignore(job_t j) { struct semaphoreitem *si; @@ -1779,9 +1769,7 @@ if ((uintptr_t)j == kev->ident || (uintptr_t)&j->start_interval == kev->ident) { job_dispatch(j, true); } else if ((uintptr_t)&j->exit_timeout == kev->ident) { - if (debug_shutdown_hangs) { - job_force_sampletool(j); - } + job_force_sampletool(j); job_log(j, LOG_WARNING, "Exit timeout elapsed (%u seconds). Killing.", j->exit_timeout); job_assumes(j, kill(j->p, SIGKILL) != -1); } else { @@ -3625,16 +3613,72 @@ void job_force_sampletool(job_t j) { - char *sample_args[] = { "sample", NULL, "1", "-mayDie", NULL }; + struct stat sb; + char logfile[PATH_MAX]; char pidstr[100]; + char *sample_args[] = { "sample", pidstr, "1", "-mayDie", "-file", logfile, NULL }; + char *contents = NULL; + int logfile_fd = -1; + int console_fd = -1; pid_t sp; + + if (!debug_shutdown_hangs) { + return; + } snprintf(pidstr, sizeof(pidstr), "%u", j->p); - sample_args[1] = pidstr; + snprintf(logfile, sizeof(logfile), "/var/log/shutdown/%s-%u.sample.txt", j->label, j->p); - if (job_assumes(j, posix_spawnp(&sp, sample_args[0], NULL, NULL, sample_args, environ) == 0)) { - job_assumes(j, kevent_mod(sp, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, &kqsimple_zombie_reaper) != -1); + job_assumes(j, mkdir("/var/log/shutdown", S_IRWXU) != -1 || errno == EEXIST); + + /* + * This will stall launchd for as long as the 'sample' tool runs. + * + * We didn't give the 'sample' tool a bootstrap port, so it therefore + * can't deadlock against launchd. + */ + if (job_assumes(j, (errno = posix_spawnp(&sp, sample_args[0], NULL, NULL, sample_args, environ)) == 0)) { + int wstatus; + + job_assumes(j, waitpid(sp, &wstatus, 0) != -1); } + + if (!job_assumes(j, (logfile_fd = open(logfile, O_RDONLY|O_NOCTTY)) != -1)) { + goto out; + } + + if (!job_assumes(j, (console_fd = open(_PATH_CONSOLE, O_WRONLY|O_APPEND||O_NOCTTY)) != -1)) { + goto out; + } + + if (!job_assumes(j, fstat(logfile_fd, &sb) != -1)) { + goto out; + } + + contents = malloc(sb.st_size); + + if (!job_assumes(j, contents != NULL)) { + goto out; + } + + if (!job_assumes(j, read(logfile_fd, contents, sb.st_size) == sb.st_size)) { + goto out; + } + + job_assumes(j, write(console_fd, contents, sb.st_size) == sb.st_size); + +out: + if (contents) { + free(contents); + } + + if (logfile_fd != -1) { + job_assumes(j, close(logfile_fd) != -1); + } + + if (console_fd != -1) { + job_assumes(j, close(console_fd) != -1); + } } bool -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070209/2dc67e91/attachment.html From source_changes at macosforge.org Fri Feb 9 14:31:37 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23052] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070209223137.446A64A084D@cvs.opensource.apple.com> Revision: 23052 http://trac.macosforge.org/projects/launchd/changeset/23052 Author: zarzycki@apple.com Date: 2007-02-09 14:31:36 -0800 (Fri, 09 Feb 2007) Log Message: ----------- Even better shutdown 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-02-09 17:56:21 UTC (rev 23051) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-09 22:31:36 UTC (rev 23052) @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -199,6 +200,7 @@ char *jm_stdout; char *jm_stderr; unsigned int global_on_demand_cnt; + unsigned int would_have_sigkilled; unsigned int transfer_bstrap:1, sent_stop_to_hopeful_jobs:1, shutting_down:1; char name[0]; }; @@ -209,6 +211,7 @@ static jobmgr_t jobmgr_new(jobmgr_t jm, mach_port_t requestorport, mach_port_t checkin_port); static jobmgr_t jobmgr_parent(jobmgr_t jm); static jobmgr_t jobmgr_tickle(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); static job_t jobmgr_new_anonymous(jobmgr_t jm); @@ -305,6 +308,7 @@ static const char *job_prog(job_t j); static pid_t job_get_pid(job_t j); static jobmgr_t job_get_bs(job_t j); +static void job_kill(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); @@ -337,6 +341,7 @@ static bool cronemu_hour(struct tm *wtm, int hour, int min); static bool cronemu_min(struct tm *wtm, int min); +static unsigned int total_children; static int dir_has_files(job_t j, const char *path); static char **mach_cmd2argv(const char *string); jobmgr_t root_jobmgr; @@ -1628,6 +1633,8 @@ return; } + total_children--; + /* Performance hack */ TAILQ_REMOVE(&j->mgr->jobs, j, sle); TAILQ_INSERT_TAIL(&j->mgr->jobs, j, sle); @@ -1756,6 +1763,19 @@ } void +job_kill(job_t j) +{ + if (debug_shutdown_hangs) { + j->mgr->would_have_sigkilled++; + if (j->mgr->would_have_sigkilled >= total_children) { + job_assumes(j, host_reboot(mach_host_self(), HOST_REBOOT_DEBUGGER) == 0); + } + } else { + job_assumes(j, kill(j->p, SIGKILL) != -1); + } +} + +void job_callback(void *obj, struct kevent *kev) { job_t j = obj; @@ -1771,7 +1791,7 @@ } else if ((uintptr_t)&j->exit_timeout == kev->ident) { job_force_sampletool(j); job_log(j, LOG_WARNING, "Exit timeout elapsed (%u seconds). Killing.", j->exit_timeout); - job_assumes(j, kill(j->p, SIGKILL) != -1); + job_kill(j); } else { calendarinterval_callback(j, kev); } @@ -1883,6 +1903,8 @@ job_start_child(j); break; default: + total_children++; + /* Performance hack */ TAILQ_REMOVE(&j->mgr->jobs, j, sle); TAILQ_INSERT_HEAD(&j->mgr->jobs, j, sle); @@ -2810,16 +2832,7 @@ job_log(j, LOG_INFO, "Exited. Was only configured to run once."); return true; } else if (j->mgr->shutting_down) { - unsigned int cnt = 0; - job_t ji; - - TAILQ_FOREACH(ji, &j->mgr->jobs, sle) { - if (ji->p) { - cnt++; - } - } - - job_log(j, LOG_INFO, "Exited while shutdown in progress. Processes remaining: %u", cnt); + job_log(j, LOG_NOTICE, "Exited while shutdown in progress. Processes remaining: %u", total_children); return true; } else if (!j->checkedin && (!SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices))) { job_log(j, LOG_WARNING, "Failed to check-in!"); @@ -3197,6 +3210,7 @@ jm->sent_stop_to_hopeful_jobs = true; if (jobmgr_is_idle(jm)) { + jobmgr_log_stray_children(jm); jobmgr_remove(jm); return NULL; } @@ -3204,6 +3218,42 @@ return jm; } +void +jobmgr_log_stray_children(jobmgr_t jm) +{ + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL }; + size_t i, kp_cnt, len = 10*1024*1024; + struct kinfo_proc *kp; + + if (jm->parentmgr || getpid() != 1) { + return; + } + + if (!jobmgr_assumes(jm, (kp = malloc(len)) != NULL)) { + return; + } + if (!jobmgr_assumes(jm, sysctl(mib, 3, kp, &len, NULL, 0) != -1)) { + goto out; + } + + kp_cnt = len / sizeof(struct kinfo_proc); + + for (i = 0; i < kp_cnt; i++) { + pid_t p_i = kp[i].kp_proc.p_pid; + pid_t pp_i = kp[i].kp_eproc.e_ppid; + + if (p_i == 0 || p_i == 1) { + continue; + } + + jobmgr_log(jm, LOG_WARNING, "Stray process at shutdown: PID %u PPID %u %s", p_i, pp_i, kp[i].kp_proc.p_comm); + jobmgr_assumes(jm, kill(p_i, SIGKILL) != -1); + } + +out: + free(kp); +} + bool jobmgr_is_idle(jobmgr_t jm) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070209/3ce0759e/attachment.html From source_changes at macosforge.org Fri Feb 9 14:51:16 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23053] trunk/launchd/src Message-ID: <20070209225116.C7DAC4A08AD@cvs.opensource.apple.com> Revision: 23053 http://trac.macosforge.org/projects/launchd/changeset/23053 Author: zarzycki@apple.com Date: 2007-02-09 14:51:16 -0800 (Fri, 09 Feb 2007) Log Message: ----------- Move call to exit() and reboot() to jobmgr_remove(root_jobmgr). 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-02-09 22:31:36 UTC (rev 23052) +++ trunk/launchd/src/launchd.c 2007-02-09 22:51:16 UTC (rev 23053) @@ -417,7 +417,7 @@ rlcj = NULL; - root_jobmgr = jobmgr_shutdown(root_jobmgr); + launchd_assert(jobmgr_shutdown(root_jobmgr) != NULL); } void @@ -624,7 +624,8 @@ void launchd_post_kevent(void) { - if (shutdown_in_progress && (!root_jobmgr || jobmgr_is_idle(root_jobmgr))) { +#if 0 + if (shutdown_in_progress && jobmgr_is_idle(root_jobmgr)) { shutdown_in_progress = false; if (getpid() == 1) { @@ -632,11 +633,9 @@ kill(-1, SIGKILL); /* One last time, just to clear the room */ launchd_assumes(execl("/sbin/launchd", "/sbin/launchd", "-s", NULL) != -1); } - launchd_assumes(reboot(RB_HALT) != -1); - } else { - exit(EXIT_SUCCESS); } } +#endif if (getpid() == 1) { if (rlcj && job_active(rlcj)) { return; Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-09 22:31:36 UTC (rev 23052) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-09 22:51:16 UTC (rev 23053) @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -211,6 +212,7 @@ static jobmgr_t jobmgr_new(jobmgr_t jm, mach_port_t requestorport, mach_port_t checkin_port); static jobmgr_t jobmgr_parent(jobmgr_t jm); static jobmgr_t jobmgr_tickle(jobmgr_t jm); +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); @@ -576,6 +578,10 @@ if (jm->parentmgr) { SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); jobmgr_tickle(jm->parentmgr); + } else if (getpid() == 1) { + jobmgr_assumes(jm, reboot(RB_HALT) != -1); + } else { + exit(EXIT_SUCCESS); } free(jm); Modified: trunk/launchd/src/launchd_core_logic.h =================================================================== --- trunk/launchd/src/launchd_core_logic.h 2007-02-09 22:31:36 UTC (rev 23052) +++ trunk/launchd/src/launchd_core_logic.h 2007-02-09 22:51:16 UTC (rev 23053) @@ -31,7 +31,6 @@ void jobmgr_set_stdout(jobmgr_t jm, const char *what); void jobmgr_set_stderr(jobmgr_t jm, const char *what); -bool jobmgr_is_idle(jobmgr_t jm); jobmgr_t jobmgr_shutdown(jobmgr_t jm); void jobmgr_dispatch_all_semaphores(jobmgr_t jm); job_t jobmgr_find(jobmgr_t jm, const char *label); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070209/626554a0/attachment.html From source_changes at macosforge.org Fri Feb 9 19:25:35 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23054] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070210032535.5121C4A1992@cvs.opensource.apple.com> Revision: 23054 http://trac.macosforge.org/projects/launchd/changeset/23054 Author: zarzycki@apple.com Date: 2007-02-09 19:25:34 -0800 (Fri, 09 Feb 2007) Log Message: ----------- Misc 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-02-09 22:51:16 UTC (rev 23053) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-10 03:25:34 UTC (rev 23054) @@ -201,7 +201,6 @@ char *jm_stdout; char *jm_stderr; unsigned int global_on_demand_cnt; - unsigned int would_have_sigkilled; unsigned int transfer_bstrap:1, sent_stop_to_hopeful_jobs:1, shutting_down:1; char name[0]; }; @@ -1771,14 +1770,7 @@ void job_kill(job_t j) { - if (debug_shutdown_hangs) { - j->mgr->would_have_sigkilled++; - if (j->mgr->would_have_sigkilled >= total_children) { - job_assumes(j, host_reboot(mach_host_self(), HOST_REBOOT_DEBUGGER) == 0); - } - } else { - job_assumes(j, kill(j->p, SIGKILL) != -1); - } + job_assumes(j, kill(j->p, SIGKILL) != -1); } void @@ -1788,8 +1780,13 @@ switch (kev->filter) { case EVFILT_PROC: - job_reap(j); - job_dispatch(j, false); + if (kev->fflags & NOTE_EXEC) { + job_log(j, LOG_DEBUG, "Called execve()"); + } + if (kev->fflags & NOTE_EXIT) { + job_reap(j); + job_dispatch(j, false); + } break; case EVFILT_TIMER: if ((uintptr_t)j == kev->ident || (uintptr_t)&j->start_interval == kev->ident) { @@ -1925,7 +1922,7 @@ job_assumes(j, close(spair[1]) == 0); ipc_open(_fd(spair[0]), j); } - if (kevent_mod(c, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, &j->kqjob_callback) == -1) { + if (kevent_mod(c, EVFILT_PROC, EV_ADD, NOTE_EXEC|NOTE_EXIT, 0, &j->kqjob_callback) == -1) { job_log_error(j, LOG_ERR, "kevent()"); job_reap(j); } else { @@ -3501,13 +3498,8 @@ void machservice_delete(struct machservice *ms) { - if (ms->recv) { - if (ms->isActive) { - /* FIXME we should cancel the notification */ - job_log(ms->job, LOG_DEBUG, "Mach service deleted while we didn't own the receive right: %s", ms->name); - } else { - job_assumes(ms->job, launchd_mport_close_recv(ms->port) == KERN_SUCCESS); - } + if (ms->recv && job_assumes(ms->job, !ms->isActive)) { + job_assumes(ms->job, launchd_mport_close_recv(ms->port) == KERN_SUCCESS); } job_assumes(ms->job, launchd_mport_deallocate(ms->port) == KERN_SUCCESS); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070209/a8a6798b/attachment.html From source_changes at macosforge.org Sat Feb 10 08:52:04 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23055] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070210165204.D69514A22F6@cvs.opensource.apple.com> Revision: 23055 http://trac.macosforge.org/projects/launchd/changeset/23055 Author: zarzycki@apple.com Date: 2007-02-10 08:52:04 -0800 (Sat, 10 Feb 2007) Log Message: ----------- Minor 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-02-10 03:25:34 UTC (rev 23054) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-10 16:52:04 UTC (rev 23055) @@ -3668,6 +3668,7 @@ char *contents = NULL; int logfile_fd = -1; int console_fd = -1; + int wstatus; pid_t sp; if (!debug_shutdown_hangs) { @@ -3685,17 +3686,23 @@ * We didn't give the 'sample' tool a bootstrap port, so it therefore * can't deadlock against launchd. */ - if (job_assumes(j, (errno = posix_spawnp(&sp, sample_args[0], NULL, NULL, sample_args, environ)) == 0)) { - int wstatus; + if (!job_assumes(j, (errno = posix_spawnp(&sp, sample_args[0], NULL, NULL, sample_args, environ)) == 0)) { + goto out; + } - job_assumes(j, waitpid(sp, &wstatus, 0) != -1); + if (!job_assumes(j, waitpid(sp, &wstatus, 0) != -1)) { + goto out; } + if (!job_assumes(j, WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == 0)) { + goto out; + } + if (!job_assumes(j, (logfile_fd = open(logfile, O_RDONLY|O_NOCTTY)) != -1)) { goto out; } - if (!job_assumes(j, (console_fd = open(_PATH_CONSOLE, O_WRONLY|O_APPEND||O_NOCTTY)) != -1)) { + if (!job_assumes(j, (console_fd = open(_PATH_CONSOLE, O_WRONLY|O_APPEND|O_NOCTTY)) != -1)) { goto out; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070210/808780b6/attachment.html From source_changes at macosforge.org Sun Feb 11 21:08:02 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23056] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070212050802.10CD94A33E6@cvs.opensource.apple.com> Revision: 23056 http://trac.macosforge.org/projects/launchd/changeset/23056 Author: zarzycki@apple.com Date: 2007-02-11 21:08:01 -0800 (Sun, 11 Feb 2007) Log Message: ----------- kqueue dispatch 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-02-10 16:52:04 UTC (rev 23055) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-12 05:08:01 UTC (rev 23056) @@ -129,7 +129,7 @@ static void socketgroup_delete(job_t j, struct socketgroup *sg); static void socketgroup_watch(job_t j, struct socketgroup *sg); static void socketgroup_ignore(job_t j, struct socketgroup *sg); -static void socketgroup_callback(job_t j, struct kevent *kev); +static void socketgroup_callback(job_t j); static void socketgroup_setup(launch_data_t obj, const char *key, void *context); struct calendarinterval { @@ -141,7 +141,7 @@ static bool calendarinterval_new_from_obj(job_t j, launch_data_t obj); static void calendarinterval_delete(job_t j, struct calendarinterval *ci); static void calendarinterval_setalarm(job_t j, struct calendarinterval *ci); -static void calendarinterval_callback(job_t j, struct kevent *kev); +static void calendarinterval_callback(job_t j, void *ident); struct envitem { SLIST_ENTRY(envitem) sle; @@ -303,6 +303,9 @@ 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); +static void job_callback_proc(job_t j, int fflags); +static void job_callback_timer(job_t j, void *ident); +static void job_callback_read(job_t j, int ident); 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); static job_t job_new_via_mach_init(job_t j, const char *cmd, uid_t uid, bool ond); @@ -1774,47 +1777,60 @@ } void +job_callback_proc(job_t j, int fflags) +{ + if (fflags & NOTE_EXEC) { + job_log(j, LOG_DEBUG, "Called execve()"); + } + + if (fflags & NOTE_EXIT) { + job_reap(j); + job_dispatch(j, false); + } +} + +void +job_callback_timer(job_t j, void *ident) +{ + if (j == ident || &j->start_interval == ident) { + job_dispatch(j, true); + } else if (&j->exit_timeout == ident) { + job_force_sampletool(j); + job_log(j, LOG_WARNING, "Exit timeout elapsed (%u seconds). Killing.", j->exit_timeout); + job_kill(j); + } else { + calendarinterval_callback(j, ident); + } +} + +void +job_callback_read(job_t j, int ident) +{ + if (ident == j->log_redirect_fd) { + job_log_stdouterr(j); + } else { + socketgroup_callback(j); + } +} + +void job_callback(void *obj, struct kevent *kev) { job_t j = obj; switch (kev->filter) { case EVFILT_PROC: - if (kev->fflags & NOTE_EXEC) { - job_log(j, LOG_DEBUG, "Called execve()"); - } - if (kev->fflags & NOTE_EXIT) { - job_reap(j); - job_dispatch(j, false); - } - break; + return job_callback_proc(j, kev->fflags); case EVFILT_TIMER: - if ((uintptr_t)j == kev->ident || (uintptr_t)&j->start_interval == kev->ident) { - job_dispatch(j, true); - } else if ((uintptr_t)&j->exit_timeout == kev->ident) { - job_force_sampletool(j); - job_log(j, LOG_WARNING, "Exit timeout elapsed (%u seconds). Killing.", j->exit_timeout); - job_kill(j); - } else { - calendarinterval_callback(j, kev); - } - break; + return job_callback_timer(j, (void *)kev->ident); case EVFILT_VNODE: - semaphoreitem_callback(j, kev); - break; + return semaphoreitem_callback(j, kev); case EVFILT_READ: - if (kev->ident == (uintptr_t)j->log_redirect_fd) { - job_log_stdouterr(j); - } else { - socketgroup_callback(j, kev); - } - break; + return job_callback_read(j, kev->ident); case EVFILT_MACHPORT: - job_dispatch(j, true); - break; + return (void)job_dispatch(j, true); default: - job_assumes(j, false); - break; + return (void)job_assumes(j, false); } } @@ -2607,12 +2623,12 @@ } void -calendarinterval_callback(job_t j, struct kevent *kev) +calendarinterval_callback(job_t j, void *ident) { struct calendarinterval *ci; SLIST_FOREACH(ci, &j->cal_intervals, sle) { - if ((uintptr_t)ci == kev->ident) { + if (ci == ident) { break; } } @@ -2704,7 +2720,7 @@ } void -socketgroup_callback(job_t j, struct kevent *kev) +socketgroup_callback(job_t j) { job_dispatch(j, true); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070211/03a56efe/attachment.html From source_changes at macosforge.org Sun Feb 11 21:21:36 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23057] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070212052136.C8D884A33F7@cvs.opensource.apple.com> Revision: 23057 http://trac.macosforge.org/projects/launchd/changeset/23057 Author: zarzycki@apple.com Date: 2007-02-11 21:21:36 -0800 (Sun, 11 Feb 2007) Log Message: ----------- Bug: launchd_core_logic.c:604 (23046):3: j->p == 0 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-02-12 05:08:01 UTC (rev 23056) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-12 05:21:36 UTC (rev 23057) @@ -273,7 +273,7 @@ importing_global_env:1, importing_hard_limits:1, setmask:1, legacy_mach_job:1, runatload: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, setnice:1, hopefully_exits_last:1; + currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1, hopefully_exits_last:1, removal_pending:1; char label[0]; }; @@ -599,17 +599,21 @@ struct machservice *ms; struct semaphoreitem *si; - job_log(j, LOG_DEBUG, "Removed"); + if (j->p) { + job_log(j, LOG_DEBUG, "Removal pended until the job exits."); + if (!j->removal_pending) { + j->removal_pending = true; + job_stop(j); + } + + return; + } + if (j->forced_peers_to_demand_mode) { job_set_global_on_demand(j, false); } - if (!job_assumes(j, j->p == 0)) { - job_assumes(j, kill(j->p, SIGKILL) != -1); - job_reap(j); - } - if (!job_assumes(j, j->forkfd == 0)) { job_assumes(j, close(j->forkfd) != -1); } @@ -689,6 +693,8 @@ jobmgr_tickle(j->mgr); } + job_log(j, LOG_DEBUG, "Removed"); + free(j); } @@ -2850,6 +2856,9 @@ } job_log(j, LOG_INFO, "Exited. Was only configured to run once."); return true; + } else if (j->removal_pending) { + job_log(j, LOG_DEBUG, "Exited while removal was pending."); + return true; } else if (j->mgr->shutting_down) { job_log(j, LOG_NOTICE, "Exited while shutdown in progress. Processes remaining: %u", total_children); return true; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070211/a125cff0/attachment.html From source_changes at macosforge.org Tue Feb 13 13:39:11 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23058] tags/launchd-194/ Message-ID: <20070213213911.F41E54A59F4@cvs.opensource.apple.com> Revision: 23058 http://trac.macosforge.org/projects/launchd/changeset/23058 Author: zarzycki@apple.com Date: 2007-02-13 13:39:11 -0800 (Tue, 13 Feb 2007) Log Message: ----------- "Tagging launchd-194 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-194/ Copied: tags/launchd-194 (from rev 23057, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070213/5e4012b0/attachment.html From source_changes at macosforge.org Tue Feb 13 17:42:51 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23059] trunk/launchd/src Message-ID: <20070214014251.E75904A5D70@cvs.opensource.apple.com> Revision: 23059 http://trac.macosforge.org/projects/launchd/changeset/23059 Author: zarzycki@apple.com Date: 2007-02-13 17:42:50 -0800 (Tue, 13 Feb 2007) Log Message: ----------- More logging. 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-02-13 21:39:11 UTC (rev 23058) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-14 01:42:50 UTC (rev 23059) @@ -362,6 +362,8 @@ return; } + job_log(j, LOG_DEBUG, "Ignoring..."); + j->currently_ignored = true; SLIST_FOREACH(sg, &j->sockets, sle) { @@ -388,6 +390,8 @@ return; } + job_log(j, LOG_DEBUG, "Watching..."); + j->currently_ignored = false; SLIST_FOREACH(sg, &j->sockets, sle) { @@ -1735,11 +1739,17 @@ if (job_useless(j)) { job_remove(j); return NULL; - } else if (kickstart || job_keepalive(j)) { + } else if (kickstart) { + job_log(j, LOG_DEBUG, "Kick-starting."); job_start(j); + } else if (job_keepalive(j)) { + job_log(j, LOG_DEBUG, "Keeping alive..."); + job_start(j); } else { job_watch(j); } + } else { + job_log(j, LOG_DEBUG, "Tried to dispatch an already active job."); } return j; @@ -1824,6 +1834,9 @@ { job_t j = obj; + job_log(j, LOG_DEBUG, "kev.ident = 0x%lx kev.filter = 0x%x kev->flags = 0x%x kev.fflags = 0x%x kev.data = 0x%lx kev.udata = %p", + kev->ident, kev->filter, kev->flags, kev->fflags, kev->data, kev->udata); + switch (kev->filter) { case EVFILT_PROC: return job_callback_proc(j, kev->fflags); @@ -2900,8 +2913,9 @@ SLIST_FOREACH(ms, &j->machservices, sle) { statusCnt = MACH_PORT_RECEIVE_STATUS_COUNT; if (mach_port_get_attributes(mach_task_self(), ms->port, MACH_PORT_RECEIVE_STATUS, - (mach_port_info_t)&status, &statusCnt) != KERN_SUCCESS) + (mach_port_info_t)&status, &statusCnt) != KERN_SUCCESS) { continue; + } if (status.mps_msgcount) { job_log(j, LOG_DEBUG, "KeepAlive check: job restarted due to %d queued Mach messages on service: %s", status.mps_msgcount, ms->name); Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-13 21:39:11 UTC (rev 23058) +++ trunk/launchd/src/launchd_runtime.c 2007-02-14 01:42:50 UTC (rev 23059) @@ -165,7 +165,9 @@ } if (status.mps_msgcount) { EV_SET(&kev, members[i], EVFILT_MACHPORT, 0, 0, 0, jobmgr_find_by_service_port(root_jobmgr, members[i])); - (*((kq_callback *)kev.udata))(kev.udata, &kev); + if (launchd_assumes(kev.udata != NULL)) { + (*((kq_callback *)kev.udata))(kev.udata, &kev); + } /* the callback may have tainted our ability to continue this for loop */ break; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070213/8a7ad510/attachment.html From source_changes at macosforge.org Tue Feb 13 17:52:08 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23060] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070214015208.D427B4A5D9C@cvs.opensource.apple.com> Revision: 23060 http://trac.macosforge.org/projects/launchd/changeset/23060 Author: zarzycki@apple.com Date: 2007-02-13 17:52:08 -0800 (Tue, 13 Feb 2007) Log Message: ----------- Let the stdout/sterr pipe linger longer for GUI applications 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-02-14 01:42:50 UTC (rev 23059) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-14 01:52:08 UTC (rev 23060) @@ -273,7 +273,8 @@ importing_global_env:1, importing_hard_limits:1, setmask:1, legacy_mach_job:1, runatload: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, setnice:1, hopefully_exits_last:1, removal_pending:1; + currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1, hopefully_exits_last:1, removal_pending:1, + wait4pipe_eof:1; char label[0]; }; @@ -869,6 +870,7 @@ } jr->unload_at_exit = true; + jr->wait4pipe_eof = true; jr->stall_before_exec = w4d; if (workingdir) { @@ -1637,7 +1639,7 @@ job_log(j, LOG_DEBUG, "Reaping"); - if (j->log_redirect_fd) { + if (j->log_redirect_fd && !j->wait4pipe_eof) { job_assumes(j, close(j->log_redirect_fd) != -1); j->log_redirect_fd = 0; } @@ -1773,6 +1775,7 @@ job_log(j, LOG_DEBUG, "Standard out/error pipe closed"); job_assumes(j, close(j->log_redirect_fd) != -1); j->log_redirect_fd = 0; + job_dispatch(j, false); } else if (job_assumes(j, rsz != -1)) { buf[rsz] = '\0'; @@ -2996,6 +2999,10 @@ return true; } + if (j->wait4pipe_eof && j->log_redirect_fd) { + return true; + } + if (j->p) { return true; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070213/3cb1edfb/attachment.html From source_changes at macosforge.org Wed Feb 14 09:09:19 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23061] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070214170919.1CBD54A6669@cvs.opensource.apple.com> Revision: 23061 http://trac.macosforge.org/projects/launchd/changeset/23061 Author: zarzycki@apple.com Date: 2007-02-14 09:09:18 -0800 (Wed, 14 Feb 2007) Log Message: ----------- postfix doesn't deliver until shutdown 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-02-14 01:52:08 UTC (rev 23060) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-14 17:09:18 UTC (rev 23061) @@ -2521,6 +2521,7 @@ case PATH_MISSING: fflags = NOTE_DELETE|NOTE_RENAME; break; + case DIR_NOT_EMPTY: case PATH_CHANGES: fflags = NOTE_DELETE|NOTE_RENAME|NOTE_REVOKE|NOTE_EXTEND|NOTE_WRITE|NOTE_ATTRIB|NOTE_LINK; break; @@ -2550,6 +2551,7 @@ case PATH_CHANGES: case PATH_EXISTS: case PATH_MISSING: + case DIR_NOT_EMPTY: break; default: continue; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070214/6b3b58fd/attachment.html From source_changes at macosforge.org Wed Feb 14 11:41:32 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23062] trunk/launchd/src Message-ID: <20070214194132.16C3C4A6A26@cvs.opensource.apple.com> Revision: 23062 http://trac.macosforge.org/projects/launchd/changeset/23062 Author: zarzycki@apple.com Date: 2007-02-14 11:41:31 -0800 (Wed, 14 Feb 2007) Log Message: ----------- Mega kevent debugging. 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-02-14 17:09:18 UTC (rev 23061) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-14 19:41:31 UTC (rev 23062) @@ -1837,8 +1837,7 @@ { job_t j = obj; - job_log(j, LOG_DEBUG, "kev.ident = 0x%lx kev.filter = 0x%x kev->flags = 0x%x kev.fflags = 0x%x kev.data = 0x%lx kev.udata = %p", - kev->ident, kev->filter, kev->flags, kev->fflags, kev->data, kev->udata); + job_log(j, LOG_DEBUG, "Dispatching kevent callback."); switch (kev->filter) { case EVFILT_PROC: Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-14 17:09:18 UTC (rev 23061) +++ trunk/launchd/src/launchd_runtime.c 2007-02-14 19:41:31 UTC (rev 23062) @@ -143,6 +143,197 @@ return NULL; } +static void +log_kevent_struct(int level, struct kevent *kev) +{ + const char *filter_str; + char ident_buf[100]; + char filter_buf[100]; + char fflags_buf[1000]; + char flags_buf[1000] = "0x0"; + char *flags_off = NULL; + char *fflags_off = NULL; + unsigned short flags = kev->flags; + unsigned int fflags = kev->fflags; + + if (flags) while (flags) { + if (flags_off) { + *flags_off = '|'; + flags_off++; + *flags_off = '\0'; + } else { + flags_off = flags_buf; + } + if (flags & EV_ADD) { + flags_off += sprintf(flags_off, "EV_ADD"); + flags &= ~EV_ADD; + } else if (flags & EV_DELETE) { + flags_off += sprintf(flags_off, "EV_DELETE"); + flags &= ~EV_DELETE; + } else if (flags & EV_ENABLE) { + flags_off += sprintf(flags_off, "EV_ENABLE"); + flags &= ~EV_ENABLE; + } else if (flags & EV_DISABLE) { + flags_off += sprintf(flags_off, "EV_DISABLE"); + flags &= ~EV_DISABLE; + } else if (flags & EV_ONESHOT) { + flags_off += sprintf(flags_off, "EV_ONESHOT"); + flags &= ~EV_ONESHOT; + } else if (flags & EV_CLEAR) { + flags_off += sprintf(flags_off, "EV_CLEAR"); + flags &= ~EV_CLEAR; + } else if (flags & EV_EOF) { + flags_off += sprintf(flags_off, "EV_EOF"); + flags &= ~EV_EOF; + } else if (flags & EV_ERROR) { + flags_off += sprintf(flags_off, "EV_ERROR"); + flags &= ~EV_ERROR; + } else { + flags_off += sprintf(flags_off, "0x%x", flags); + flags = 0; + } + } + + snprintf(ident_buf, sizeof(ident_buf), "%ld", kev->ident); + snprintf(fflags_buf, sizeof(fflags_buf), "0x%x", fflags); + + switch (kev->filter) { + case EVFILT_READ: + filter_str = "EVFILT_READ"; + break; + case EVFILT_WRITE: + filter_str = "EVFILT_WRITE"; + break; + case EVFILT_AIO: + filter_str = "EVFILT_AIO"; + break; + case EVFILT_VNODE: + filter_str = "EVFILT_VNODE"; + if (fflags) while (fflags) { + if (fflags_off) { + *fflags_off = '|'; + fflags_off++; + *fflags_off = '\0'; + } else { + fflags_off = fflags_buf; + } + +#define FFLAGIF(ff) if (fflags & ff) { fflags_off += sprintf(fflags_off, #ff); fflags &= ~ff; } + + FFLAGIF(NOTE_DELETE) + else FFLAGIF(NOTE_WRITE) + else FFLAGIF(NOTE_EXTEND) + else FFLAGIF(NOTE_ATTRIB) + else FFLAGIF(NOTE_LINK) + else FFLAGIF(NOTE_RENAME) + else FFLAGIF(NOTE_REVOKE) + else { + fflags_off += sprintf(fflags_off, "0x%x", fflags); + fflags = 0; + } + } + break; + case EVFILT_PROC: + filter_str = "EVFILT_PROC"; + if (fflags) while (fflags) { + if (fflags_off) { + *fflags_off = '|'; + fflags_off++; + *fflags_off = '\0'; + } else { + fflags_off = fflags_buf; + } + + FFLAGIF(NOTE_EXIT) + else FFLAGIF(NOTE_FORK) + else FFLAGIF(NOTE_EXEC) + else FFLAGIF(NOTE_TRACK) + else FFLAGIF(NOTE_TRACKERR) + else FFLAGIF(NOTE_CHILD) + else { + fflags_off += sprintf(fflags_off, "0x%x", fflags); + fflags = 0; + } + } + break; + case EVFILT_SIGNAL: + filter_str = "EVFILT_SIGNAL"; + switch (kev->ident) { +#define SIG2CASE(sg) case sg: sprintf(ident_buf, #sg); break + SIG2CASE(SIGHUP); + SIG2CASE(SIGINT); + SIG2CASE(SIGQUIT); + SIG2CASE(SIGILL); + SIG2CASE(SIGTRAP); + SIG2CASE(SIGABRT); + SIG2CASE(SIGFPE); + SIG2CASE(SIGKILL); + SIG2CASE(SIGBUS); + SIG2CASE(SIGSEGV); + SIG2CASE(SIGSYS); + SIG2CASE(SIGPIPE); + SIG2CASE(SIGALRM); + SIG2CASE(SIGTERM); + SIG2CASE(SIGURG); + SIG2CASE(SIGSTOP); + SIG2CASE(SIGTSTP); + SIG2CASE(SIGCONT); + SIG2CASE(SIGCHLD); + SIG2CASE(SIGTTIN); + SIG2CASE(SIGTTOU); + SIG2CASE(SIGIO); + SIG2CASE(SIGXCPU); + SIG2CASE(SIGXFSZ); + SIG2CASE(SIGVTALRM); + SIG2CASE(SIGPROF); + SIG2CASE(SIGWINCH); + SIG2CASE(SIGINFO); + SIG2CASE(SIGUSR1); + SIG2CASE(SIGUSR2); + default: + sprintf(ident_buf, "%ld", kev->ident); + break; + } + break; + case EVFILT_TIMER: + filter_str = "EVFILT_TIMER"; + snprintf(ident_buf, sizeof(ident_buf), "0x%lx", kev->ident); + if (fflags) while (fflags) { + if (fflags_off) { + *fflags_off = '|'; + fflags_off++; + *fflags_off = '\0'; + } else { + fflags_off = fflags_buf; + } + + FFLAGIF(NOTE_SECONDS) + else FFLAGIF(NOTE_USECONDS) + else FFLAGIF(NOTE_NSECONDS) + else FFLAGIF(NOTE_ABSOLUTE) + else { + fflags_off += sprintf(fflags_off, "0x%x", fflags); + fflags = 0; + } + } + break; + case EVFILT_MACHPORT: + filter_str = "EVFILT_MACHPORT"; + snprintf(ident_buf, sizeof(ident_buf), "0x%lx", kev->ident); + break; + case EVFILT_FS: + filter_str = "EVFILT_FS"; + break; + default: + snprintf(filter_buf, sizeof(filter_buf), "%d", kev->filter); + filter_str = filter_buf; + break; + } + + syslog(level, "KEVENT: ident = %s filter = %s flags = %s fflags = %s data = 0x%x udata = %p", + ident_buf, filter_str, flags_buf, fflags_buf, kev->data, kev->udata); +} + kern_return_t x_handle_mport(mach_port_t junk __attribute__((unused))) { @@ -166,7 +357,10 @@ if (status.mps_msgcount) { EV_SET(&kev, members[i], EVFILT_MACHPORT, 0, 0, 0, jobmgr_find_by_service_port(root_jobmgr, members[i])); if (launchd_assumes(kev.udata != NULL)) { + log_kevent_struct(LOG_DEBUG, &kev); (*((kq_callback *)kev.udata))(kev.udata, &kev); + } else { + log_kevent_struct(LOG_ERR, &kev); } /* the callback may have tainted our ability to continue this for loop */ break; @@ -207,10 +401,10 @@ if (kevr == 1) { if (launchd_assumes(malloc_size(kev.udata) || dladdr(kev.udata, &dli))) { + log_kevent_struct(LOG_DEBUG, &kev); (*((kq_callback *)kev.udata))(kev.udata, &kev); } else { - syslog(LOG_ERR, "kev.ident == 0x%x kev.filter == 0x%x kev.fflags = 0x%x kev.udata = 0x%x", - kev.ident, kev.filter, kev.fflags, kev.udata); + log_kevent_struct(LOG_ERR, &kev); } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070214/1caff8a8/attachment.html From source_changes at macosforge.org Wed Feb 14 11:51:28 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23063] trunk/launchd/src/launchd_runtime.c Message-ID: <20070214195128.0DAE74A6A5D@cvs.opensource.apple.com> Revision: 23063 http://trac.macosforge.org/projects/launchd/changeset/23063 Author: zarzycki@apple.com Date: 2007-02-14 11:51:27 -0800 (Wed, 14 Feb 2007) Log Message: ----------- Macros for fun and profit. Modified Paths: -------------- trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-14 19:41:31 UTC (rev 23062) +++ trunk/launchd/src/launchd_runtime.c 2007-02-14 19:51:27 UTC (rev 23063) @@ -164,31 +164,18 @@ } else { flags_off = flags_buf; } - if (flags & EV_ADD) { - flags_off += sprintf(flags_off, "EV_ADD"); - flags &= ~EV_ADD; - } else if (flags & EV_DELETE) { - flags_off += sprintf(flags_off, "EV_DELETE"); - flags &= ~EV_DELETE; - } else if (flags & EV_ENABLE) { - flags_off += sprintf(flags_off, "EV_ENABLE"); - flags &= ~EV_ENABLE; - } else if (flags & EV_DISABLE) { - flags_off += sprintf(flags_off, "EV_DISABLE"); - flags &= ~EV_DISABLE; - } else if (flags & EV_ONESHOT) { - flags_off += sprintf(flags_off, "EV_ONESHOT"); - flags &= ~EV_ONESHOT; - } else if (flags & EV_CLEAR) { - flags_off += sprintf(flags_off, "EV_CLEAR"); - flags &= ~EV_CLEAR; - } else if (flags & EV_EOF) { - flags_off += sprintf(flags_off, "EV_EOF"); - flags &= ~EV_EOF; - } else if (flags & EV_ERROR) { - flags_off += sprintf(flags_off, "EV_ERROR"); - flags &= ~EV_ERROR; - } else { + +#define FLAGIF(f) if (flags & f) { flags_off += sprintf(flags_off, #f); flags &= ~f; } + + FLAGIF(EV_ADD) + 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_ERROR) + else { flags_off += sprintf(flags_off, "0x%x", flags); flags = 0; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070214/8c7649aa/attachment.html From source_changes at macosforge.org Wed Feb 14 12:01:09 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23064] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070214200109.572DE4A6AA5@cvs.opensource.apple.com> Revision: 23064 http://trac.macosforge.org/projects/launchd/changeset/23064 Author: zarzycki@apple.com Date: 2007-02-14 12:01:09 -0800 (Wed, 14 Feb 2007) Log Message: ----------- 9A357: hang on startup after install to case sensitive volume 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-02-14 19:51:27 UTC (rev 23063) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-14 20:01:09 UTC (rev 23064) @@ -1963,9 +1963,7 @@ job_log_error(j, LOG_ERR, "kevent()"); job_reap(j); } else { - if (j->ondemand) { - job_ignore(j); - } + job_ignore(j); } if (!j->stall_before_exec) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070214/ca86b314/attachment.html From source_changes at macosforge.org Wed Feb 14 12:14:38 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23065] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070214201438.96B5A4A6AD1@cvs.opensource.apple.com> Revision: 23065 http://trac.macosforge.org/projects/launchd/changeset/23065 Author: zarzycki@apple.com Date: 2007-02-14 12:14:38 -0800 (Wed, 14 Feb 2007) Log Message: ----------- We're not ready to do anything useful with NOTE_EXEC or NOTE_FORK yet. We may never do anything with NOTE_FORK for that matter. 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-02-14 20:01:09 UTC (rev 23064) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-14 20:14:38 UTC (rev 23065) @@ -1802,6 +1802,10 @@ job_log(j, LOG_DEBUG, "Called execve()"); } + if (fflags & NOTE_FORK) { + job_log(j, LOG_DEBUG, "Called fork()"); + } + if (fflags & NOTE_EXIT) { job_reap(j); job_dispatch(j, false); @@ -1959,7 +1963,7 @@ job_assumes(j, close(spair[1]) == 0); ipc_open(_fd(spair[0]), j); } - if (kevent_mod(c, EVFILT_PROC, EV_ADD, NOTE_EXEC|NOTE_EXIT, 0, &j->kqjob_callback) == -1) { + if (kevent_mod(c, EVFILT_PROC, EV_ADD, /* NOTE_EXEC|NOTE_FORK| */ NOTE_EXIT, 0, &j->kqjob_callback) == -1) { job_log_error(j, LOG_ERR, "kevent()"); job_reap(j); } else { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070214/d737709e/attachment.html From source_changes at macosforge.org Wed Feb 14 13:45:02 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23066] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070214214502.9A4F14A6BFC@cvs.opensource.apple.com> Revision: 23066 http://trac.macosforge.org/projects/launchd/changeset/23066 Author: zarzycki@apple.com Date: 2007-02-14 13:45:02 -0800 (Wed, 14 Feb 2007) Log Message: ----------- Compile time assert tricks are cool. 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-02-14 20:14:38 UTC (rev 23065) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-14 21:45:02 UTC (rev 23066) @@ -919,6 +919,7 @@ job_t job_new(jobmgr_t jm, const char *label, const char *prog, const char *const *argv, const char *stdinpath) { + char compile_time_assert[offsetof(struct job_s, kqjob_callback) == 0 ? 1 : -1] __attribute__((unused)); const char *const *argv_tmp = argv; char *co; int i, cc = 0; @@ -1963,7 +1964,7 @@ job_assumes(j, 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, &j->kqjob_callback) == -1) { + if (kevent_mod(c, EVFILT_PROC, EV_ADD, /* NOTE_EXEC|NOTE_FORK| */ NOTE_EXIT, 0, j) == -1) { job_log_error(j, LOG_ERR, "kevent()"); job_reap(j); } else { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070214/ca66cd8d/attachment.html From source_changes at macosforge.org Wed Feb 14 13:45:13 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23067] tags/launchd-195/ Message-ID: <20070214214513.627A94A6C00@cvs.opensource.apple.com> Revision: 23067 http://trac.macosforge.org/projects/launchd/changeset/23067 Author: zarzycki@apple.com Date: 2007-02-14 13:45:13 -0800 (Wed, 14 Feb 2007) Log Message: ----------- "Tagging launchd-195 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-195/ Copied: tags/launchd-195 (from rev 23066, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070214/32311131/attachment.html From source_changes at macosforge.org Thu Feb 15 08:12:24 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23068] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070215161224.E49E94A72AC@cvs.opensource.apple.com> Revision: 23068 http://trac.macosforge.org/projects/launchd/changeset/23068 Author: zarzycki@apple.com Date: 2007-02-15 08:12:24 -0800 (Thu, 15 Feb 2007) Log Message: ----------- launchd restarting on-demand service 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-02-14 21:45:13 UTC (rev 23067) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-15 16:12:24 UTC (rev 23068) @@ -687,9 +687,6 @@ if (j->start_interval) { job_assumes(j, kevent_mod((uintptr_t)&j->start_interval, EVFILT_TIMER, EV_DELETE, 0, 0, NULL) != -1); } - if (j->exit_timeout) { - kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); - } kevent_mod((uintptr_t)j, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); @@ -1654,6 +1651,10 @@ return; } + if (j->exit_timeout) { + kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); + } + total_children--; /* Performance hack */ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070215/25b74351/attachment.html From source_changes at macosforge.org Thu Feb 15 08:12:49 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23069] trunk/launchd/src Message-ID: <20070215161249.344BB4A72B8@cvs.opensource.apple.com> Revision: 23069 http://trac.macosforge.org/projects/launchd/changeset/23069 Author: zarzycki@apple.com Date: 2007-02-15 08:12:48 -0800 (Thu, 15 Feb 2007) Log Message: ----------- Documentation update. Modified Paths: -------------- trunk/launchd/src/launchd.plist.5 trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd.plist.5 =================================================================== --- trunk/launchd/src/launchd.plist.5 2007-02-15 16:12:24 UTC (rev 23068) +++ trunk/launchd/src/launchd.plist.5 2007-02-15 16:12:48 UTC (rev 23069) @@ -232,7 +232,7 @@ .It Sy WaitForDebugger This optional key specifies that .Nm launchd -should instruct the kernel to have the job wait for a debugger to attach before any code in the job is executed. +should instruct the kernel to have the job wait for a debugger to attach before any code in the job is executed. This feature may not work due to bug 4438161. .It Sy SoftResourceLimits .It Sy HardResourceLimits Resource limits to be imposed on the job. These adjust variables set with Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-15 16:12:24 UTC (rev 23068) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-15 16:12:48 UTC (rev 23069) @@ -2027,6 +2027,7 @@ } if (j->wait4debugger) { + /* 4438161 gdb hangs when trying to attach to SIGSTOPed processes (breaks launchd's "WaitForDebugger") */ spflags |= POSIX_SPAWN_START_SUSPENDED; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070215/50317b1c/attachment.html From source_changes at macosforge.org Thu Feb 15 10:26:23 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23070] trunk/launchd/src Message-ID: <20070215182623.143884A73B5@cvs.opensource.apple.com> Revision: 23070 http://trac.macosforge.org/projects/launchd/changeset/23070 Author: zarzycki@apple.com Date: 2007-02-15 10:26:22 -0800 (Thu, 15 Feb 2007) Log Message: ----------- poweroff() API to wrap reboot() Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/libvproc.c trunk/launchd/src/protocol_job.defs Added Paths: ----------- trunk/launchd/src/poweroff.h Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-02-15 16:12:48 UTC (rev 23069) +++ trunk/launchd/src/Makefile.am 2007-02-15 18:26:22 UTC (rev 23070) @@ -89,6 +89,7 @@ mkdir -p $(DESTDIR)/usr/local/include cp $(srcdir)/liblaunch_private.h $(DESTDIR)/usr/local/include/launch_priv.h cp $(srcdir)/libvproc_private.h $(DESTDIR)/usr/local/include/vproc_priv.h + cp $(srcdir)/poweroff.h $(DESTDIR)/usr/local/include/poweroff.h mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init.d mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init_per_user.d mkdir -p $(DESTDIR)/Library/LaunchDaemons Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-02-15 16:12:48 UTC (rev 23069) +++ trunk/launchd/src/Makefile.in 2007-02-15 18:26:22 UTC (rev 23070) @@ -1103,6 +1103,7 @@ @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/usr/local/include @LIBS_ONLY_FALSE@ cp $(srcdir)/liblaunch_private.h $(DESTDIR)/usr/local/include/launch_priv.h @LIBS_ONLY_FALSE@ cp $(srcdir)/libvproc_private.h $(DESTDIR)/usr/local/include/vproc_priv.h +@LIBS_ONLY_FALSE@ cp $(srcdir)/poweroff.h $(DESTDIR)/usr/local/include/poweroff.h @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init.d @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init_per_user.d @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/Library/LaunchDaemons Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-15 16:12:48 UTC (rev 23069) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-15 18:26:22 UTC (rev 23070) @@ -80,6 +80,8 @@ #include "libvproc_public.h" #include "libvproc_internal.h" +#include "poweroff.h" + #include "launchd.h" #include "launchd_runtime.h" #include "launchd_unix_ipc.h" @@ -201,7 +203,7 @@ char *jm_stdout; char *jm_stderr; unsigned int global_on_demand_cnt; - unsigned int transfer_bstrap:1, sent_stop_to_hopeful_jobs:1, shutting_down:1; + unsigned int transfer_bstrap:1, sent_stop_to_hopeful_jobs:1, shutting_down:1, power_cycle:1; char name[0]; }; @@ -586,7 +588,7 @@ SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); jobmgr_tickle(jm->parentmgr); } else if (getpid() == 1) { - jobmgr_assumes(jm, reboot(RB_HALT) != -1); + jobmgr_assumes(jm, reboot(jm->power_cycle ? RB_AUTOBOOT : RB_HALT) != -1); } else { exit(EXIT_SUCCESS); } @@ -4111,6 +4113,30 @@ } kern_return_t +job_mig_poweroff(job_t j, uint64_t flags) +{ + struct ldcred ldc; + + if (getpid() != 1) { + return BOOTSTRAP_NOT_PRIVILEGED; + } + + runtime_get_caller_creds(&ldc); + + if (ldc.euid) { + return BOOTSTRAP_NOT_PRIVILEGED; + } + + if (flags & POWEROFF_RESET) { + root_jobmgr->power_cycle = true; + } + + launchd_shutdown(); + + return 0; +} + +kern_return_t job_mig_set_integer(job_t j, get_set_int_key_t key, int64_t val) { kern_return_t kr = 0; Modified: trunk/launchd/src/libvproc.c =================================================================== --- trunk/launchd/src/libvproc.c 2007-02-15 16:12:48 UTC (rev 23069) +++ trunk/launchd/src/libvproc.c 2007-02-15 18:26:22 UTC (rev 23070) @@ -36,6 +36,8 @@ #include "protocol_vproc.h" +#include "poweroff.h" + 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, @@ -217,6 +219,34 @@ return (vproc_err_t)__vproc_tag_loginwindow_context; } +void * +poweroff(uint64_t flags) +{ + mach_port_t parent_port = 0; + mach_port_t previous_port = 0; + + do { + if (previous_port) { + mach_port_deallocate(mach_task_self(), previous_port); + previous_port = parent_port; + } else { + previous_port = bootstrap_port; + } + + if (bootstrap_parent(previous_port, &parent_port) != 0) { + goto out_bad; + } + + } while (parent_port != previous_port); + + if (vproc_mig_poweroff(parent_port, flags) == 0) { + return NULL; + } + +out_bad: + return poweroff; +} + vproc_err_t _vproc_set_global_on_demand(bool state) { Added: trunk/launchd/src/poweroff.h =================================================================== --- trunk/launchd/src/poweroff.h (rev 0) +++ trunk/launchd/src/poweroff.h 2007-02-15 18:26:22 UTC (rev 23070) @@ -0,0 +1,36 @@ +#ifndef _POWEROFF_H_ +#define _POWEROFF_H_ +/* + * Copyright (c) 2007 Apple 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@ + */ + +#include +#include + +__BEGIN_DECLS + +#define POWEROFF_RESET 1 + +/* Returns NULL on success. Not NULL on failure */ + +__attribute__((visibility("default"))) void *poweroff(uint64_t flags); + +__END_DECLS + +#endif Modified: trunk/launchd/src/protocol_job.defs =================================================================== --- trunk/launchd/src/protocol_job.defs 2007-02-15 16:12:48 UTC (rev 23069) +++ trunk/launchd/src/protocol_job.defs 2007-02-15 18:26:22 UTC (rev 23070) @@ -41,7 +41,9 @@ __on_demand : boolean_t; out __server_port : mach_port_make_send_t); -skip; /* Last used in 10.4. Was bootstrap_unprivileged() */ +routine poweroff( + __bs_port : job_t; + __flags : uint64_t); routine check_in( __bs_port : job_t; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070215/20d01ba6/attachment.html From source_changes at macosforge.org Thu Feb 15 10:54:56 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23071] trunk/launchd/src Message-ID: <20070215185456.062D54A7408@cvs.opensource.apple.com> Revision: 23071 http://trac.macosforge.org/projects/launchd/changeset/23071 Author: zarzycki@apple.com Date: 2007-02-15 10:54:55 -0800 (Thu, 15 Feb 2007) Log Message: ----------- Add a UPS flag. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/poweroff.h Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-15 18:26:22 UTC (rev 23070) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-15 18:54:55 UTC (rev 23071) @@ -203,7 +203,7 @@ char *jm_stdout; char *jm_stderr; unsigned int global_on_demand_cnt; - unsigned int transfer_bstrap:1, sent_stop_to_hopeful_jobs:1, shutting_down:1, power_cycle:1; + unsigned int transfer_bstrap:1, sent_stop_to_hopeful_jobs:1, shutting_down:1, power_cycle:1, ups_delay:1; char name[0]; }; @@ -588,7 +588,16 @@ SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); jobmgr_tickle(jm->parentmgr); } else if (getpid() == 1) { - jobmgr_assumes(jm, reboot(jm->power_cycle ? RB_AUTOBOOT : RB_HALT) != -1); + int flags = 0; + + if (!jm->power_cycle) { + flags |= RB_HALT; + } + if (!jm->ups_delay) { + flags |= RB_UPSDELAY; + } + + jobmgr_assumes(jm, reboot(flags) != -1); } else { exit(EXIT_SUCCESS); } @@ -4130,6 +4139,9 @@ if (flags & POWEROFF_RESET) { root_jobmgr->power_cycle = true; } + if (flags & POWEROFF_UPSDELAY) { + root_jobmgr->ups_delay = true; + } launchd_shutdown(); Modified: trunk/launchd/src/poweroff.h =================================================================== --- trunk/launchd/src/poweroff.h 2007-02-15 18:26:22 UTC (rev 23070) +++ trunk/launchd/src/poweroff.h 2007-02-15 18:54:55 UTC (rev 23071) @@ -26,6 +26,7 @@ __BEGIN_DECLS #define POWEROFF_RESET 1 +#define POWEROFF_UPSDELAY 2 /* Returns NULL on success. Not NULL on failure */ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070215/81344019/attachment.html From source_changes at macosforge.org Thu Feb 15 10:57:17 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:40 2007 Subject: [launchd-changes] [23072] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070215185717.CF91B4A7410@cvs.opensource.apple.com> Revision: 23072 http://trac.macosforge.org/projects/launchd/changeset/23072 Author: zarzycki@apple.com Date: 2007-02-15 10:57:17 -0800 (Thu, 15 Feb 2007) Log Message: ----------- Copy/paste error. 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-02-15 18:54:55 UTC (rev 23071) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-15 18:57:17 UTC (rev 23072) @@ -593,7 +593,7 @@ if (!jm->power_cycle) { flags |= RB_HALT; } - if (!jm->ups_delay) { + if (jm->ups_delay) { flags |= RB_UPSDELAY; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070215/d8640463/attachment.html From source_changes at macosforge.org Thu Feb 15 14:18:08 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23073] trunk/launchd/src Message-ID: <20070215221808.691014A7616@cvs.opensource.apple.com> Revision: 23073 http://trac.macosforge.org/projects/launchd/changeset/23073 Author: zarzycki@apple.com Date: 2007-02-15 14:18:08 -0800 (Thu, 15 Feb 2007) Log Message: ----------- On second thought, let's call the poweroff() API "reboot2()" and just pass the reboot flags down opaquely. Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/libvproc.c trunk/launchd/src/protocol_job.defs Added Paths: ----------- trunk/launchd/src/reboot2.h Removed Paths: ------------- trunk/launchd/src/poweroff.h Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-02-15 18:57:17 UTC (rev 23072) +++ trunk/launchd/src/Makefile.am 2007-02-15 22:18:08 UTC (rev 23073) @@ -89,7 +89,7 @@ mkdir -p $(DESTDIR)/usr/local/include cp $(srcdir)/liblaunch_private.h $(DESTDIR)/usr/local/include/launch_priv.h cp $(srcdir)/libvproc_private.h $(DESTDIR)/usr/local/include/vproc_priv.h - cp $(srcdir)/poweroff.h $(DESTDIR)/usr/local/include/poweroff.h + cp $(srcdir)/reboot2.h $(DESTDIR)/usr/local/include/reboot2.h mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init.d mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init_per_user.d mkdir -p $(DESTDIR)/Library/LaunchDaemons Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-02-15 18:57:17 UTC (rev 23072) +++ trunk/launchd/src/Makefile.in 2007-02-15 22:18:08 UTC (rev 23073) @@ -1103,7 +1103,7 @@ @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/usr/local/include @LIBS_ONLY_FALSE@ cp $(srcdir)/liblaunch_private.h $(DESTDIR)/usr/local/include/launch_priv.h @LIBS_ONLY_FALSE@ cp $(srcdir)/libvproc_private.h $(DESTDIR)/usr/local/include/vproc_priv.h -@LIBS_ONLY_FALSE@ cp $(srcdir)/poweroff.h $(DESTDIR)/usr/local/include/poweroff.h +@LIBS_ONLY_FALSE@ cp $(srcdir)/reboot2.h $(DESTDIR)/usr/local/include/reboot2.h @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init.d @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init_per_user.d @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/Library/LaunchDaemons Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-15 18:57:17 UTC (rev 23072) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-15 22:18:08 UTC (rev 23073) @@ -80,7 +80,7 @@ #include "libvproc_public.h" #include "libvproc_internal.h" -#include "poweroff.h" +#include "reboot2.h" #include "launchd.h" #include "launchd_runtime.h" @@ -202,8 +202,9 @@ job_t anonj; char *jm_stdout; char *jm_stderr; + int reboot_flags; unsigned int global_on_demand_cnt; - unsigned int transfer_bstrap:1, sent_stop_to_hopeful_jobs:1, shutting_down:1, power_cycle:1, ups_delay:1; + unsigned int transfer_bstrap:1, sent_stop_to_hopeful_jobs:1, shutting_down:1; char name[0]; }; @@ -588,16 +589,7 @@ SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); jobmgr_tickle(jm->parentmgr); } else if (getpid() == 1) { - int flags = 0; - - if (!jm->power_cycle) { - flags |= RB_HALT; - } - if (jm->ups_delay) { - flags |= RB_UPSDELAY; - } - - jobmgr_assumes(jm, reboot(flags) != -1); + jobmgr_assumes(jm, reboot(jm->reboot_flags) != -1); } else { exit(EXIT_SUCCESS); } @@ -4122,7 +4114,7 @@ } kern_return_t -job_mig_poweroff(job_t j, uint64_t flags) +job_mig_reboot2(job_t j, uint64_t flags) { struct ldcred ldc; @@ -4136,12 +4128,7 @@ return BOOTSTRAP_NOT_PRIVILEGED; } - if (flags & POWEROFF_RESET) { - root_jobmgr->power_cycle = true; - } - if (flags & POWEROFF_UPSDELAY) { - root_jobmgr->ups_delay = true; - } + root_jobmgr->reboot_flags = (int)flags; launchd_shutdown(); Modified: trunk/launchd/src/libvproc.c =================================================================== --- trunk/launchd/src/libvproc.c 2007-02-15 18:57:17 UTC (rev 23072) +++ trunk/launchd/src/libvproc.c 2007-02-15 22:18:08 UTC (rev 23073) @@ -36,7 +36,7 @@ #include "protocol_vproc.h" -#include "poweroff.h" +#include "reboot2.h" kern_return_t _vproc_grab_subset(mach_port_t bp, mach_port_t *reqport, mach_port_t *rcvright, @@ -220,7 +220,7 @@ } void * -poweroff(uint64_t flags) +reboot2(uint64_t flags) { mach_port_t parent_port = 0; mach_port_t previous_port = 0; @@ -239,12 +239,12 @@ } while (parent_port != previous_port); - if (vproc_mig_poweroff(parent_port, flags) == 0) { + if (vproc_mig_reboot2(parent_port, flags) == 0) { return NULL; } out_bad: - return poweroff; + return reboot2; } vproc_err_t Deleted: trunk/launchd/src/poweroff.h =================================================================== --- trunk/launchd/src/poweroff.h 2007-02-15 18:57:17 UTC (rev 23072) +++ trunk/launchd/src/poweroff.h 2007-02-15 22:18:08 UTC (rev 23073) @@ -1,37 +0,0 @@ -#ifndef _POWEROFF_H_ -#define _POWEROFF_H_ -/* - * Copyright (c) 2007 Apple 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@ - */ - -#include -#include - -__BEGIN_DECLS - -#define POWEROFF_RESET 1 -#define POWEROFF_UPSDELAY 2 - -/* Returns NULL on success. Not NULL on failure */ - -__attribute__((visibility("default"))) void *poweroff(uint64_t flags); - -__END_DECLS - -#endif Modified: trunk/launchd/src/protocol_job.defs =================================================================== --- trunk/launchd/src/protocol_job.defs 2007-02-15 18:57:17 UTC (rev 23072) +++ trunk/launchd/src/protocol_job.defs 2007-02-15 22:18:08 UTC (rev 23073) @@ -41,7 +41,7 @@ __on_demand : boolean_t; out __server_port : mach_port_make_send_t); -routine poweroff( +routine reboot2( __bs_port : job_t; __flags : uint64_t); Copied: trunk/launchd/src/reboot2.h (from rev 23071, trunk/launchd/src/poweroff.h) =================================================================== --- trunk/launchd/src/reboot2.h (rev 0) +++ trunk/launchd/src/reboot2.h 2007-02-15 22:18:08 UTC (rev 23073) @@ -0,0 +1,35 @@ +#ifndef _REBOOT2_H_ +#define _REBOOT2_H_ +/* + * Copyright (c) 2007 Apple 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@ + */ + +#include +#include +#include + +__BEGIN_DECLS + +/* Returns NULL on success. Not NULL on failure */ + +__attribute__((visibility("default"))) void *reboot2(uint64_t flags); + +__END_DECLS + +#endif -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070215/ca433288/attachment.html From source_changes at macosforge.org Thu Feb 15 14:21:08 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23074] tags/launchd-196/ Message-ID: <20070215222108.55B6E4A7624@cvs.opensource.apple.com> Revision: 23074 http://trac.macosforge.org/projects/launchd/changeset/23074 Author: zarzycki@apple.com Date: 2007-02-15 14:21:08 -0800 (Thu, 15 Feb 2007) Log Message: ----------- "Tagging launchd-196 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-196/ Copied: tags/launchd-196 (from rev 23073, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070215/42cb1e93/attachment.html From source_changes at macosforge.org Thu Feb 15 18:51:55 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23075] trunk/launchd/src Message-ID: <20070216025155.53E004A791F@cvs.opensource.apple.com> Revision: 23075 http://trac.macosforge.org/projects/launchd/changeset/23075 Author: zarzycki@apple.com Date: 2007-02-15 18:51:55 -0800 (Thu, 15 Feb 2007) Log Message: ----------- Remove the "gc_this_jobmgr" hack and other cleanup. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_core_logic.h trunk/launchd/src/launchd_runtime.c trunk/launchd/src/protocol_job.defs Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-15 22:21:08 UTC (rev 23074) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-16 02:51:55 UTC (rev 23075) @@ -204,7 +204,7 @@ char *jm_stderr; int reboot_flags; unsigned int global_on_demand_cnt; - unsigned int transfer_bstrap:1, sent_stop_to_hopeful_jobs:1, shutting_down:1; + unsigned int sent_stop_to_hopeful_jobs:1, shutting_down:1; char name[0]; }; @@ -213,14 +213,13 @@ static jobmgr_t jobmgr_new(jobmgr_t jm, mach_port_t requestorport, mach_port_t checkin_port); static jobmgr_t jobmgr_parent(jobmgr_t jm); -static jobmgr_t jobmgr_tickle(jobmgr_t jm); +static jobmgr_t jobmgr_do_garbage_collection(jobmgr_t jm); 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); static job_t jobmgr_new_anonymous(jobmgr_t jm); static job_t job_mig_intran2(jobmgr_t jm, mach_port_t p); -static mach_port_t jobmgr_get_reqport(jobmgr_t jm); static void job_export_all2(jobmgr_t jm, launch_data_t where); static pid_t jobmgr_fork(jobmgr_t jm); static void jobmgr_setup_env_from_other_jobs(jobmgr_t jm); @@ -353,7 +352,6 @@ static int dir_has_files(job_t j, const char *path); static char **mach_cmd2argv(const char *string); jobmgr_t root_jobmgr; -jobmgr_t gc_this_jobmgr; void job_ignore(job_t j) @@ -526,6 +524,8 @@ jobmgr_log(jm, LOG_DEBUG, "Beginning job manager shutdown"); + jm->shutting_down = true; + SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { jobmgr_shutdown(jmi); } @@ -538,9 +538,7 @@ } } - jm->shutting_down = true; - - return jobmgr_tickle(jm); + return jobmgr_do_garbage_collection(jm); } void @@ -559,7 +557,12 @@ /* We should have one job left and it should be the anonymous job */ ji = TAILQ_FIRST(&jm->jobs); - jobmgr_assumes(jm, ji && ji == jm->anonj && (TAILQ_NEXT(ji, sle) == NULL)); + if (!(jobmgr_assumes(jm, ji != NULL) && jobmgr_assumes(jm, ji == jm->anonj) + && jobmgr_assumes(jm, TAILQ_NEXT(ji, sle) == NULL))) { + TAILQ_FOREACH(ji, &jm->jobs, sle) { + job_log(ji, LOG_ERR, "Still remaining at removal."); + } + } while ((ji = TAILQ_FIRST(&jm->jobs))) { job_remove(ji); @@ -570,11 +573,7 @@ } if (jm->jm_port) { - if (jm->transfer_bstrap) { - jobmgr_assumes(jm, launchd_mport_deallocate(jm->jm_port) == KERN_SUCCESS); - } else { - jobmgr_assumes(jm, launchd_mport_close_recv(jm->jm_port) == KERN_SUCCESS); - } + jobmgr_assumes(jm, launchd_mport_close_recv(jm->jm_port) == KERN_SUCCESS); } if (jm->jm_stdout) { @@ -587,7 +586,6 @@ if (jm->parentmgr) { SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); - jobmgr_tickle(jm->parentmgr); } else if (getpid() == 1) { jobmgr_assumes(jm, reboot(jm->reboot_flags) != -1); } else { @@ -695,7 +693,6 @@ if (job_assumes(j, j->mgr)) { TAILQ_REMOVE(&j->mgr->jobs, j, sle); - jobmgr_tickle(j->mgr); } job_log(j, LOG_DEBUG, "Removed"); @@ -1814,6 +1811,10 @@ if (fflags & NOTE_EXIT) { job_reap(j); job_dispatch(j, false); + + if (launchd_assumes(root_jobmgr != NULL)) { + root_jobmgr = jobmgr_do_garbage_collection(root_jobmgr); + } } } @@ -3247,32 +3248,45 @@ } jobmgr_t -jobmgr_tickle(jobmgr_t jm) +jobmgr_do_garbage_collection(jobmgr_t jm) { + jobmgr_t jmi, jmn; job_t ji; - if (jm->sent_stop_to_hopeful_jobs || !jm->shutting_down) { + SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { + jobmgr_do_garbage_collection(jmi); + } + + if (!jm->shutting_down) { return jm; } + jobmgr_log(jm, LOG_DEBUG, "Garbage collecting."); + + if (jobmgr_is_idle(jm)) { + jobmgr_log_stray_children(jm); + jobmgr_remove(jm); + return NULL; + } + + if (jm->sent_stop_to_hopeful_jobs) { + return jm; + } + TAILQ_FOREACH(ji, &jm->jobs, sle) { if (ji->p && !ji->hopefully_exits_last) { return jm; } } + jobmgr_log(jm, LOG_DEBUG, "Asking \"hopeful\" jobs to exit."); + TAILQ_FOREACH(ji, &jm->jobs, sle) { job_stop(ji); } jm->sent_stop_to_hopeful_jobs = true; - if (jobmgr_is_idle(jm)) { - jobmgr_log_stray_children(jm); - jobmgr_remove(jm); - return NULL; - } - return jm; } @@ -3461,7 +3475,7 @@ return NULL; } -void +jobmgr_t jobmgr_delete_anything_with_port(jobmgr_t jm, mach_port_t port) { struct machservice *ms, *next_ms; @@ -3478,10 +3492,6 @@ * to use. */ - if (jm->req_port == port) { - jobmgr_shutdown(jm); - } - SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { jobmgr_delete_anything_with_port(jmi, port); } @@ -3493,6 +3503,12 @@ } } } + + if (jm->req_port == port) { + return jobmgr_shutdown(jm); + } + + return jm; } struct machservice * @@ -3688,15 +3704,6 @@ job_dispatch(j, false); } -mach_port_t -jobmgr_get_reqport(jobmgr_t jm) -{ - jm->transfer_bstrap = true; - gc_this_jobmgr = jm; - - return jm->req_port; -} - jobmgr_t job_get_bs(job_t j) { @@ -4609,6 +4616,8 @@ SLIST_FOREACH(ms, &j->machservices, sle) { strlcpy(service_names[cnt2], machservice_name(ms), sizeof(service_names[0])); ports[cnt2] = machservice_port(ms); + /* Increment the send right by one so we can shutdown the jobmgr cleanly */ + jobmgr_assumes(jm, (errno = mach_port_mod_refs(mach_task_self(), ports[cnt2], MACH_PORT_RIGHT_SEND, 1)) == 0); cnt2++; } @@ -4618,12 +4627,13 @@ *portsp = ports; *servicenames_cnt = *ports_cnt = cnt; - *reqport = jobmgr_get_reqport(jm); + *reqport = jm->req_port; *rcvright = jm->jm_port; - launchd_assumes(runtime_remove_mport(*rcvright) == KERN_SUCCESS); + jm->req_port = 0; + jm->jm_port = 0; - launchd_assumes(launchd_mport_make_send(*rcvright) == KERN_SUCCESS); + jobmgr_shutdown(jm); return BOOTSTRAP_SUCCESS; Modified: trunk/launchd/src/launchd_core_logic.h =================================================================== --- trunk/launchd/src/launchd_core_logic.h 2007-02-15 22:21:08 UTC (rev 23074) +++ trunk/launchd/src/launchd_core_logic.h 2007-02-16 02:51:55 UTC (rev 23075) @@ -27,14 +27,13 @@ typedef struct jobmgr_s *jobmgr_t; extern jobmgr_t root_jobmgr; -extern jobmgr_t gc_this_jobmgr; void jobmgr_set_stdout(jobmgr_t jm, const char *what); void jobmgr_set_stderr(jobmgr_t jm, const char *what); jobmgr_t jobmgr_shutdown(jobmgr_t jm); 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); +jobmgr_t jobmgr_delete_anything_with_port(jobmgr_t jm, mach_port_t port); bool jobmgr_ack_port_destruction(jobmgr_t jm, mach_port_t p); job_t jobmgr_find_by_service_port(jobmgr_t jm, mach_port_t p); Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-15 22:21:08 UTC (rev 23074) +++ trunk/launchd/src/launchd_runtime.c 2007-02-16 02:51:55 UTC (rev 23075) @@ -659,7 +659,9 @@ inherited_bootstrap_port = MACH_PORT_NULL; } - jobmgr_delete_anything_with_port(root_jobmgr, name); + if (launchd_assumes(root_jobmgr != NULL)) { + root_jobmgr = jobmgr_delete_anything_with_port(root_jobmgr, name); + } /* A dead-name notification about a port appears to increment the * rights on said port. Let's deallocate it so that we don't leak @@ -760,12 +762,6 @@ bufRequest = bufReply; bufReply = bufTemp; - /* XXX - So very gross */ - if (gc_this_jobmgr) { - jobmgr_shutdown(gc_this_jobmgr); - gc_this_jobmgr = NULL; - } - if (!(tmp_options & MACH_RCV_MSG)) { continue; } Modified: trunk/launchd/src/protocol_job.defs =================================================================== --- trunk/launchd/src/protocol_job.defs 2007-02-15 22:21:08 UTC (rev 23074) +++ trunk/launchd/src/protocol_job.defs 2007-02-16 02:51:55 UTC (rev 23075) @@ -31,6 +31,10 @@ import "libvproc_public.h"; import "libvproc_internal.h"; +type mach_port_move_send_array_t = array[] of mach_port_move_send_t + ctype: mach_port_array_t; + + userprefix vproc_mig_; serverprefix job_mig_; @@ -85,10 +89,10 @@ routine take_subset( __bs_port : job_t; - out __bs_reqport : mach_port_t; + out __bs_reqport : mach_port_move_send_t; out __bs_rcvright : mach_port_move_receive_t; out __service_names : name_array_t, dealloc; - out __service_ports : mach_port_array_t, dealloc); + out __service_ports : mach_port_move_send_array_t, dealloc); routine getsocket( __bs_port : job_t; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070215/58cc5421/attachment.html From source_changes at macosforge.org Thu Feb 15 19:17:34 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23076] trunk/launchd/src Message-ID: <20070216031734.891124A7951@cvs.opensource.apple.com> Revision: 23076 http://trac.macosforge.org/projects/launchd/changeset/23076 Author: zarzycki@apple.com Date: 2007-02-15 19:17:34 -0800 (Thu, 15 Feb 2007) Log Message: ----------- change to stackshot mechanism is yielding bogus stackshot logs Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/launchd.c Removed Paths: ------------- trunk/launchd/src/shutdown_debugger.8 trunk/launchd/src/shutdown_debugger.c Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-02-16 02:51:55 UTC (rev 23075) +++ trunk/launchd/src/Makefile.am 2007-02-16 03:17:34 UTC (rev 23076) @@ -32,7 +32,7 @@ bin_PROGRAMS = launchctl wait4path sbin_PROGRAMS = launchd SystemStarter -libexec_PROGRAMS = launchproxy shutdown_debugger +libexec_PROGRAMS = launchproxy sysconf_DATA = hostconfig rc.common rc.netboot rc.shutdown @@ -66,7 +66,7 @@ man5_MANS = launchd.plist.5 launchd.conf.5 -man8_MANS = StartupItemContext.8 SystemStarter.8 rc.8 launchd.8 service.8 launchproxy.8 shutdown_debugger.8 +man8_MANS = StartupItemContext.8 SystemStarter.8 rc.8 launchd.8 service.8 launchproxy.8 STARTUPITEMS = $(basename $(notdir $(wildcard $(srcdir)/StartupItems/*.plist))) Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-02-16 02:51:55 UTC (rev 23075) +++ trunk/launchd/src/Makefile.in 2007-02-16 03:17:34 UTC (rev 23076) @@ -40,8 +40,7 @@ @LIBS_ONLY_FALSE@bin_PROGRAMS = launchctl$(EXEEXT) wait4path$(EXEEXT) @LIBS_ONLY_FALSE@sbin_PROGRAMS = launchd$(EXEEXT) \ @LIBS_ONLY_FALSE@ SystemStarter$(EXEEXT) -@LIBS_ONLY_FALSE@libexec_PROGRAMS = launchproxy$(EXEEXT) \ -@LIBS_ONLY_FALSE@ shutdown_debugger$(EXEEXT) +@LIBS_ONLY_FALSE@libexec_PROGRAMS = launchproxy$(EXEEXT) subdir = src DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(srcdir)/config.h.in @@ -110,9 +109,6 @@ launchproxy_SOURCES = launchproxy.c launchproxy_OBJECTS = launchproxy.$(OBJEXT) launchproxy_LDADD = $(LDADD) -shutdown_debugger_SOURCES = shutdown_debugger.c -shutdown_debugger_OBJECTS = shutdown_debugger.$(OBJEXT) -shutdown_debugger_LDADD = $(LDADD) wait4path_SOURCES = wait4path.c wait4path_OBJECTS = wait4path.$(OBJEXT) wait4path_LDADD = $(LDADD) @@ -127,12 +123,11 @@ LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ SOURCES = $(liblaunch_a_SOURCES) $(liblaunch_profile_a_SOURCES) \ $(SystemStarter_SOURCES) launchctl.c $(launchd_SOURCES) \ - launchproxy.c shutdown_debugger.c wait4path.c + launchproxy.c wait4path.c DIST_SOURCES = $(am__liblaunch_a_SOURCES_DIST) \ $(am__liblaunch_profile_a_SOURCES_DIST) \ $(am__SystemStarter_SOURCES_DIST) launchctl.c \ - $(am__launchd_SOURCES_DIST) launchproxy.c shutdown_debugger.c \ - wait4path.c + $(am__launchd_SOURCES_DIST) launchproxy.c wait4path.c man1dir = $(mandir)/man1 man5dir = $(mandir)/man5 man8dir = $(mandir)/man8 @@ -253,7 +248,7 @@ @LIBS_ONLY_FALSE@launchproxy_LDFLAGS = -weak_framework Security @LIBS_ONLY_FALSE@man1_MANS = wait4path.1 launchctl.1 @LIBS_ONLY_FALSE@man5_MANS = launchd.plist.5 launchd.conf.5 -@LIBS_ONLY_FALSE@man8_MANS = StartupItemContext.8 SystemStarter.8 rc.8 launchd.8 service.8 launchproxy.8 shutdown_debugger.8 +@LIBS_ONLY_FALSE@man8_MANS = StartupItemContext.8 SystemStarter.8 rc.8 launchd.8 service.8 launchproxy.8 @LIBS_ONLY_FALSE@STARTUPITEMS = $(basename $(notdir $(wildcard $(srcdir)/StartupItems/*.plist))) all: config.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -398,9 +393,6 @@ launchproxy$(EXEEXT): $(launchproxy_OBJECTS) $(launchproxy_DEPENDENCIES) @rm -f launchproxy$(EXEEXT) $(LINK) $(launchproxy_LDFLAGS) $(launchproxy_OBJECTS) $(launchproxy_LDADD) $(LIBS) -shutdown_debugger$(EXEEXT): $(shutdown_debugger_OBJECTS) $(shutdown_debugger_DEPENDENCIES) - @rm -f shutdown_debugger$(EXEEXT) - $(LINK) $(shutdown_debugger_LDFLAGS) $(shutdown_debugger_OBJECTS) $(shutdown_debugger_LDADD) $(LIBS) wait4path$(EXEEXT): $(wait4path_OBJECTS) $(wait4path_DEPENDENCIES) @rm -f wait4path$(EXEEXT) $(LINK) $(wait4path_LDFLAGS) $(wait4path_OBJECTS) $(wait4path_LDADD) $(LIBS) @@ -453,7 +445,6 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblaunch_profile_a-protocol_vprocUser.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvproc.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protocol_vprocUser.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shutdown_debugger.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wait4path.Po@am__quote@ .c.o: Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-02-16 02:51:55 UTC (rev 23075) +++ trunk/launchd/src/launchd.c 2007-02-16 03:17:34 UTC (rev 23076) @@ -79,15 +79,15 @@ #define PID1LAUNCHD_CONF "/etc/launchd.conf" #define LAUNCHD_CONF ".launchd.conf" #define SECURITY_LIB "/System/Library/Frameworks/Security.framework/Versions/A/Security" +#define SHUTDOWN_LOG_DIR "/var/log/shutdown" + extern char **environ; static void signal_callback(void *, struct kevent *); -static void debugshutdown_callback(void); static void pfsystem_callback(void *, struct kevent *); static kq_callback kqsignal_callback = signal_callback; -static kq_callback kqdebugshutdown_callback = (kq_callback)debugshutdown_callback; static kq_callback kqpfsystem_callback = pfsystem_callback; static void pid1_magic_init(bool sflag); @@ -99,6 +99,7 @@ static void monitor_networking_state(void); static void fatal_signal_handler(int sig, siginfo_t *si, void *uap); static void handle_pid1_crashes_separately(void); +static void prep_shutdown_log_dir(void); static bool re_exec_in_single_user_mode = false; static job_t rlcj = NULL; @@ -392,6 +393,51 @@ } void +prep_shutdown_log_dir(void) +{ + struct stat sb; + struct dirent *de; + DIR *thedir = NULL; + + if (!launchd_assumes(mkdir(SHUTDOWN_LOG_DIR, S_IRWXU) != -1 || errno == EEXIST)) { + goto out; + } + + if (!launchd_assumes(lstat(SHUTDOWN_LOG_DIR, &sb) != -1)) { + goto out; + } + + if (!launchd_assumes(S_ISDIR(sb.st_mode))) { + goto out; + } + + if (!launchd_assumes(chdir(SHUTDOWN_LOG_DIR) != -1)) { + goto out; + } + + if (!launchd_assumes((thedir = opendir(".")) != NULL)) { + goto out; + } + + while ((de = readdir(thedir))) { + if (strcmp(de->d_name, ".") == 0) { + continue; + } else if (strcmp(de->d_name, "..") == 0) { + continue; + } else { + launchd_assumes(remove(de->d_name) != -1); + } + } + +out: + if (thedir) { + closedir(thedir); + } + + chdir("/"); +} + +void launchd_shutdown(void) { struct stat sb; @@ -402,17 +448,13 @@ shutdown_in_progress = true; - if (getpid() == 1) { - if (stat("/var/db/debugShutdownHangs", &sb) != -1) { - /* - * When this changes to a more sustainable API, update this: - * http://howto.apple.com/db.cgi?Debugging_Apps_Non-Responsive_At_Shutdown - */ - debug_shutdown_hangs = true; - } - - launchd_assumes(kevent_mod((uintptr_t)debugshutdown_callback, - EVFILT_TIMER, EV_ADD|EV_ONESHOT, NOTE_SECONDS, 5, &kqdebugshutdown_callback) != -1); + if (getpid() == 1 && stat("/var/db/debugShutdownHangs", &sb) != -1) { + /* + * When this changes to a more sustainable API, update this: + * http://howto.apple.com/db.cgi?Debugging_Apps_Non-Responsive_At_Shutdown + */ + prep_shutdown_log_dir(); + debug_shutdown_hangs = true; } rlcj = NULL; @@ -643,17 +685,3 @@ init_pre_kevent(); } } - -void -debugshutdown_callback(void) -{ - char *sdd_args[] = { "/usr/libexec/shutdown_debugger", NULL }; - pid_t sddp; - - if (launchd_assumes(posix_spawn(&sddp, sdd_args[0], NULL, NULL, sdd_args, environ) == 0)) { - int wstatus; - - /* No bootstrap port was given. It is safe to block. */ - launchd_assumes(waitpid(sddp, &wstatus, 0) != -1); - } -} Deleted: trunk/launchd/src/shutdown_debugger.8 =================================================================== --- trunk/launchd/src/shutdown_debugger.8 2007-02-16 02:51:55 UTC (rev 23075) +++ trunk/launchd/src/shutdown_debugger.8 2007-02-16 03:17:34 UTC (rev 23076) @@ -1,10 +0,0 @@ -.Dd December 14, 2006 -.Dt shutdown_debugger 8 -.Os Darwin -.Sh NAME -.Nm shutdown_debugger -.Nd tool to aid debugging shutdowns -.Sh SYNOPSIS -.Nm -.Sh DESCRIPTION -This tool is invoked a few seconds after a shutdown or reboot request to figure out why the machine isn't off yet. Useful debug files are placed in /var/log/shutdown. Deleted: trunk/launchd/src/shutdown_debugger.c =================================================================== --- trunk/launchd/src/shutdown_debugger.c 2007-02-16 02:51:55 UTC (rev 23075) +++ trunk/launchd/src/shutdown_debugger.c 2007-02-16 03:17:34 UTC (rev 23076) @@ -1,537 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern char **environ; - -struct hproc { - TAILQ_ENTRY(hproc) tqe; - pid_t stuck_p; - pid_t sample_p; -}; - -static void hproc_new(pid_t p, const char *pname); - -static TAILQ_HEAD(hproc_head, hproc) hprocs = TAILQ_HEAD_INITIALIZER(hprocs); - -static void populate_proc_list(void); -static void debug_machports(pid_t pid, const char *pname); -static void debug_machports2(pid_t pid, FILE *where); -static void do_stackshot(void); - -static int kq; - -#define SHUTDOWN_LOG_DIR "/var/log/shutdown" - -int -main(void) -{ - struct kevent kev; - struct stat sb; - struct hproc *hp; - struct dirent *de; - DIR *thedir; - int wstatus; - - mkdir(SHUTDOWN_LOG_DIR, S_IRWXU); - - assert(lstat(SHUTDOWN_LOG_DIR, &sb) != -1); - - assert(S_ISDIR(sb.st_mode)); - - assert(chdir(SHUTDOWN_LOG_DIR) != -1); - - assert((thedir = opendir(".")) != NULL); - - while ((de = readdir(thedir))) { - if (strcmp(de->d_name, ".") == 0) { - continue; - } else if (strcmp(de->d_name, "..") == 0) { - continue; - } else { - remove(de->d_name); - } - } - - closedir(thedir); - - do_stackshot(); - - assert((kq = kqueue()) != -1); - - debug_machports(1, "launchd"); - - populate_proc_list(); - - while (!TAILQ_EMPTY(&hprocs)) { - assert(kevent(kq, NULL, 0, &kev, 1, NULL) != -1); - - hp = kev.udata; - - assert(waitpid(hp->sample_p, &wstatus, 0) != -1); - - TAILQ_REMOVE(&hprocs, hp, tqe); - } - - exit(EXIT_SUCCESS); -} - -void -populate_proc_list(void) -{ - int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL }; - struct kinfo_proc *kp = NULL; - size_t i, len = 0; - - assert(sysctl(mib, 3, kp, &len, NULL, 0) != -1); - - assert((kp = malloc(len * 2)) != NULL); - - assert(sysctl(mib, 3, kp, &len, NULL, 0) != -1); - - for (i = 0; i < (len / sizeof(struct kinfo_proc)); i++) { - pid_t p_iter = kp[i].kp_proc.p_pid; - - if (p_iter == 0 || p_iter == 1 || p_iter == getpid()) { - continue; - } - - hproc_new(p_iter, kp[i].kp_proc.p_comm); - } - - free(kp); -} - -void -hproc_new(pid_t p, const char *pname) -{ - char pidstr[100], logfile[PATH_MAX]; - char *sample_args[] = { "sample", pidstr, "1", "-mayDie", "-file", logfile, NULL }; - posix_spawnattr_t spattr; - struct kevent kev; - struct hproc *hp; - pid_t sp; - - debug_machports(p, pname); - - assert((hp = calloc(1, sizeof(struct hproc))) != NULL); - - assert(posix_spawnattr_init(&spattr) == 0); - - assert(posix_spawnattr_setflags(&spattr, POSIX_SPAWN_START_SUSPENDED) == 0); - - snprintf(pidstr, sizeof(pidstr), "%u", p); - snprintf(logfile, sizeof(logfile), "%s-%u.sample.txt", pname, p); - - assert(posix_spawnp(&sp, sample_args[0], NULL, &spattr, sample_args, environ) == 0); - - assert(posix_spawnattr_destroy(&spattr) == 0); - - EV_SET(&kev, sp, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, hp); - - assert(kevent(kq, &kev, 1, NULL, 0, NULL) != -1); - - assert(kill(sp, SIGCONT) != -1); - - hp->stuck_p = p; - hp->sample_p = sp; - - TAILQ_INSERT_TAIL(&hprocs, hp, tqe); -} - -void -debug_machports(pid_t pid, const char *pname) -{ - char logfilepath[PATH_MAX]; - FILE *mplogfile; - - snprintf(logfilepath, sizeof(logfilepath), "%s-%u.machports.txt", pname, pid); - - assert((mplogfile = fopen(logfilepath, "a")) != NULL); - - debug_machports2(pid, mplogfile); - - fclose(mplogfile); -} - - -/* - * WARNING - these types are copied from xnu/osfmk/kern/ipc_kobject.h - * Need to stay in sync to print accurate results. - */ -#define IKOT_NONE 0 -#define IKOT_THREAD 1 -#define IKOT_TASK 2 -#define IKOT_HOST 3 -#define IKOT_HOST_PRIV 4 -#define IKOT_PROCESSOR 5 -#define IKOT_PSET 6 -#define IKOT_PSET_NAME 7 -#define IKOT_TIMER 8 -#define IKOT_PAGING_REQUEST 9 -#define IKOT_MIG 10 -#define IKOT_MEMORY_OBJECT 11 -#define IKOT_XMM_PAGER 12 -#define IKOT_XMM_KERNEL 13 -#define IKOT_XMM_REPLY 14 -#define IKOT_UND_REPLY 15 -#define IKOT_HOST_NOTIFY 16 -#define IKOT_HOST_SECURITY 17 -#define IKOT_LEDGER 18 -#define IKOT_MASTER_DEVICE 19 -#define IKOT_TASK_NAME 20 -#define IKOT_SUBSYSTEM 21 -#define IKOT_IO_DONE_QUEUE 22 -#define IKOT_SEMAPHORE 23 -#define IKOT_LOCK_SET 24 -#define IKOT_CLOCK 25 -#define IKOT_CLOCK_CTRL 26 -#define IKOT_IOKIT_SPARE 27 -#define IKOT_NAMED_ENTRY 28 -#define IKOT_IOKIT_CONNECT 29 -#define IKOT_IOKIT_OBJECT 30 -#define IKOT_UPL 31 - -static const char * -kobject_name(natural_t kotype) -{ - switch (kotype) { - case IKOT_NONE: return "message-queue"; - case IKOT_THREAD: return "kobject(THREAD)"; - case IKOT_TASK: return "kobject(TASK)"; - case IKOT_HOST: return "kobject(HOST)"; - case IKOT_HOST_PRIV: return "kobject(HOST-PRIV)"; - case IKOT_PROCESSOR: return "kobject(PROCESSOR)"; - case IKOT_PSET: return "kobject(PROCESSOR-SET)"; - case IKOT_PSET_NAME: return "kobject(PROCESSOR-SET-NAME)"; - case IKOT_TIMER: return "kobject(TIMER)"; - case IKOT_PAGING_REQUEST: return "kobject(PAGER-REQUEST)"; - case IKOT_MIG: return "kobject(MIG)"; - case IKOT_MEMORY_OBJECT: return "kobject(MEMORY-OBJECT)"; - case IKOT_XMM_PAGER: return "kobject(XMM-PAGER)"; - case IKOT_XMM_KERNEL: return "kobject(XMM-KERNEL)"; - case IKOT_XMM_REPLY: return "kobject(XMM-REPLY)"; - case IKOT_UND_REPLY: return "kobject(UND-REPLY)"; - case IKOT_HOST_NOTIFY: return "message-queue"; - case IKOT_HOST_SECURITY: return "kobject(HOST-SECURITY)"; - case IKOT_LEDGER: return "kobject(LEDGER)"; - case IKOT_MASTER_DEVICE: return "kobject(MASTER-DEVICE)"; - case IKOT_TASK_NAME: return "kobject(TASK-NAME)"; - case IKOT_SUBSYSTEM: return "kobject(SUBSYSTEM)"; - case IKOT_IO_DONE_QUEUE: return "kobject(IO-QUEUE-DONE)"; - case IKOT_SEMAPHORE: return "kobject(SEMAPHORE)"; - case IKOT_LOCK_SET: return "kobject(LOCK-SET)"; - case IKOT_CLOCK: return "kobject(CLOCK)"; - case IKOT_CLOCK_CTRL: return "kobject(CLOCK-CONTROL)"; - case IKOT_IOKIT_SPARE: return "kobject(IOKIT-SPARE)"; - case IKOT_NAMED_ENTRY: return "kobject(NAMED-MEMORY)"; - case IKOT_IOKIT_CONNECT: return "kobject(IOKIT-CONNECT)"; - case IKOT_IOKIT_OBJECT: return "kobject(IOKIT-OBJECT)"; - case IKOT_UPL: return "kobject(UPL)"; - default: return "kobject(UNKNOWN)"; - } -} - -/* private structure to wrap up per-task info */ -typedef struct my_per_task_info { - task_t task; - pid_t pid; - ipc_info_space_t info; - ipc_info_name_array_t table; - mach_msg_type_number_t tableCount; - ipc_info_tree_name_array_t tree; - mach_msg_type_number_t treeCount; -} my_per_task_info_t; - -void -debug_machports2(pid_t pid, FILE *where) -{ - kern_return_t ret; - my_per_task_info_t aTask; - my_per_task_info_t *taskinfo = NULL; - my_per_task_info_t *psettaskinfo; - mach_msg_type_number_t i, j, k, taskCount; - int emptycount = 0, portsetcount = 0, sendcount = 0, receivecount = 0, sendoncecount = 0, deadcount = 0, dncount = 0; - - /* if priviledged, get the info for all tasks so we can match ports up */ - if (geteuid() == 0) { - processor_set_name_array_t psets; - mach_msg_type_number_t psetCount; - mach_port_t pset_priv; - task_array_t tasks; - - ret = host_processor_sets(mach_host_self(), &psets, &psetCount); - if (ret != KERN_SUCCESS) { - fprintf(where, "host_processor_sets() failed: %s\n", mach_error_string(ret)); - return; - } - if (psetCount != 1) { - fprintf(where, "Assertion Failure: pset count greater than one (%d)\n", psetCount); - return; - } - - /* convert the processor-set-name port to a privileged port */ - ret = host_processor_set_priv(mach_host_self(), psets[0], &pset_priv); - if (ret != KERN_SUCCESS) { - fprintf(where, "host_processor_set_priv() failed: %s\n", mach_error_string(ret)); - return; - } - mach_port_deallocate(mach_task_self(), psets[0]); - vm_deallocate(mach_task_self(), (vm_address_t)psets, (vm_size_t)psetCount * sizeof(mach_port_t)); - - /* convert the processor-set-priv to a list of tasks for the processor set */ - ret = processor_set_tasks(pset_priv, &tasks, &taskCount); - if (ret != KERN_SUCCESS) { - fprintf(where, "processor_set_tasks() failed: %s\n", mach_error_string(ret)); - return; - } - mach_port_deallocate(mach_task_self(), pset_priv); - - /* convert each task to structure of pointer for the task info */ - psettaskinfo = (my_per_task_info_t *)malloc(taskCount * sizeof(my_per_task_info_t)); - for (i = 0; i < taskCount; i++) { - psettaskinfo[i].task = tasks[i]; - pid_for_task(tasks[i], &psettaskinfo[i].pid); - ret = mach_port_space_info(tasks[i], &psettaskinfo[i].info, - &psettaskinfo[i].table, &psettaskinfo[i].tableCount, - &psettaskinfo[i].tree, &psettaskinfo[i].treeCount); - if (ret != KERN_SUCCESS) { - fprintf(where, "mach_port_space_info() failed: %s\n", mach_error_string(ret)); - return; - } - if (psettaskinfo[i].pid == pid) - taskinfo = &psettaskinfo[i]; - } - vm_deallocate(mach_task_self(), (vm_address_t)tasks, (vm_size_t)taskCount * sizeof(mach_port_t)); - } - else - { - /* just the one process */ - ret = task_for_pid((mach_task_self)(), pid, &aTask.task); - if (ret != KERN_SUCCESS) { - fprintf(where, "task_for_pid() failed: %s\n", mach_error_string(ret)); - return; - } - ret = mach_port_space_info(aTask.task, &aTask.info, - &aTask.table, &aTask.tableCount, - &aTask.tree, &aTask.treeCount); - if (ret != KERN_SUCCESS) { - fprintf(where, "mach_port_space_info() failed: %s\n", mach_error_string(ret)); - return; - } - taskinfo = &aTask; - psettaskinfo = taskinfo; - taskCount = 1; - } - - fprintf(where, "set-name ipc-object rights "); - fprintf(where, " member-cnt\n"); - fprintf(where, "recv-name ipc-object rights "); - fprintf(where, "reqs urefs orefs qlimit msgcount\n"); - fprintf(where, "send-name ipc-object rights "); - fprintf(where, "reqs urefs orefs kern-object type\n"); - fprintf(where, "--------where, - ---------- ---------- "); - fprintf(where, "---where, - ----- ----- ----------- ------------\n"); - - for (i = 0; i < taskinfo->tableCount; i++) { - boolean_t found = FALSE; - boolean_t sendr = FALSE; - boolean_t sendonce = FALSE; - boolean_t dnreq = FALSE; - int sendrights = 0; - unsigned int kotype = 0; - vm_offset_t kobject = (vm_offset_t)0; - - /* skip empty slots in the table */ - if (taskinfo->table[i].iin_object == 0) { - emptycount++; - continue; - } - - if (taskinfo->table[i].iin_type == MACH_PORT_TYPE_PORT_SET) { - mach_port_name_array_t members; - mach_msg_type_number_t membersCnt; - - ret = mach_port_get_set_status(taskinfo->task, - taskinfo->table[i].iin_name, - &members, &membersCnt); - if (ret != KERN_SUCCESS) { - fprintf(where, "mach_port_get_set_status(0x%08x) failed: %s\n", - taskinfo->table[i].iin_name, - mach_error_string(ret)); - continue; - } - fprintf(where, "0x%08x 0x%08x port-set --- 1 %5d members\n", - taskinfo->table[i].iin_name, - taskinfo->table[i].iin_object, - membersCnt); - /* get some info for each portset member */ - for (j = 0; j < membersCnt; j++) { - for (k = 0; k < taskinfo->tableCount; k++) { - if (taskinfo->table[k].iin_name == members[j]) { - fprintf(where, " 0x%08x %s --- 0x%08x process(%d)\n", - taskinfo->table[k].iin_object, - (taskinfo->table[k].iin_type & MACH_PORT_TYPE_SEND) ? "recv,send ":"recv ", - taskinfo->table[k].iin_name, - pid); - break; - } - } - } - - ret = vm_deallocate(mach_task_self(), (vm_address_t)members, - membersCnt * sizeof(mach_port_name_t)); - if (ret != KERN_SUCCESS) { - fprintf(where, "vm_deallocate() failed: %s\n", - mach_error_string(ret)); - return; - } - portsetcount++; - continue; - } - - if (taskinfo->table[i].iin_type & MACH_PORT_TYPE_SEND) { - sendr = TRUE; - sendrights = taskinfo->table[i].iin_urefs; - sendcount++; - } - - if (taskinfo->table[i].iin_type & MACH_PORT_TYPE_SEND_ONCE) { - sendonce = TRUE; - sendoncecount++; - } - - if (taskinfo->table[i].iin_type & MACH_PORT_TYPE_DNREQUEST) { - dnreq = TRUE; - dncount++; - } - - if (taskinfo->table[i].iin_type & MACH_PORT_TYPE_RECEIVE) { - mach_port_status_t status; - mach_msg_type_number_t statusCnt; - - statusCnt = MACH_PORT_RECEIVE_STATUS_COUNT; - ret = mach_port_get_attributes(taskinfo->task, - taskinfo->table[i].iin_name, - MACH_PORT_RECEIVE_STATUS, - (mach_port_info_t)&status, - &statusCnt); - if (ret != KERN_SUCCESS) { - fprintf(where, "mach_port_get_attributes(0x%08x) failed: %s\n", - taskinfo->table[i].iin_name, - mach_error_string(ret)); - continue; - } - - fprintf(where, "0x%08x 0x%08x %s %s%s%s %5d %s(%02d) 0x%08x 0x%08x\n", - taskinfo->table[i].iin_name, - taskinfo->table[i].iin_object, - (sendr) ? "recv,send ":"recv ", - (dnreq) ? "D":"-", - (status.mps_nsrequest) ? "N":"-", - (status.mps_pdrequest) ? "P":"-", - sendrights + 1, - (status.mps_srights) ? "Y":"N", - status.mps_sorights, - status.mps_qlimit, - status.mps_msgcount); - receivecount++; - - /* show other rights (in this and other tasks) for the port */ - for (j = 0; j < taskCount; j++) { - for (k = 0; k < psettaskinfo->tableCount; k++) { - if (&psettaskinfo[j].table[k] == &taskinfo->table[i] || - psettaskinfo[j].table[k].iin_object != taskinfo->table[i].iin_object) - continue; - fprintf(where, " 0x%08x %s --- %5d 0x%08x process(%d)\n", - psettaskinfo[j].table[k].iin_object, - (psettaskinfo[j].table[k].iin_type & MACH_PORT_TYPE_SEND_ONCE) ? - "send-once " : "send ", - psettaskinfo[j].table[k].iin_urefs, - psettaskinfo[j].table[k].iin_name, - psettaskinfo[j].pid); - } - } - continue; - } - else if (taskinfo->table[i].iin_type & MACH_PORT_TYPE_DEAD_NAME) - { - fprintf(where, "0x%08x 0x%08x dead-name --- %5d\n", - taskinfo->table[i].iin_name, - taskinfo->table[i].iin_object, - taskinfo->table[i].iin_urefs); - deadcount++; - continue; - } - - fprintf(where, "0x%08x 0x%08x %s %s%s%s %5d ", - taskinfo->table[i].iin_name, - taskinfo->table[i].iin_object, - (sendr) ? "send ":"send-once ", - (dnreq) ? "D":"-", - "-", - "-", - (sendr) ? sendrights : 1); - - /* converting to kobjects is not always supported */ - ret = mach_port_kernel_object(taskinfo->task, - taskinfo->table[i].iin_name, - &kotype, &kobject); - if (kotype != 0) { - fprintf(where, "0x%08x %s\n", kobject, kobject_name(kotype)); - continue; - } - - /* not kobject - find the receive right holder */ - for (j = 0; j < taskCount && !found; j++) { - for (k = 0; k < psettaskinfo[j].tableCount && !found; k++) { - if ((psettaskinfo[j].table[k].iin_type & MACH_PORT_TYPE_RECEIVE) && - psettaskinfo[j].table[k].iin_object == taskinfo->table[i].iin_object ) { - fprintf(where, "0x%08x process(%d)\n", - psettaskinfo[j].table[k].iin_name, - psettaskinfo[j].pid); - found = TRUE; - } - } - } - if (!found) - fprintf(where, "0x00000000 process(unknown)\n"); - } - fprintf(where, "total = %d\n", taskinfo->tableCount + taskinfo->treeCount - emptycount); - fprintf(where, "SEND = %d\n", sendcount); - fprintf(where, "RECEIVE = %d\n", receivecount); - fprintf(where, "SEND_ONCE = %d\n", sendoncecount); - fprintf(where, "PORT_SET = %d\n", portsetcount); - fprintf(where, "DEAD_NAME = %d\n", deadcount); - fprintf(where, "DNREQUEST = %d\n", dncount); - - if (taskCount > 1) - free(psettaskinfo); - - fprintf(where, "Finished.\n"); - return; -} - -void -do_stackshot(void) -{ - /* yes, we really mean to exec without fork at this point in time */ - execl("/usr/libexec/stackshot", "/usr/libexec/stackshot", "-i", "-f", "./shutdown-stackshot.log", NULL); - _exit(EXIT_FAILURE); -} -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070215/ca3ee40d/attachment.html From source_changes at macosforge.org Fri Feb 16 09:08:11 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23077] trunk/launchd/src Message-ID: <20070216170811.CE7404AB0C8@cvs.opensource.apple.com> Revision: 23077 http://trac.macosforge.org/projects/launchd/changeset/23077 Author: zarzycki@apple.com Date: 2007-02-16 09:08:11 -0800 (Fri, 16 Feb 2007) Log Message: ----------- Extra debug code for the kernel team. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/liblaunch_private.h Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-16 03:17:34 UTC (rev 23076) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-16 17:08:11 UTC (rev 23077) @@ -101,7 +101,7 @@ SLIST_ENTRY(machservice) sle; job_t job; mach_port_name_t port; - unsigned int isActive:1, reset:1, recv:1, hide:1, kUNCServer:1, must_match_uid:1; + unsigned int isActive:1, reset:1, recv:1, hide:1, kUNCServer:1, must_match_uid:1, debug_on_close:1; char name[0]; }; @@ -1676,7 +1676,7 @@ delta = (double)tvd.tv_sec + (double)tvd.tv_usec / (double)1000000; - job_log(j, tvd.tv_sec ? LOG_NOTICE : LOG_INFO, "Exited %f seconds after SIGTERM was sent", delta); + job_log(j, LOG_INFO, "Exited %f seconds after SIGTERM was sent", delta); } timeradd(&ru.ru_utime, &j->ru.ru_utime, &j->ru.ru_utime); @@ -2886,7 +2886,7 @@ job_log(j, LOG_DEBUG, "Exited while removal was pending."); return true; } else if (j->mgr->shutting_down) { - job_log(j, LOG_NOTICE, "Exited while shutdown in progress. Processes remaining: %u", total_children); + job_log(j, LOG_DEBUG, "Exited while shutdown in progress. Processes remaining: %u", total_children); return true; } else if (!j->checkedin && (!SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices))) { job_log(j, LOG_WARNING, "Failed to check-in!"); @@ -3196,7 +3196,9 @@ } case LAUNCH_DATA_BOOL: b = launch_data_get_bool(obj); - if (strcasecmp(key, LAUNCH_JOBKEY_MACH_RESETATCLOSE) == 0) { + if (strcasecmp(key, LAUNCH_JOBKEY_MACH_ENTERKERNELDEBUGGERONCLOSE) == 0) { + ms->debug_on_close = b; + } else if (strcasecmp(key, LAUNCH_JOBKEY_MACH_RESETATCLOSE) == 0) { ms->reset = b; } else if (strcasecmp(key, LAUNCH_JOBKEY_MACH_HIDEUNTILCHECKIN) == 0) { ms->hide = b; @@ -3569,6 +3571,11 @@ void machservice_delete(struct machservice *ms) { + if (ms->debug_on_close) { + job_log(ms->job, LOG_NOTICE, "About to enter kernel debugger because of Mach port: 0x%x", ms->port); + job_assumes(ms->job, host_reboot(mach_host_self(), HOST_REBOOT_DEBUGGER) == KERN_SUCCESS); + } + if (ms->recv && job_assumes(ms->job, !ms->isActive)) { job_assumes(ms->job, launchd_mport_close_recv(ms->port) == KERN_SUCCESS); } Modified: trunk/launchd/src/liblaunch_private.h =================================================================== --- trunk/launchd/src/liblaunch_private.h 2007-02-16 03:17:34 UTC (rev 23076) +++ trunk/launchd/src/liblaunch_private.h 2007-02-16 17:08:11 UTC (rev 23077) @@ -55,6 +55,7 @@ #define LAUNCH_JOBKEY_MACH_EXCEPTIONSERVER "ExceptionServer" #define LAUNCH_JOBKEY_MACH_TASKSPECIALPORT "TaskSpecialPort" #define LAUNCH_JOBKEY_MACH_HOSTSPECIALPORT "HostSpecialPort" +#define LAUNCH_JOBKEY_MACH_ENTERKERNELDEBUGGERONCLOSE "EnterKernelDebuggerOnClose" typedef struct _launch *launch_t; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070216/22738ada/attachment.html From source_changes at macosforge.org Fri Feb 16 09:21:59 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23078] trunk/launchd/src/StartupItems/Disks Message-ID: <20070216172159.759784AB1E8@cvs.opensource.apple.com> Revision: 23078 http://trac.macosforge.org/projects/launchd/changeset/23078 Author: zarzycki@apple.com Date: 2007-02-16 09:21:59 -0800 (Fri, 16 Feb 2007) Log Message: ----------- MacBuddy should 'vsdbutil -i' so we don't need a StartupItem for it Modified Paths: -------------- trunk/launchd/src/StartupItems/Disks Modified: trunk/launchd/src/StartupItems/Disks =================================================================== --- trunk/launchd/src/StartupItems/Disks 2007-02-16 17:08:11 UTC (rev 23077) +++ trunk/launchd/src/StartupItems/Disks 2007-02-16 17:21:59 UTC (rev 23078) @@ -8,16 +8,8 @@ StartService () { - if [ ! -f /var/db/volinfo.database ]; then Uninitialized_VSDB=-YES-; fi - echo "Checking disks" /sbin/autodiskmount -va - - if [ "${Uninitialized_VSDB:=-NO-}" = "-YES-" ]; then - if [ -x /usr/sbin/vsdbutil ]; then - /usr/sbin/vsdbutil -i - fi - fi } StopService () -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070216/d082faa1/attachment.html From source_changes at macosforge.org Fri Feb 16 09:45:28 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23079] trunk/launchd/src Message-ID: <20070216174528.BF3AA4AB41B@cvs.opensource.apple.com> Revision: 23079 http://trac.macosforge.org/projects/launchd/changeset/23079 Author: zarzycki@apple.com Date: 2007-02-16 09:45:28 -0800 (Fri, 16 Feb 2007) Log Message: ----------- The last StartupItem installed by launchd is now dead. :-) Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/StartupItems.c trunk/launchd/src/SystemStarter.c Removed Paths: ------------- trunk/launchd/src/StartupItems/ Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-02-16 17:21:59 UTC (rev 23078) +++ trunk/launchd/src/Makefile.am 2007-02-16 17:45:28 UTC (rev 23079) @@ -68,17 +68,7 @@ man8_MANS = StartupItemContext.8 SystemStarter.8 rc.8 launchd.8 service.8 launchproxy.8 -STARTUPITEMS = $(basename $(notdir $(wildcard $(srcdir)/StartupItems/*.plist))) - -$(addprefix $(DESTDIR)/System/Library/StartupItems/, $(STARTUPITEMS)): - mkdir -p $@ - cp $(srcdir)/StartupItems/$(notdir $@) $@ - chmod 755 $@/$(notdir $@) - cp $(srcdir)/StartupItems/$(notdir $@).plist $@/StartupParameters.plist - -install-startupitems: $(addprefix $(DESTDIR)/System/Library/StartupItems/, $(STARTUPITEMS)) - -install-data-hook: install-startupitems +install-data-hook: mkdir -p $(DESTDIR)/usr/libexec cp $(srcdir)/StartupItemContext $(DESTDIR)/usr/libexec mkdir -p $(DESTDIR)/usr/include/servers Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-02-16 17:21:59 UTC (rev 23078) +++ trunk/launchd/src/Makefile.in 2007-02-16 17:45:28 UTC (rev 23079) @@ -249,7 +249,6 @@ @LIBS_ONLY_FALSE@man1_MANS = wait4path.1 launchctl.1 @LIBS_ONLY_FALSE@man5_MANS = launchd.plist.5 launchd.conf.5 @LIBS_ONLY_FALSE@man8_MANS = StartupItemContext.8 SystemStarter.8 rc.8 launchd.8 service.8 launchproxy.8 -@LIBS_ONLY_FALSE@STARTUPITEMS = $(basename $(notdir $(wildcard $(srcdir)/StartupItems/*.plist))) all: config.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -1075,15 +1074,7 @@ @LIBS_ONLY_FALSE@launchd_internal.h launchd_internalServer.c launchd_internalUser.c launchd_internalServer.h: $(srcdir)/launchd_internal.defs @LIBS_ONLY_FALSE@ mig $(MIGFLAGS) -sheader launchd_internalServer.h $(srcdir)/launchd_internal.defs -@LIBS_ONLY_FALSE@$(addprefix $(DESTDIR)/System/Library/StartupItems/, $(STARTUPITEMS)): -@LIBS_ONLY_FALSE@ mkdir -p $@ -@LIBS_ONLY_FALSE@ cp $(srcdir)/StartupItems/$(notdir $@) $@ -@LIBS_ONLY_FALSE@ chmod 755 $@/$(notdir $@) -@LIBS_ONLY_FALSE@ cp $(srcdir)/StartupItems/$(notdir $@).plist $@/StartupParameters.plist - -@LIBS_ONLY_FALSE@install-startupitems: $(addprefix $(DESTDIR)/System/Library/StartupItems/, $(STARTUPITEMS)) - -@LIBS_ONLY_FALSE@install-data-hook: install-startupitems +@LIBS_ONLY_FALSE@install-data-hook: @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/usr/libexec @LIBS_ONLY_FALSE@ cp $(srcdir)/StartupItemContext $(DESTDIR)/usr/libexec @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/usr/include/servers Modified: trunk/launchd/src/StartupItems.c =================================================================== --- trunk/launchd/src/StartupItems.c 2007-02-16 17:21:59 UTC (rev 23078) +++ trunk/launchd/src/StartupItems.c 2007-02-16 17:45:28 UTC (rev 23079) @@ -158,6 +158,7 @@ CFSTR("Core Services"), CFSTR("Network"), CFSTR("TIM"), + CFSTR("Disks"), NULL }; CFMutableArrayRef aList, aNewList; @@ -959,7 +960,6 @@ case 0: /* Child */ { - setpriority(PRIO_PROCESS, 0, 0); if (setsid() == -1) syslog(LOG_WARNING, "Unable to create session for item %s: %m", anExecutable); Modified: trunk/launchd/src/SystemStarter.c =================================================================== --- trunk/launchd/src/SystemStarter.c 2007-02-16 17:21:59 UTC (rev 23078) +++ trunk/launchd/src/SystemStarter.c 2007-02-16 17:45:28 UTC (rev 23079) @@ -44,6 +44,7 @@ static int system_starter(Action anAction, const char *aService); static void displayErrorMessages(StartupContext aStartupContext); static void doCFnote(void); +static pid_t fwexec(const char *const *argv, bool _wait); int main(int argc, char *argv[]) @@ -112,11 +113,9 @@ if (argc == 2) { aService = argv[1]; } else if (!gDebugFlag && anAction != kActionStop) { - pid_t ipwa; - int status; + const char *ipw_cmd[] = { "/usr/sbin/ipconfig", "waitall", NULL }; + const char *adm_cmd[] = { "/sbin/autodiskmount", "-va", NULL }; - setpriority(PRIO_PROCESS, 0, 20); - /* Too many old StartupItems had implicit dependancies on * "Network" via other StartupItems that are now no-ops. * @@ -124,30 +123,8 @@ * so we'll stall here to deal with this legacy dependancy * problem. */ - switch ((ipwa = fork())) { - case -1: - syslog(LOG_WARNING, "fork(): %m"); - break; - case 0: - execl("/usr/sbin/ipconfig", "ipconfig", "waitall", NULL); - syslog(LOG_WARNING, "execl(): %m"); - exit(EXIT_FAILURE); - default: - if (waitpid(ipwa, &status, 0) == -1) { - syslog(LOG_WARNING, "waitpid(): %m"); - break; - } else if (WIFEXITED(status)) { - if (WEXITSTATUS(status) == 0) { - break; - } else { - syslog(LOG_WARNING, "ipconfig waitall exit status: %d", WEXITSTATUS(status)); - } - } else { - /* must have died due to signal */ - syslog(LOG_WARNING, "ipconfig waitall: %s", strsignal(WTERMSIG(status))); - } - break; - } + fwexec(ipw_cmd, true); + fwexec(adm_cmd, true); } int ssec = system_starter(anAction, aService); @@ -406,3 +383,38 @@ NULL, NULL, kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); } + +pid_t +fwexec(const char *const *argv, bool _wait) +{ + int wstatus; + pid_t p; + + switch ((p = fork())) { + case -1: + return -1; + case 0: + setsid(); + execvp(argv[0], (char *const *)argv); + _exit(EXIT_FAILURE); + break; + default: + if (!_wait) + return p; + if (waitpid(p, &wstatus, 0) == -1) { + return -1; + } else if (WIFEXITED(wstatus)) { + if (WEXITSTATUS(wstatus) == 0) { + return 0; + } else { + syslog(LOG_WARNING, "%s exit status: %d", argv[0], WEXITSTATUS(wstatus)); + } + } else { + /* must have died due to signal */ + syslog(LOG_WARNING, "%s died: %s", argv[0], strsignal(WTERMSIG(wstatus))); + } + break; + } + + return -1; +} -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070216/cad69ce2/attachment.html From source_changes at macosforge.org Fri Feb 16 10:12:03 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23080] trunk/launchd/src/launchctl.c Message-ID: <20070216181203.D8D644AB61D@cvs.opensource.apple.com> Revision: 23080 http://trac.macosforge.org/projects/launchd/changeset/23080 Author: zarzycki@apple.com Date: 2007-02-16 10:12:03 -0800 (Fri, 16 Feb 2007) Log Message: ----------- Small boot time optimization. Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-02-16 17:45:28 UTC (rev 23079) +++ trunk/launchd/src/launchctl.c 2007-02-16 18:12:03 UTC (rev 23080) @@ -2455,16 +2455,20 @@ const char *remount_tool[] = { "mount", "-uw", "/", NULL }; struct statfs sfs; - if (assumes(statfs("/", &sfs) != -1)) { - if (!(sfs.f_flags & MNT_RDONLY)) { - fprintf(stdout, "Root file system is read-write, skipping fsck.\n"); - return; - } + if (!assumes(statfs("/", &sfs) != -1)) { + return; } + if (!(sfs.f_flags & MNT_RDONLY)) { + return; + } + if (!is_safeboot()) { - if (fwexec(fsck_tool, true) != -1) + if (sfs.f_flags & MNT_JOURNALED) { goto out; + } else if (fwexec(fsck_tool, true) != -1) { + goto out; + } } if (fwexec(safe_fsck_tool, true) != -1) { @@ -2475,6 +2479,16 @@ return; out: + /* + * Once this is fixed: + * + * Mount flag updates should be possible with NULL as the forth argument to mount() + * + * We can then do this one system call instead of calling out a full blown process. + * + * assumes(mount(sfs.f_fstypename, "/", MNT_UPDATE, NULL) != -1); + */ + assumes(fwexec(remount_tool, true) != -1); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070216/8ba8ba92/attachment.html From source_changes at macosforge.org Sun Feb 18 10:48:20 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23081] trunk/launchd/src Message-ID: <20070218184820.896544AE7F6@cvs.opensource.apple.com> Revision: 23081 http://trac.macosforge.org/projects/launchd/changeset/23081 Author: zarzycki@apple.com Date: 2007-02-18 10:48:19 -0800 (Sun, 18 Feb 2007) Log Message: ----------- Miscellaneous. 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-02-16 18:12:03 UTC (rev 23080) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-18 18:48:19 UTC (rev 23081) @@ -92,6 +92,7 @@ #define LAUNCHD_MIN_JOB_RUN_TIME 10 #define LAUNCHD_ADVISABLE_IDLE_TIMEOUT 30 #define LAUNCHD_DEFAULT_EXIT_TIMEOUT 20 +#define LAUNCHD_SIGKILL_TIMEOUT 5 extern char **environ; @@ -276,7 +277,7 @@ 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, setnice:1, hopefully_exits_last:1, removal_pending:1, - wait4pipe_eof:1; + wait4pipe_eof:1, sent_sigkill:1; char label[0]; }; @@ -1709,7 +1710,12 @@ } } + if (!j->checkedin && (!SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices))) { + job_log(j, LOG_WARNING, "Failed to check-in!"); + } + j->last_exit_status = status; + j->sent_sigkill = false; j->p = 0; } @@ -1743,12 +1749,8 @@ if (job_useless(j)) { job_remove(j); return NULL; - } else if (kickstart) { - job_log(j, LOG_DEBUG, "Kick-starting."); + } else if (kickstart || job_keepalive(j)) { job_start(j); - } else if (job_keepalive(j)) { - job_log(j, LOG_DEBUG, "Keeping alive..."); - job_start(j); } else { job_watch(j); } @@ -1795,6 +1797,11 @@ job_kill(job_t j) { job_assumes(j, kill(j->p, SIGKILL) != -1); + + j->sent_sigkill = true; + + job_assumes(j, kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, + EV_ADD|EV_ONESHOT, NOTE_SECONDS, LAUNCHD_SIGKILL_TIMEOUT, j) != -1); } void @@ -1824,9 +1831,16 @@ if (j == ident || &j->start_interval == ident) { job_dispatch(j, true); } else if (&j->exit_timeout == ident) { - job_force_sampletool(j); - job_log(j, LOG_WARNING, "Exit timeout elapsed (%u seconds). Killing.", j->exit_timeout); - job_kill(j); + if (j->sent_sigkill) { + job_log(j, LOG_ERR, "Did not die after sending SIGKILL %u seconds ago...", LAUNCHD_SIGKILL_TIMEOUT); + if (debug_shutdown_hangs) { + job_assumes(j, host_reboot(mach_host_self(), HOST_REBOOT_DEBUGGER) == KERN_SUCCESS); + } + } else { + job_force_sampletool(j); + job_log(j, LOG_WARNING, "Exit timeout elapsed (%u seconds). Killing.", j->exit_timeout); + job_kill(j); + } } else { calendarinterval_callback(j, ident); } @@ -2888,12 +2902,14 @@ } else if (j->mgr->shutting_down) { job_log(j, LOG_DEBUG, "Exited while shutdown in progress. Processes remaining: %u", total_children); return true; - } else if (!j->checkedin && (!SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices))) { - job_log(j, LOG_WARNING, "Failed to check-in!"); - return true; - } else if (j->legacy_mach_job && SLIST_EMPTY(&j->machservices)) { - job_log(j, LOG_INFO, "Garbage collecting"); - return true; + } else if (j->legacy_mach_job) { + if (SLIST_EMPTY(&j->machservices)) { + job_log(j, LOG_INFO, "Garbage collecting"); + return true; + } else if (!j->checkedin) { + job_log(j, LOG_WARNING, "Failed to check-in!"); + return true; + } } return false; @@ -2946,8 +2962,7 @@ wanted_state = true; case NETWORK_DOWN: if (network_up == wanted_state) { - job_log(j, LOG_DEBUG, "KeepAlive check: job configured to run while the network is %s.", - wanted_state ? "up" : "down"); + job_log(j, LOG_DEBUG, "KeepAlive: The network is %s.", wanted_state ? "up" : "down"); return true; } break; @@ -2955,8 +2970,7 @@ wanted_state = true; case FAILED_EXIT: if (good_exit == wanted_state) { - job_log(j, LOG_DEBUG, "KeepAlive check: job configured to run while the exit state was %s.", - wanted_state ? "successful" : "failure"); + job_log(j, LOG_DEBUG, "KeepAlive: The exit state was %s.", wanted_state ? "successful" : "failure"); return true; } break; @@ -2964,12 +2978,11 @@ wanted_state = true; case PATH_MISSING: 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; } + job_log(j, LOG_DEBUG, "KeepAlive: The following path %s: %s", wanted_state ? "exists" : "is missing", si->what); return true; } break; @@ -2979,6 +2992,7 @@ 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) { + job_log(j, LOG_DEBUG, "KeepAlive: Directory is not empty: %s", si->what); return true; } break; Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-16 18:12:03 UTC (rev 23080) +++ trunk/launchd/src/launchd_runtime.c 2007-02-18 18:48:19 UTC (rev 23081) @@ -343,12 +343,16 @@ } if (status.mps_msgcount) { EV_SET(&kev, members[i], EVFILT_MACHPORT, 0, 0, 0, jobmgr_find_by_service_port(root_jobmgr, members[i])); +#if 0 if (launchd_assumes(kev.udata != NULL)) { +#endif log_kevent_struct(LOG_DEBUG, &kev); (*((kq_callback *)kev.udata))(kev.udata, &kev); +#if 0 } else { log_kevent_struct(LOG_ERR, &kev); } +#endif /* the callback may have tainted our ability to continue this for loop */ break; } @@ -381,18 +385,23 @@ { struct timespec ts = { 0, 0 }; struct kevent kev; - Dl_info dli; int kevr; launchd_assumes((kevr = kevent(fd, NULL, 0, &kev, 1, &ts)) != -1); if (kevr == 1) { +#if 0 + Dl_info dli; + if (launchd_assumes(malloc_size(kev.udata) || dladdr(kev.udata, &dli))) { +#endif log_kevent_struct(LOG_DEBUG, &kev); (*((kq_callback *)kev.udata))(kev.udata, &kev); +#if 0 } else { log_kevent_struct(LOG_ERR, &kev); } +#endif } launchd_post_kevent(); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070218/a1992788/attachment.html From source_changes at macosforge.org Sun Feb 18 18:03:20 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23082] trunk/launchd/src Message-ID: <20070219020320.0DA344AECB4@cvs.opensource.apple.com> Revision: 23082 http://trac.macosforge.org/projects/launchd/changeset/23082 Author: zarzycki@apple.com Date: 2007-02-18 18:03:20 -0800 (Sun, 18 Feb 2007) Log Message: ----------- Major changes: 1) init.c is 100% dead. 2) single-user-mode is now a feature of launchctl. 3) The 'jobmgr' concept is better able to self-bootstrap now. 4) Some per process kevents have been moved to the root jobmgr. 5) The user's "background" session is now being bootstrapped. 6) Deleted dead code: launchctl stdout/stderr sub commands. 7) Miscellaneous. Work to be done: 1) Restore launchd.conf functionality. 2) Make jobmgr self-bootstrap atomic WRT bootstrap_look_up(). 3) Self-bootstrap sub jobmgr objects. Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/launchctl.1 trunk/launchd/src/launchctl.c trunk/launchd/src/launchd.c trunk/launchd/src/launchd.h trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_core_logic.h trunk/launchd/src/launchd_runtime.c trunk/launchd/src/launchd_runtime.h trunk/launchd/src/launchd_unix_ipc.c trunk/launchd/src/launchd_unix_ipc.h trunk/launchd/src/liblaunch_private.h trunk/launchd/src/libvproc_public.h Removed Paths: ------------- trunk/launchd/src/init.c Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/Makefile.am 2007-02-19 02:03:20 UTC (rev 23082) @@ -45,7 +45,7 @@ launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -Wno-unused-parameter launchd_LDFLAGS = -lbsm -launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c init.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c +launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime.c:: notifyServer.h launchd_internal.h launchd_core_logic.c:: protocol_vproc.h job_reply.h protocol_vprocServer.h Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/Makefile.in 2007-02-19 02:03:20 UTC (rev 23082) @@ -91,13 +91,12 @@ launchctl_OBJECTS = launchctl-launchctl.$(OBJEXT) launchctl_LDADD = $(LDADD) am__launchd_SOURCES_DIST = launchd.c launchd_core_logic.c \ - launchd_unix_ipc.c init.c protocol_vprocServer.c \ - notifyServer.c launchd_internalUser.c launchd_internalServer.c \ + launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c \ + launchd_internalUser.c launchd_internalServer.c \ job_replyUser.c launchd_runtime.c @LIBS_ONLY_FALSE@am_launchd_OBJECTS = launchd-launchd.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-launchd_core_logic.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-launchd_unix_ipc.$(OBJEXT) \ -@LIBS_ONLY_FALSE@ launchd-init.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-protocol_vprocServer.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-notifyServer.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-launchd_internalUser.$(OBJEXT) \ @@ -244,7 +243,7 @@ @LIBS_ONLY_FALSE@SystemStarter_SOURCES = StartupItems.c IPC.c SystemStarter.c @LIBS_ONLY_FALSE@launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -Wno-unused-parameter @LIBS_ONLY_FALSE@launchd_LDFLAGS = -lbsm -@LIBS_ONLY_FALSE@launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c init.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c +@LIBS_ONLY_FALSE@launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c @LIBS_ONLY_FALSE@launchproxy_LDFLAGS = -weak_framework Security @LIBS_ONLY_FALSE@man1_MANS = wait4path.1 launchctl.1 @LIBS_ONLY_FALSE@man5_MANS = launchd.plist.5 launchd.conf.5 @@ -425,7 +424,6 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemStarter-StartupItems.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemStarter-SystemStarter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchctl-launchctl.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-init.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-job_replyUser.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-launchd.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-launchd_core_logic.Po@am__quote@ @@ -614,20 +612,6 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -c -o launchd-launchd_unix_ipc.obj `if test -f 'launchd_unix_ipc.c'; then $(CYGPATH_W) 'launchd_unix_ipc.c'; else $(CYGPATH_W) '$(srcdir)/launchd_unix_ipc.c'; fi` -launchd-init.o: init.c -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-init.o -MD -MP -MF "$(DEPDIR)/launchd-init.Tpo" -c -o launchd-init.o `test -f 'init.c' || echo '$(srcdir)/'`init.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/launchd-init.Tpo" "$(DEPDIR)/launchd-init.Po"; else rm -f "$(DEPDIR)/launchd-init.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='init.c' object='launchd-init.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -c -o launchd-init.o `test -f 'init.c' || echo '$(srcdir)/'`init.c - -launchd-init.obj: init.c -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-init.obj -MD -MP -MF "$(DEPDIR)/launchd-init.Tpo" -c -o launchd-init.obj `if test -f 'init.c'; then $(CYGPATH_W) 'init.c'; else $(CYGPATH_W) '$(srcdir)/init.c'; fi`; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/launchd-init.Tpo" "$(DEPDIR)/launchd-init.Po"; else rm -f "$(DEPDIR)/launchd-init.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='init.c' object='launchd-init.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -c -o launchd-init.obj `if test -f 'init.c'; then $(CYGPATH_W) 'init.c'; else $(CYGPATH_W) '$(srcdir)/init.c'; fi` - launchd-protocol_vprocServer.o: protocol_vprocServer.c @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-protocol_vprocServer.o -MD -MP -MF "$(DEPDIR)/launchd-protocol_vprocServer.Tpo" -c -o launchd-protocol_vprocServer.o `test -f 'protocol_vprocServer.c' || echo '$(srcdir)/'`protocol_vprocServer.c; \ @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/launchd-protocol_vprocServer.Tpo" "$(DEPDIR)/launchd-protocol_vprocServer.Po"; else rm -f "$(DEPDIR)/launchd-protocol_vprocServer.Tpo"; exit 1; fi Deleted: trunk/launchd/src/init.c =================================================================== --- trunk/launchd/src/init.c 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/init.c 2007-02-19 02:03:20 UTC (rev 23082) @@ -1,383 +0,0 @@ -/* - * Copyright (c) 1999 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@ - */ -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Donn Seeley at Berkeley Software Design, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -static const char *const __rcs_file_version__ = "$Revision$"; - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "launchd.h" -#include "launchd_runtime.h" - -#define _PATH_RUNCOM "/etc/rc" - -#define STALL_TIMEOUT 30 /* wait N secs after warning */ - -static void stall(char *, ...); - -static void single_user_callback(void *, struct kevent *); -static kq_callback kqsingle_user_callback = single_user_callback; -static void runcom_callback(void *, struct kevent *); -static kq_callback kqruncom_callback = runcom_callback; - -static void single_user(void); -static void runcom(void); - -static bool single_user_mode = false; -static bool run_runcom = true; -static pid_t single_user_pid = 0; -static pid_t runcom_pid = 0; - -static void setctty(const char *, int); - -static void setsecuritylevel(int); -static int getsecuritylevel(void); -static bool should_fsck(void); - -void -init_boot(bool sflag) -{ - if (sflag) { - single_user_mode = true; - run_runcom = false; - } -} - -void -init_pre_kevent(void) -{ - if (single_user_pid || runcom_pid) - return; - - if (single_user_mode) - return single_user(); - - if (run_runcom) - return runcom(); - - /* - * If the administrator has not set the security level to -1 - * to indicate that the kernel should not run multiuser in secure - * 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) { - setsecuritylevel(1); - } -} - -void -stall(char *message, ...) -{ - va_list ap; - va_start(ap, message); - - vsyslog(LOG_ALERT, message, ap); - va_end(ap); - sleep(STALL_TIMEOUT); -} - -int -getsecuritylevel(void) -{ - int name[2], curlevel; - size_t len; - - name[0] = CTL_KERN; - name[1] = KERN_SECURELVL; - len = sizeof (curlevel); - if (sysctl(name, 2, &curlevel, &len, NULL, 0) == -1) { - syslog(LOG_ALERT, "cannot get kernel security level: %m"); - return -1; - } - return curlevel; -} - -void -setsecuritylevel(int newlevel) -{ - int name[2], curlevel; - - curlevel = getsecuritylevel(); - if (newlevel == curlevel) - return; - name[0] = CTL_KERN; - name[1] = KERN_SECURELVL; - if (sysctl(name, 2, NULL, NULL, &newlevel, sizeof newlevel) == -1) { - syslog(LOG_ALERT, "cannot change kernel security level from %d to %d: %m", - curlevel, newlevel); - return; - } - syslog(LOG_INFO, "kernel security level changed from %d to %d", - curlevel, newlevel); -} - -/* - * Start a session and allocate a controlling terminal. - * Only called by children of init after forking. - */ -void -setctty(const char *name, int flags) -{ - int fd; - - revoke(name); - if ((fd = open(name, flags | O_RDWR)) == -1) { - stall("can't open %s: %m", name); - exit(EXIT_FAILURE); - } - if (login_tty(fd) == -1) { - stall("can't get %s for controlling terminal: %m", name); - exit(EXIT_FAILURE); - } -} - -void -single_user(void) -{ - bool runcom_fsck = should_fsck(); - char *argv[2]; - - if (getsecuritylevel() > 0) - setsecuritylevel(0); - - if ((single_user_pid = launchd_fork()) == -1) { - syslog(LOG_ERR, "can't fork single-user shell, trying again: %m"); - return; - } else if (single_user_pid == 0) { - setctty(_PATH_CONSOLE, O_POPUP); - - setenv("TERM", "vt100", 1); - - if (runcom_fsck) { - fprintf(stdout, "Singleuser boot -- fsck not done\n"); - fprintf(stdout, "Root device is mounted read-only\n\n"); - fprintf(stdout, "If you want to make modifications to files:\n"); - fprintf(stdout, "\t/sbin/fsck -fy\n\t/sbin/mount -uw /\n\n"); - fprintf(stdout, "If you wish to boot the system:\n"); - fprintf(stdout, "\texit\n\n"); - fflush(stdout); - } - - argv[0] = "-sh"; - argv[1] = NULL; - execv(_PATH_BSHELL, argv); - syslog(LOG_ERR, "can't exec %s for single user: %m", _PATH_BSHELL); - sleep(STALL_TIMEOUT); - exit(EXIT_FAILURE); - } else { - if (kevent_mod(single_user_pid, EVFILT_PROC, EV_ADD, - NOTE_EXIT, 0, &kqsingle_user_callback) == -1) - single_user_callback(NULL, NULL); - } -} - -void -single_user_callback(void *obj __attribute__((unused)), struct kevent *kev __attribute__((unused))) -{ - int status; - - if (!launchd_assumes(waitpid(single_user_pid, &status, 0) == single_user_pid)) - return; - - if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) { - syslog(LOG_INFO, "single user shell terminated, restarting"); - run_runcom = true; - single_user_mode = false; - } else { - syslog(LOG_INFO, "single user shell terminated."); - run_runcom = false; - if (WTERMSIG(status) != SIGKILL) - single_user_mode = true; - } - - single_user_pid = 0; -} - -static struct timeval runcom_start_tv = { 0, 0 }; - -/* - * Run the system startup script. - */ -void -runcom(void) -{ - char *argv[] = { "/bin/launchctl", "bootstrap", NULL }; - struct termios term; - int vdisable; - - gettimeofday(&runcom_start_tv, NULL); - - if ((runcom_pid = launchd_fork()) == -1) { - syslog(LOG_ERR, "can't fork for %s on %s: %m", _PATH_BSHELL, _PATH_RUNCOM); - sleep(STALL_TIMEOUT); - runcom_pid = 0; - single_user_mode = true; - return; - } else if (runcom_pid > 0) { - run_runcom = false; - if (kevent_mod(runcom_pid, EVFILT_PROC, EV_ADD, - NOTE_EXIT, 0, &kqruncom_callback) == -1) { - runcom_callback(NULL, NULL); - } - return; - } - - setctty(_PATH_CONSOLE, 0); - - if ((vdisable = fpathconf(STDIN_FILENO, _PC_VDISABLE)) == -1) { - syslog(LOG_WARNING, "fpathconf(\"%s\") %m", _PATH_CONSOLE); - } else if (tcgetattr(STDIN_FILENO, &term) == -1) { - syslog(LOG_WARNING, "tcgetattr(\"%s\") %m", _PATH_CONSOLE); - } else { - term.c_cc[VINTR] = vdisable; - term.c_cc[VKILL] = vdisable; - term.c_cc[VQUIT] = vdisable; - term.c_cc[VSUSP] = vdisable; - term.c_cc[VSTART] = vdisable; - term.c_cc[VSTOP] = vdisable; - term.c_cc[VDSUSP] = vdisable; - - if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &term) == -1) - syslog(LOG_WARNING, "tcsetattr(\"%s\") %m", _PATH_CONSOLE); - } - - execv(argv[0], argv); - stall("can't exec %s for %s: %m", _PATH_BSHELL, _PATH_RUNCOM); - exit(EXIT_FAILURE); -} - -void -runcom_callback(void *obj __attribute__((unused)), struct kevent *kev __attribute__((unused))) -{ - int status; - struct timeval runcom_end_tv, runcom_total_tv; - double sec; - - gettimeofday(&runcom_end_tv, NULL); - timersub(&runcom_end_tv, &runcom_start_tv, &runcom_total_tv); - sec = runcom_total_tv.tv_sec; - sec += (double)runcom_total_tv.tv_usec / (double)1000000; - syslog(LOG_INFO, "%s finished in: %.3f seconds", _PATH_RUNCOM, sec); - - if (launchd_assumes(waitpid(runcom_pid, &status, 0) == runcom_pid)) { - runcom_pid = 0; - } else { - syslog(LOG_ERR, "going to single user mode"); - single_user_mode = true; - return; - } - - if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) { - return; - } else if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGTERM || WTERMSIG(status) == SIGKILL)) { - return; - } - - syslog(LOG_ERR, "%s on %s terminated abnormally, going to single user mode", - _PATH_BSHELL, _PATH_RUNCOM); - single_user_mode = true; -} - -bool -init_check_pid(pid_t p) -{ - if (single_user_pid == p) - return true; - - if (runcom_pid == p) - return true; - - return false; -} - -bool -should_fsck(void) -{ - struct statfs sfs; - bool r = true; - - if (launchd_assumes(statfs("/", &sfs) != -1)) { - if (!(sfs.f_flags & MNT_RDONLY)) { - r = false; - } - } - - return r; -} Modified: trunk/launchd/src/launchctl.1 =================================================================== --- trunk/launchd/src/launchctl.1 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/launchctl.1 2007-02-19 02:03:20 UTC (rev 23082) @@ -130,12 +130,6 @@ With four arguments, the third and forth argument represent the soft and hard limits respectively. See .Xr setrlimit 2 . -.It Ar stdout path -Set the standard out file descriptor to the given path. -.Nm launchd -.It Ar stderr path -Set the standard error file descriptor to the given path. -.Nm launchd .It Ar shutdown Tell .Nm launchd Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/launchctl.c 2007-02-19 02:03:20 UTC (rev 23082) @@ -61,6 +61,7 @@ #include #include #include +#include #include "libbootstrap_public.h" #include "libvproc_public.h" @@ -137,6 +138,8 @@ 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); +static void do_single_user_mode(bool); +static bool do_single_user_mode2(void); static int bootstrap_cmd(int argc, char *const argv[]); static int load_and_unload_cmd(int argc, char *const argv[]); @@ -1174,16 +1177,74 @@ return fd; } -int -bootstrap_cmd(int argc __attribute__((unused)), char *const argv[] __attribute__((unused))) +void +do_single_user_mode(bool sflag) { + if (sflag) { + while (!do_single_user_mode2()) { + sleep(1); + } + } +} + +bool +do_single_user_mode2(void) +{ + bool runcom_fsck = true; /* should_fsck(); */ + int wstatus; + int fd; + pid_t p; + + switch ((p = fork())) { + case -1: + syslog(LOG_ERR, "can't fork single-user shell, trying again: %m"); + return false; + case 0: + break; + default: + assumes(waitpid(p, &wstatus, 0) != -1); + if (WIFEXITED(wstatus)) { + if (WEXITSTATUS(wstatus) == EXIT_SUCCESS) { + return true; + } else { + fprintf(stdout, "single user mode: exit status: %d\n", WEXITSTATUS(wstatus)); + } + } else { + fprintf(stdout, "single user mode shell: %s\n", strsignal(WTERMSIG(wstatus))); + } + return false; + } + + revoke(_PATH_CONSOLE); + if (!assumes((fd = open(_PATH_CONSOLE, O_RDWR)) != -1)) { + _exit(EXIT_FAILURE); + } + if (!assumes(login_tty(fd) != -1)) { + _exit(EXIT_FAILURE); + } + setenv("TERM", "vt100", 1); + if (runcom_fsck) { + fprintf(stdout, "Singleuser boot -- fsck not done\n"); + fprintf(stdout, "Root device is mounted read-only\n\n"); + fprintf(stdout, "If you want to make modifications to files:\n"); + fprintf(stdout, "\t/sbin/fsck -fy\n\t/sbin/mount -uw /\n\n"); + fprintf(stdout, "If you wish to boot the system:\n"); + fprintf(stdout, "\texit\n\n"); + fflush(stdout); + } + + execl(_PATH_BSHELL, "-sh", NULL); + syslog(LOG_ERR, "can't exec %s for single user: %m", _PATH_BSHELL); + _exit(EXIT_FAILURE); +} + +static void +very_pid2_specific_bootstrap(bool sflag) +{ int hnmib[] = { CTL_KERN, KERN_HOSTNAME }; struct group *tfp_gr; - if (getuid() != 0) { - fprintf(stderr, "%s: Only root can run the 'bootstrap' sub-command right now.\n", getprogname()); - return 1; - } + do_single_user_mode(sflag); if (assumes((tfp_gr = getgrnam("procview")) != NULL)) { int tfp_r_mib[3] = { CTL_KERN, KERN_TFP, KERN_TFP_READ_GROUP }; @@ -1262,9 +1323,12 @@ _vproc_set_global_on_demand(true); - char *load_launchd_items[] = { "load", "-D", "all", "/etc/mach_init.d", NULL }; - if (is_safeboot()) + char *load_launchd_items[] = { "load", "-D", "all", "/etc/mach_init.d", NULL, NULL }; + + if (is_safeboot()) { load_launchd_items[2] = "system"; + } + assumes(load_and_unload_cmd(4, load_launchd_items) == 0); const char *bcc_tag_tool[] = { "BootCacheControl", "tag", NULL }; @@ -1273,7 +1337,23 @@ do_bootroot_magic(); _vproc_set_global_on_demand(false); +} +int +bootstrap_cmd(int argc, char *const argv[] __attribute__((unused))) +{ + if (getpid() == 2 && getuid() == 0) { + very_pid2_specific_bootstrap(argc == 2); + } else if (getuid() != 0) { + char *load_launchd_items[] = { "load", "-D", "all", "-S", "Background", NULL }; + + if (is_safeboot()) { + load_launchd_items[2] = "system"; + } + + assumes(load_and_unload_cmd(5, load_launchd_items) == 0); + } + return 0; } @@ -1680,45 +1760,10 @@ } int -stdio_cmd(int argc, char *const argv[]) +stdio_cmd(int argc __attribute__((unused)), char *const argv[]) { - launch_data_t resp, msg, tmp; - int e, r = 0; - - if (argc != 2) { - fprintf(stderr, "usage: %s %s \n", getprogname(), argv[0]); - return 1; - } - - msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY); - - tmp = launch_data_new_string(argv[1]); - - if (!strcmp(argv[0], "stdout")) { - launch_data_dict_insert(msg, tmp, LAUNCH_KEY_SETSTDOUT); - } else { - launch_data_dict_insert(msg, tmp, LAUNCH_KEY_SETSTDERR); - } - - 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 { - fprintf(stderr, "%s %s returned unknown response\n", getprogname(), argv[0]); - r = 1; - } - - launch_data_free(resp); - - return r; + fprintf(stderr, "%s %s: This sub-command no longer does anything\n", getprogname(), argv[0]); + return 1; } int Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/launchd.c 2007-02-19 02:03:20 UTC (rev 23082) @@ -70,13 +70,11 @@ #include "libvproc_public.h" #include "libvproc_internal.h" #include "liblaunch_public.h" -#include "liblaunch_private.h" #include "launchd_runtime.h" #include "launchd_core_logic.h" #include "launchd_unix_ipc.h" -#define PID1LAUNCHD_CONF "/etc/launchd.conf" #define LAUNCHD_CONF ".launchd.conf" #define SECURITY_LIB "/System/Library/Frameworks/Security.framework/Versions/A/Security" #define SHUTDOWN_LOG_DIR "/var/log/shutdown" @@ -84,16 +82,12 @@ extern char **environ; -static void signal_callback(void *, struct kevent *); static void pfsystem_callback(void *, struct kevent *); -static kq_callback kqsignal_callback = signal_callback; static kq_callback kqpfsystem_callback = pfsystem_callback; -static void pid1_magic_init(bool sflag); +static void pid1_magic_init(void); -static void usage(FILE *where); - static void testfd_or_openfd(int fd, const char *path, int flags); static bool get_network_state(void); static void monitor_networking_state(void); @@ -102,13 +96,9 @@ static void prep_shutdown_log_dir(void); static bool re_exec_in_single_user_mode = false; -static job_t rlcj = NULL; -static jmp_buf doom_doom_doom; static void *crash_addr; static pid_t crash_pid; -static const char *launchctl_bootstrap_tool[] = { "/bin/launchctl", /* "bootstrap", */ NULL }; -sigset_t blocked_signals = 0; static bool shutdown_in_progress = false; bool debug_shutdown_hangs = false; bool network_up = false; @@ -118,187 +108,61 @@ main(int argc, char *const *argv) { static const int sigigns[] = { SIGHUP, SIGINT, SIGPIPE, SIGALRM, - SIGTERM, SIGURG, SIGTSTP, SIGTSTP, SIGCONT, /*SIGCHLD,*/ - SIGTTIN, SIGTTOU, SIGIO, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, + SIGTERM, SIGURG, SIGTSTP, SIGTSTP, SIGCONT, SIGTTIN, + SIGTTOU, SIGIO, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, SIGWINCH, SIGINFO, SIGUSR1, SIGUSR2 }; - bool sflag = false, Dflag = false; - char ldconf[PATH_MAX] = PID1LAUNCHD_CONF; - const char *h = getenv("HOME"); - const char *optargs = NULL; - struct stat sb; - size_t i, checkin_fdcnt = 0; - int *checkin_fds = NULL; - mach_port_t checkin_mport = MACH_PORT_NULL; - int ch, logopts; + bool sflag = false; + size_t i; + int ch; testfd_or_openfd(STDIN_FILENO, _PATH_DEVNULL, O_RDONLY); testfd_or_openfd(STDOUT_FILENO, _PATH_DEVNULL, O_WRONLY); testfd_or_openfd(STDERR_FILENO, _PATH_DEVNULL, O_WRONLY); - /* main() phase one: sanitize the process */ - - if (getpid() != 1) { - launch_data_t ldresp, ldmsg = launch_data_new_string(LAUNCH_KEY_CHECKIN); - - if ((ldresp = launch_msg(ldmsg))) { - if (launch_data_get_type(ldresp) == LAUNCH_DATA_DICTIONARY) { - const char *ldlabel = launch_data_get_string(launch_data_dict_lookup(ldresp, LAUNCH_JOBKEY_LABEL)); - launch_data_t tmp; - - if ((tmp = launch_data_dict_lookup(ldresp, LAUNCH_JOBKEY_SOCKETS))) { - if ((tmp = launch_data_dict_lookup(tmp, "LaunchIPC"))) { - checkin_fdcnt = launch_data_array_get_count(tmp); - checkin_fds = alloca(sizeof(int) * checkin_fdcnt); - for (i = 0; i < checkin_fdcnt; i++) { - checkin_fds[i] = _fd(launch_data_get_fd(launch_data_array_get_index(tmp, i))); - } - } - } - if ((tmp = launch_data_dict_lookup(ldresp, LAUNCH_JOBKEY_MACHSERVICES))) { - if ((tmp = launch_data_dict_lookup(tmp, ldlabel))) { - checkin_mport = launch_data_get_machport(tmp); - } - } - } - launch_data_free(ldresp); - } else { - int sigi, fdi, dts = getdtablesize(); - sigset_t emptyset; - - /* We couldn't check-in. - * - * Assume the worst and clean up whatever mess our parent process left us with... - */ - - for (fdi = STDERR_FILENO + 1; fdi < dts; fdi++) - close(fdi); - for (sigi = 1; sigi < NSIG; sigi++) { - switch (sigi) { - case SIGKILL: - case SIGSTOP: - break; - default: - launchd_assumes(signal(sigi, SIG_DFL) != SIG_ERR); - break; - } - } - sigemptyset(&emptyset); - launchd_assumes(sigprocmask(SIG_SETMASK, &emptyset, NULL) == 0); - } - - launch_data_free(ldmsg); - } - - launchd_runtime_init(); - - /* main() phase two: parse arguments */ - - if (getpid() == 1) { - optargs = "s"; - } else { - optargs = "Dh"; - } - - while ((ch = getopt(argc, argv, optargs)) != -1) { + while ((ch = getopt(argc, argv, "s")) != -1) { switch (ch) { - case 'D': Dflag = true; break; /* debug */ case 's': sflag = true; break; /* single user */ - case 'h': usage(stdout); break; /* help */ case '?': /* we should do something with the global optopt variable here */ default: - fprintf(stderr, "ignoring unknown arguments\n"); - usage(stderr); + fprintf(stderr, "%s: ignoring unknown arguments\n", getprogname()); break; } } - argc -= optind; - argv += optind; - /* main phase three: get the party started */ - - logopts = LOG_PID|LOG_CONS; - if (Dflag) { - logopts |= LOG_PERROR; + if (getpid() != 1 && getppid() != 1) { + fprintf(stderr, "%s: This program is not meant to be run directly.\n", getprogname()); + exit(EXIT_FAILURE); } - openlog(getprogname(), logopts, LOG_LAUNCHD); - setlogmask(LOG_UPTO(Dflag ? LOG_DEBUG : LOG_NOTICE)); + launchd_runtime_init(); - sigemptyset(&blocked_signals); + openlog(getprogname(), LOG_PID|LOG_CONS, LOG_LAUNCHD); + setlogmask(LOG_UPTO(/* LOG_DEBUG */ LOG_NOTICE)); for (i = 0; i < (sizeof(sigigns) / sizeof(int)); i++) { - launchd_assumes(kevent_mod(sigigns[i], EVFILT_SIGNAL, EV_ADD, 0, 0, &kqsignal_callback) != -1); - sigaddset(&blocked_signals, sigigns[i]); launchd_assumes(signal(sigigns[i], SIG_IGN) != SIG_ERR); } - /* sigh... ignoring SIGCHLD has side effects: we can't call wait*() */ - launchd_assert(kevent_mod(SIGCHLD, EVFILT_SIGNAL, EV_ADD, 0, 0, &kqsignal_callback) != -1); - - mach_init_init(checkin_mport); - - if (h) { - snprintf(ldconf, sizeof(ldconf), "%s/%s", h, LAUNCHD_CONF); - } - - rlcj = job_new(root_jobmgr, READCONF_LABEL, NULL, launchctl_bootstrap_tool, ldconf); - launchd_assert(rlcj != NULL); - if (NULL == getenv("PATH")) { setenv("PATH", _PATH_STDPATH, 1); } if (getpid() == 1) { - pid1_magic_init(sflag); + pid1_magic_init(); } else { - ipc_server_init(checkin_fds, checkin_fdcnt); + ipc_server_init(); } monitor_networking_state(); - /* - * 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) { - rlcj = job_dispatch(rlcj, true); - } - char *doom_why = "at instruction"; - switch (setjmp(doom_doom_doom)) { - case 0: - break; - case SIGBUS: - case SIGSEGV: - doom_why = "trying to read/write"; - case SIGILL: - case SIGFPE: - syslog(LOG_EMERG, "We crashed %s: %p (sent by PID %u)", doom_why, crash_addr, crash_pid); - default: - sync(); - sleep(3); - /* the kernel will panic() when PID 1 exits */ - _exit(EXIT_FAILURE); - /* we should never get here */ - reboot(0); - /* or here either */ - break; - } - if (getpid() == 1) { handle_pid1_crashes_separately(); - - if (!job_active(rlcj)) { - init_pre_kevent(); - } } + jobmgr_init(sflag); + launchd_runtime(); } @@ -322,6 +186,7 @@ void fatal_signal_handler(int sig, siginfo_t *si, void *uap) { + const char *doom_why = "at instruction"; char *sample_args[] = { "/usr/bin/sample", "1", "1", "-file", PID1_CRASH_LOGFILE, NULL }; pid_t sample_p; int wstatus; @@ -338,51 +203,42 @@ break; default: waitpid(sample_p, &wstatus, 0); - sync(); break; case -1: break; } - longjmp(doom_doom_doom, sig); + switch (sig) { + default: + case 0: + break; + case SIGBUS: + case SIGSEGV: + doom_why = "trying to read/write"; + case SIGILL: + case SIGFPE: + syslog(LOG_EMERG, "We crashed %s: %p (sent by PID %u)", doom_why, crash_addr, crash_pid); + sync(); + sleep(3); + /* the kernel will panic() when PID 1 exits */ + _exit(EXIT_FAILURE); + /* we should never get here */ + reboot(0); + /* or here either */ + break; + } } void -pid1_magic_init(bool sflag) +pid1_magic_init(void) { launchd_assumes(setsid() != -1); launchd_assumes(chdir("/") != -1); launchd_assumes(setlogin("root") != -1); launchd_assumes(mount("fdesc", "/dev", MNT_UNION, NULL) != -1); - - init_boot(sflag); } -void -usage(FILE *where) -{ - const char *opts = "[-d]"; - - if (getuid() == 0) { - opts = "[-d] [-S -U ]"; - } - - fprintf(where, "%s: %s [-- command [args ...]]\n", getprogname(), opts); - - fprintf(where, "\t-d Daemonize.\n"); - fprintf(where, "\t-h This usage statement.\n"); - - if (getuid() == 0) { - fprintf(where, "\t-S What type of session to create (Aqua, tty or X11).\n"); - fprintf(where, "\t-U Which user to create the session as.\n"); - } - - if (where == stdout) { - exit(EXIT_SUCCESS); - } -} - int _fd(int fd) { @@ -395,46 +251,7 @@ void prep_shutdown_log_dir(void) { - struct stat sb; - struct dirent *de; - DIR *thedir = NULL; - - if (!launchd_assumes(mkdir(SHUTDOWN_LOG_DIR, S_IRWXU) != -1 || errno == EEXIST)) { - goto out; - } - - if (!launchd_assumes(lstat(SHUTDOWN_LOG_DIR, &sb) != -1)) { - goto out; - } - - if (!launchd_assumes(S_ISDIR(sb.st_mode))) { - goto out; - } - - if (!launchd_assumes(chdir(SHUTDOWN_LOG_DIR) != -1)) { - goto out; - } - - if (!launchd_assumes((thedir = opendir(".")) != NULL)) { - goto out; - } - - while ((de = readdir(thedir))) { - if (strcmp(de->d_name, ".") == 0) { - continue; - } else if (strcmp(de->d_name, "..") == 0) { - continue; - } else { - launchd_assumes(remove(de->d_name) != -1); - } - } - -out: - if (thedir) { - closedir(thedir); - } - - chdir("/"); + launchd_assumes(mkdir(SHUTDOWN_LOG_DIR, S_IRWXU) != -1 || errno == EEXIST); } void @@ -457,8 +274,6 @@ debug_shutdown_hangs = true; } - rlcj = NULL; - launchd_assert(jobmgr_shutdown(root_jobmgr) != NULL); } @@ -476,24 +291,6 @@ kill(-1, SIGKILL); } -static void signal_callback(void *obj __attribute__((unused)), struct kevent *kev) -{ - syslog(LOG_DEBUG, "Received signal: %u", kev->ident); - - switch (kev->ident) { - case SIGHUP: - if (rlcj) { - rlcj = job_dispatch(rlcj, true); - } - break; - case SIGTERM: - launchd_shutdown(); - break; - default: - break; - } -} - void launchd_SessionCreate(void) { @@ -525,30 +322,6 @@ } } -launch_data_t -launchd_setstdio(int d, launch_data_t o) -{ - launch_data_t resp = launch_data_new_errno(0); - - if (launch_data_get_type(o) == LAUNCH_DATA_STRING) { - switch (d) { - case STDOUT_FILENO: - jobmgr_set_stdout(root_jobmgr, launch_data_get_string(o)); - break; - case STDERR_FILENO: - jobmgr_set_stderr(root_jobmgr, launch_data_get_string(o)); - break; - default: - launch_data_set_errno(resp, EINVAL); - break; - } - } else { - launch_data_set_errno(resp, EINVAL); - } - - return resp; -} - void batch_job_enable(bool e, struct conncb *c) { @@ -662,26 +435,3 @@ syslog(LOG_NOTICE, "Bug: %s:%u (%s):%u: %s", file, line, buf, saved_errno, test); } - -void -launchd_post_kevent(void) -{ -#if 0 - if (shutdown_in_progress && jobmgr_is_idle(root_jobmgr)) { - shutdown_in_progress = false; - - if (getpid() == 1) { - if (re_exec_in_single_user_mode) { - kill(-1, SIGKILL); /* One last time, just to clear the room */ - launchd_assumes(execl("/sbin/launchd", "/sbin/launchd", "-s", NULL) != -1); - } - } - } -#endif - if (getpid() == 1) { - if (rlcj && job_active(rlcj)) { - return; - } - init_pre_kevent(); - } -} Modified: trunk/launchd/src/launchd.h =================================================================== --- trunk/launchd/src/launchd.h 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/launchd.h 2007-02-19 02:03:20 UTC (rev 23082) @@ -26,12 +26,11 @@ #include "libbootstrap_public.h" #include "launchd_runtime.h" -#define READCONF_LABEL "com.apple.launchd.readconfig" +#define SHUTDOWN_LOG_DIR "/var/log/shutdown" struct kevent; struct conncb; -extern sigset_t blocked_signals; extern bool debug_shutdown_hangs; extern bool network_up; extern int batch_disabler_count; @@ -45,15 +44,9 @@ void launchd_SessionCreate(void); void launchd_shutdown(void); void launchd_single_user(void); -void launchd_post_kevent(void); -pid_t launchd_fork(void); boolean_t launchd_mach_ipc_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply); -void init_boot(bool sflag); -void init_pre_kevent(void); - void mach_start_shutdown(void); -void mach_init_init(mach_port_t); int _fd(int fd); Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-19 02:03:20 UTC (rev 23082) @@ -194,6 +194,7 @@ static void semaphoreitem_ignore(job_t j, struct semaphoreitem *si); struct jobmgr_s { + kq_callback kqjobmgr_callback; SLIST_ENTRY(jobmgr_s) sle; SLIST_HEAD(, jobmgr_s) submgrs; TAILQ_HEAD(, job_s) jobs; @@ -201,8 +202,6 @@ mach_port_t req_port; jobmgr_t parentmgr; job_t anonj; - char *jm_stdout; - char *jm_stderr; int reboot_flags; unsigned int global_on_demand_cnt; unsigned int sent_stop_to_hopeful_jobs:1, shutting_down:1; @@ -212,7 +211,7 @@ #define jobmgr_assumes(jm, e) \ (__builtin_expect(!(e), 0) ? jobmgr_log_bug(jm, __rcs_file_version__, __FILE__, __LINE__, #e), false : true) -static jobmgr_t jobmgr_new(jobmgr_t jm, mach_port_t requestorport, mach_port_t checkin_port); +static jobmgr_t jobmgr_new(jobmgr_t jm, mach_port_t requestorport, mach_port_t transfer_port, bool sflag); static jobmgr_t jobmgr_parent(jobmgr_t jm); static jobmgr_t jobmgr_do_garbage_collection(jobmgr_t jm); static bool jobmgr_is_idle(jobmgr_t jm); @@ -222,6 +221,7 @@ static job_t jobmgr_new_anonymous(jobmgr_t jm); 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); static pid_t jobmgr_fork(jobmgr_t jm); static void jobmgr_setup_env_from_other_jobs(jobmgr_t jm); static struct machservice *jobmgr_lookup_service(jobmgr_t jm, const char *name, bool check_parent); @@ -229,8 +229,6 @@ static void jobmgr_log(jobmgr_t jm, int pri, const char *msg, ...) __attribute__((format(printf, 3, 4))); /* static void jobmgr_log_error(jobmgr_t jm, int pri, const char *msg, ...) __attribute__((format(printf, 3, 4))); */ static void jobmgr_log_bug(jobmgr_t jm, const char *rcs_rev, const char *path, unsigned int line, const char *test); -static char *jobmgr_get_stdout(jobmgr_t jm); -static char *jobmgr_get_stderr(jobmgr_t jm); struct job_s { kq_callback kqjob_callback; @@ -255,7 +253,6 @@ char *workingdir; char *username; char *groupname; - char *stdinpath; char *stdoutpath; char *stderrpath; pid_t p; @@ -311,6 +308,7 @@ static void job_callback_timer(job_t j, void *ident); static void job_callback_read(job_t j, int ident); static launch_data_t job_export2(job_t j, bool subjobs); +static job_t job_new(jobmgr_t jm, const char *label, const char *prog, const char *const *argv); 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); static job_t job_new_via_mach_init(job_t j, const char *cmd, uid_t uid, bool ond); static const char *job_prog(job_t j); @@ -577,14 +575,6 @@ jobmgr_assumes(jm, launchd_mport_close_recv(jm->jm_port) == KERN_SUCCESS); } - if (jm->jm_stdout) { - free(jm->jm_stdout); - } - - if (jm->jm_stderr) { - free(jm->jm_stderr); - } - if (jm->parentmgr) { SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); } else if (getpid() == 1) { @@ -677,9 +667,6 @@ if (j->groupname) { free(j->groupname); } - if (j->stdinpath) { - free(j->stdinpath); - } if (j->stdoutpath) { free(j->stdoutpath); } @@ -797,7 +784,7 @@ /* preflight the string so we know how big it is */ snprintf(buf, sizeof(buf), "%s.%s", sizeof(void *) == 8 ? "0xdeadbeeffeedface" : "0xbabecafe", basename((char *)argv[0])); - jr = job_new(j->mgr, buf, NULL, argv, NULL); + jr = job_new(j->mgr, buf, NULL, argv); free(argv); @@ -852,7 +839,7 @@ return NULL; } - jr = job_new(j->mgr, label, path, argv, NULL); + jr = job_new(j->mgr, label, path, argv); if (!jr) { return NULL; @@ -907,7 +894,7 @@ snprintf(newlabel, sizeof(newlabel), "%u.anonymous", MACH_PORT_INDEX(jm->jm_port)); - if ((jr = job_new(jm, newlabel, procname, NULL, NULL))) { + if ((jr = job_new(jm, newlabel, procname, NULL))) { jr->anonymous = true; } @@ -915,14 +902,15 @@ } job_t -job_new(jobmgr_t jm, const char *label, const char *prog, const char *const *argv, const char *stdinpath) +job_new(jobmgr_t jm, const char *label, const char *prog, const char *const *argv) { - char compile_time_assert[offsetof(struct job_s, kqjob_callback) == 0 ? 1 : -1] __attribute__((unused)); const char *const *argv_tmp = argv; char *co; int i, cc = 0; job_t j; + launchd_assert(offsetof(struct job_s, kqjob_callback) == 0); + if (jm->shutting_down) { errno = EINVAL; return NULL; @@ -956,13 +944,6 @@ } } - if (stdinpath) { - j->stdinpath = strdup(stdinpath); - if (!job_assumes(j, j->stdinpath != NULL)) { - goto out_bad; - } - } - if (argv) { while (*argv_tmp++) j->argc++; @@ -996,9 +977,6 @@ if (j->prog) { free(j->prog); } - if (j->stdinpath) { - free(j->stdinpath); - } free(j); return NULL; @@ -1488,7 +1466,7 @@ return NULL; } - if ((j = job_new(root_jobmgr, label, prog, argv, NULL))) { + if ((j = job_new(root_jobmgr, label, prog, argv))) { launch_data_dict_iterate(pload, job_import_keys, j); } @@ -1801,7 +1779,7 @@ j->sent_sigkill = true; job_assumes(j, kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, - EV_ADD|EV_ONESHOT, NOTE_SECONDS, LAUNCHD_SIGKILL_TIMEOUT, j) != -1); + EV_ADD, NOTE_SECONDS, LAUNCHD_SIGKILL_TIMEOUT, j) != -1); } void @@ -1832,8 +1810,15 @@ job_dispatch(j, true); } else if (&j->exit_timeout == ident) { if (j->sent_sigkill) { - job_log(j, LOG_ERR, "Did not die after sending SIGKILL %u seconds ago...", LAUNCHD_SIGKILL_TIMEOUT); - if (debug_shutdown_hangs) { + struct timeval tvd, tve; + double delta; + + job_assumes(j, gettimeofday(&tve, NULL) != -1); + timersub(&tve, &j->sent_sigterm_time, &tvd); + delta = (double)tvd.tv_sec + (double)tvd.tv_usec / (double)1000000; + delta -= (double)j->exit_timeout; + job_log(j, LOG_ERR, "Did not die after sending SIGKILL %f seconds ago...", delta); + if (debug_shutdown_hangs && delta > 60) { job_assumes(j, host_reboot(mach_host_self(), HOST_REBOOT_DEBUGGER) == KERN_SUCCESS); } } else { @@ -1857,6 +1842,25 @@ } void +jobmgr_callback(void *obj, struct kevent *kev) +{ + jobmgr_t jm = obj; + + switch (kev->filter) { + case EVFILT_SIGNAL: + switch (kev->ident) { + case SIGTERM: + return launchd_shutdown(); + default: + return (void)jobmgr_assumes(jm, false); + } + break; + default: + return (void)jobmgr_assumes(jm, false); + } +} + +void job_callback(void *obj, struct kevent *kev) { job_t j = obj; @@ -1915,10 +1919,7 @@ j->sent_sigterm_time.tv_sec = 0; j->sent_sigterm_time.tv_usec = 0; - /* FIXME, using stdinpath is a hack for re-reading the conf file */ - if (j->stdinpath) { - sipc = true; - } else if (!j->legacy_mach_job) { + if (!j->legacy_mach_job) { sipc = (!SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices)); } @@ -2056,6 +2057,10 @@ job_assumes(j, binpref_out_cnt == j->j_binpref_cnt); } + for (i = 1; i < NSIG; i++) { + signal(i, SIG_DFL); + } + if (j->prog) { errno = posix_spawn(&junk_pid, j->inetcompat ? file2exec : j->prog, NULL, &spattr, (char *const*)argv, environ); job_log_error(j, LOG_ERR, "posix_spawn(\"%s\", ...)", j->prog); @@ -2262,9 +2267,8 @@ umask(j->mask); } - job_setup_fd(j, STDIN_FILENO, j->stdinpath, O_RDONLY); - job_setup_fd(j, STDOUT_FILENO, j->stdoutpath ? j->stdoutpath : jobmgr_get_stdout(j->mgr), O_WRONLY|O_APPEND|O_CREAT); - job_setup_fd(j, STDERR_FILENO, j->stderrpath ? j->stderrpath : jobmgr_get_stderr(j->mgr), O_WRONLY|O_APPEND|O_CREAT); + job_setup_fd(j, STDOUT_FILENO, j->stdoutpath, O_WRONLY|O_APPEND|O_CREAT); + job_setup_fd(j, STDERR_FILENO, j->stderrpath, O_WRONLY|O_APPEND|O_CREAT); jobmgr_setup_env_from_other_jobs(j->mgr); @@ -2278,43 +2282,10 @@ void job_setup_fd(job_t j, int target_fd, const char *path, int flags) { -#if 0 - char newpath[PATH_MAX]; -#endif int fd; if (!path) { -#if 0 - switch (target_fd) { - case STDOUT_FILENO: - case STDERR_FILENO: - flags |= O_TRUNC; - break; - default: - return; - } - - if (getuid() == 0) { - snprintf(newpath, sizeof(newpath), "/var/log/launchd"); - } else { - struct passwd *pwe; - - if (!job_assumes(j, (pwe = getpwuid(getuid())) != NULL)) { - return; - } - - snprintf(newpath, sizeof(newpath), "%s/Library/Logs/launchd", pwe->pw_dir); - } - - mkdir(newpath, ACCESSPERMS); - - strcat(newpath, "/"); - strcat(newpath, j->label); - - path = newpath; -#else return; -#endif } if ((fd = open(path, flags|O_NOCTTY, DEFFILEMODE)) == -1) { @@ -2427,10 +2398,10 @@ void job_logv(job_t j, int pri, int err, const char *msg, va_list ap) { - char newmsg[10000]; + char *newmsg; char *newlabel; int oldmask = 0; - size_t i, o, jlabel_len = strlen(j->label); + size_t i, o, jlabel_len = strlen(j->label), newmsgsz; /* * Hack: If bootstrap_port is set, we must be on the child side of a @@ -2442,6 +2413,8 @@ } newlabel = alloca((jlabel_len + 1) * 2); + newmsgsz = (jlabel_len + 1) * 2 + strlen(msg) + 100; + newmsg = alloca(newmsgsz); for (i = 0, o = 0; i < jlabel_len; i++, o++) { if (j->label[i] == '%') { @@ -2453,16 +2426,16 @@ newlabel[o] = '\0'; if (err) { - snprintf(newmsg, sizeof(newmsg), "%s: %s: %s", newlabel, msg, strerror(err)); + snprintf(newmsg, newmsgsz, "%s: %s: %s", newlabel, msg, strerror(err)); } else { - snprintf(newmsg, sizeof(newmsg), "%s: %s", newlabel, msg); + snprintf(newmsg, newmsgsz, "%s: %s", newlabel, msg); } if (j->debug) { oldmask = setlogmask(LOG_UPTO(LOG_DEBUG)); } - vsyslog(pri, newmsg, ap); + jobmgr_logv(j->mgr, pri, 0, newmsg, ap); if (j->debug) { setlogmask(oldmask); @@ -2514,9 +2487,34 @@ void jobmgr_logv(jobmgr_t jm, int pri, int err, const char *msg, va_list ap) { - if (launchd_assumes(jm->anonj)) { - job_logv(jm->anonj, pri, err, msg, ap); + char *newmsg; + char *newname; + size_t i, o, jmname_len = strlen(jm->name), newmsgsz; + + newname = alloca((jmname_len + 1) * 2); + newmsgsz = (jmname_len + 1) * 2 + strlen(msg) + 100; + newmsg = alloca(newmsgsz); + + for (i = 0, o = 0; i < jmname_len; i++, o++) { + if (jm->name[i] == '%') { + newname[o] = '%'; + o++; + } + newname[o] = jm->name[i]; } + newname[o] = '\0'; + + if (err) { + snprintf(newmsg, newmsgsz, "%s: %s: %s", newname, msg, strerror(err)); + } else { + snprintf(newmsg, newmsgsz, "%s: %s", newname, msg); + } + + if (jm->parentmgr) { + jobmgr_logv(jm->parentmgr, pri, 0, newmsg, ap); + } else { + vsyslog(pri, newmsg, ap); + } } void @@ -3045,20 +3043,12 @@ } pid_t -launchd_fork(void) -{ - return jobmgr_fork(root_jobmgr); -} - -pid_t jobmgr_fork(jobmgr_t jm) { mach_port_t p = jm->jm_port; pid_t r = -1; int saved_errno; - sigprocmask(SIG_BLOCK, &blocked_signals, NULL); - jobmgr_assumes(jm, launchd_mport_make_send(p) == KERN_SUCCESS); jobmgr_assumes(jm, launchd_set_bport(p) == KERN_SUCCESS); jobmgr_assumes(jm, launchd_mport_deallocate(p) == KERN_SUCCESS); @@ -3069,18 +3059,8 @@ if (r != 0) { jobmgr_assumes(jm, launchd_set_bport(MACH_PORT_NULL) == KERN_SUCCESS); - } else if (r == 0) { - size_t i; - - for (i = 0; i < NSIG; i++) { - if (sigismember(&blocked_signals, i)) { - signal(i, SIG_DFL); - } - } } - sigprocmask(SIG_UNBLOCK, &blocked_signals, NULL); - errno = saved_errno; return r; } @@ -3360,50 +3340,6 @@ return true; } -void -jobmgr_set_stdout(jobmgr_t jm, const char *what) -{ - if (jm->jm_stdout) { - free(jm->jm_stdout); - } - - jm->jm_stdout = strdup(what); -} - -void -jobmgr_set_stderr(jobmgr_t jm, const char *what) -{ - if (jm->jm_stderr) { - free(jm->jm_stderr); - } - - jm->jm_stderr = strdup(what); -} - -char * -jobmgr_get_stdout(jobmgr_t jm) -{ - if (jm->jm_stdout) { - return jm->jm_stdout; - } else if (jm->parentmgr == NULL) { - return NULL; - } - - return jobmgr_get_stdout(jm->parentmgr); -} - -char * -jobmgr_get_stderr(jobmgr_t jm) -{ - if (jm->jm_stderr) { - return jm->jm_stderr; - } else if (jm->parentmgr == NULL) { - return NULL; - } - - return jobmgr_get_stderr(jm->parentmgr); -} - jobmgr_t jobmgr_parent(jobmgr_t jm) { @@ -3424,25 +3360,33 @@ } jobmgr_t -jobmgr_new(jobmgr_t jm, mach_port_t requestorport, mach_port_t checkin_port) +jobmgr_new(jobmgr_t jm, mach_port_t requestorport, mach_port_t transfer_port, bool sflag) { + const char *bootstrap_tool[] = { "/bin/launchctl", "bootstrap", NULL, NULL }; mach_msg_size_t mxmsgsz; + job_t bootstrapper = NULL; jobmgr_t jmr; - if (requestorport == MACH_PORT_NULL) { - if (jm) { - jobmgr_log(jm, LOG_ERR, "Mach sub-bootstrap create request requires a requester port"); - } + if (sflag) { + bootstrap_tool[2] = "-s"; + } + + launchd_assert(offsetof(struct jobmgr_s, kqjobmgr_callback) == 0); + + if (jm && requestorport == MACH_PORT_NULL) { + jobmgr_log(jm, LOG_ERR, "Mach sub-bootstrap create request requires a requester port"); return NULL; } - jmr = calloc(1, sizeof(struct jobmgr_s) + strlen("LoginWindow") + 1); + jmr = calloc(1, sizeof(struct jobmgr_s) + 30); if (jmr == NULL) { return NULL; } TAILQ_INIT(&jmr->jobs); + jmr->kqjobmgr_callback = jobmgr_callback; + strcpy(jmr->name, "In-utero"); jmr->req_port = requestorport; @@ -3450,17 +3394,44 @@ SLIST_INSERT_HEAD(&jm->submgrs, jmr, sle); } - if (!jobmgr_assumes(jmr, launchd_mport_notify_req(jmr->req_port, MACH_NOTIFY_DEAD_NAME) == KERN_SUCCESS)) { + if (jm && !jobmgr_assumes(jmr, launchd_mport_notify_req(jmr->req_port, MACH_NOTIFY_DEAD_NAME) == KERN_SUCCESS)) { goto out_bad; } - if (checkin_port != MACH_PORT_NULL) { - jmr->jm_port = checkin_port; + if (transfer_port != MACH_PORT_NULL) { + jobmgr_assumes(jmr, jm != NULL); + jmr->jm_port = transfer_port; + } else if (!jm && getpid() != 1) { + char *trusted_fd = getenv(LAUNCHD_TRUSTED_FD_ENV); + name_t service_buf; + + snprintf(service_buf, sizeof(service_buf), "com.apple.launchd.peruser.%u", getuid()); + + if (!jobmgr_assumes(jmr, bootstrap_check_in(bootstrap_port, service_buf, &jmr->jm_port) == 0)) { + goto out_bad; + } + + if (trusted_fd) { + int dfd, lfd = strtol(trusted_fd, NULL, 10); + + if ((dfd = dup(lfd)) >= 0) { + jobmgr_assumes(jmr, close(dfd) != -1); + jobmgr_assumes(jmr, close(lfd) != -1); + } + + unsetenv(LAUNCHD_TRUSTED_FD_ENV); + } + + inherited_bootstrap_port = bootstrap_port; + /* cut off the Libc cache, we don't want to deadlock against ourself */ + bootstrap_port = MACH_PORT_NULL; + /* We set this explicitly as we start each child */ + launchd_assert(launchd_set_bport(MACH_PORT_NULL) == KERN_SUCCESS); } else if (!jobmgr_assumes(jmr, launchd_mport_create_recv(&jmr->jm_port) == KERN_SUCCESS)) { goto out_bad; } - snprintf(jmr->name, strlen(jmr->name) + 1, "%u", MACH_PORT_INDEX(jmr->jm_port)); + sprintf(jmr->name, "%u", MACH_PORT_INDEX(jmr->jm_port)); /* Sigh... at the moment, MIG has maxsize == sizeof(reply union) */ mxmsgsz = sizeof(union __RequestUnion__job_mig_protocol_vproc_subsystem); @@ -3472,16 +3443,20 @@ goto out_bad; } - if (jm) { - jobmgr_log(jm, LOG_DEBUG, "Mach sub-bootstrap created: %s", jmr->name); - } + jobmgr_assumes(jmr, (jmr->anonj = jobmgr_new_anonymous(jmr)) != NULL); - jmr->anonj = jobmgr_new_anonymous(jmr); + bootstrapper = job_new(jmr, "com.apple.launchctld", NULL, bootstrap_tool); - jobmgr_assumes(jmr, jmr->anonj != NULL); + if (!jm) { + jobmgr_assumes(jmr, kevent_mod(SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, jmr) != -1); + } - jobmgr_log(jmr, LOG_DEBUG, "Created job manager"); + jobmgr_log(jmr, LOG_DEBUG, "Created job manager%s%s", jm ? " with parent: " : ".", jm ? jm->name : ""); + if (!jm && jobmgr_assumes(jmr, bootstrapper != NULL)) { + jobmgr_assumes(jmr, job_dispatch(bootstrapper, true) != NULL); + } + return jmr; out_bad: @@ -3759,9 +3734,11 @@ } snprintf(pidstr, sizeof(pidstr), "%u", j->p); - snprintf(logfile, sizeof(logfile), "/var/log/shutdown/%s-%u.sample.txt", j->label, j->p); + snprintf(logfile, sizeof(logfile), SHUTDOWN_LOG_DIR "/%s-%u.sample.txt", j->label, j->p); - job_assumes(j, mkdir("/var/log/shutdown", S_IRWXU) != -1 || errno == EEXIST); + if (!job_assumes(j, unlink(logfile) != -1 || errno == ENOENT)) { + goto out; + } /* * This will stall launchd for as long as the 'sample' tool runs. @@ -3777,6 +3754,8 @@ goto out; } + sync(); + if (!job_assumes(j, WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == 0)) { goto out; } @@ -4194,7 +4173,7 @@ return BOOTSTRAP_NO_MEMORY; } - ipc_server_init(NULL, 0); + ipc_server_init(); if (!sockpath) { return BOOTSTRAP_NO_MEMORY; @@ -4262,7 +4241,7 @@ sprintf(lbuf, "com.apple.launchd.peruser.%u", which_user); - ji = job_new(root_jobmgr, lbuf, "/sbin/launchd", NULL, NULL); + ji = job_new(root_jobmgr, lbuf, "/sbin/launchd", NULL); if (ji == NULL) { return BOOTSTRAP_NO_MEMORY; @@ -4562,7 +4541,7 @@ launchd_assert(l2l_name_cnt == l2l_port_cnt); - if ((jmr = jobmgr_new(j->mgr, reqport, rcvright)) == NULL) { + if ((jmr = jobmgr_new(j->mgr, reqport, rcvright, false)) == NULL) { kr = BOOTSTRAP_NO_MEMORY; goto out; } @@ -4691,7 +4670,7 @@ return BOOTSTRAP_NO_MEMORY; } - if ((jmr = jobmgr_new(j->mgr, requestorport, MACH_PORT_NULL)) == NULL) { + if ((jmr = jobmgr_new(j->mgr, requestorport, MACH_PORT_NULL, false)) == NULL) { if (requestorport == MACH_PORT_NULL) { return BOOTSTRAP_NOT_PRIVILEGED; } @@ -4864,30 +4843,7 @@ } void -mach_init_init(mach_port_t checkin_port) +jobmgr_init(bool sflag) { - job_t ji, anon_job = NULL; - - launchd_assert((root_jobmgr = jobmgr_new(NULL, mach_task_self(), checkin_port)) != NULL); - - TAILQ_FOREACH(ji, &root_jobmgr->jobs, sle) { - if (ji->anonymous) { - anon_job = ji; - break; - } - } - - launchd_assert(anon_job != NULL); - - launchd_assert(launchd_get_bport(&inherited_bootstrap_port) == KERN_SUCCESS); - - if (getpid() != 1) { - launchd_assumes(inherited_bootstrap_port != MACH_PORT_NULL); - } - - /* We set this explicitly as we start each child */ - launchd_assert(launchd_set_bport(MACH_PORT_NULL) == KERN_SUCCESS); - - /* cut off the Libc cache, we don't want to deadlock against ourself */ - bootstrap_port = MACH_PORT_NULL; + launchd_assert((root_jobmgr = jobmgr_new(NULL, MACH_PORT_NULL, MACH_PORT_NULL, sflag)) != NULL); } Modified: trunk/launchd/src/launchd_core_logic.h =================================================================== --- trunk/launchd/src/launchd_core_logic.h 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/launchd_core_logic.h 2007-02-19 02:03:20 UTC (rev 23082) @@ -28,8 +28,7 @@ extern jobmgr_t root_jobmgr; -void jobmgr_set_stdout(jobmgr_t jm, const char *what); -void jobmgr_set_stderr(jobmgr_t jm, const char *what); +void jobmgr_init(bool); jobmgr_t jobmgr_shutdown(jobmgr_t jm); void jobmgr_dispatch_all_semaphores(jobmgr_t jm); job_t jobmgr_find(jobmgr_t jm, const char *label); @@ -39,7 +38,6 @@ launch_data_t job_export_all(void); -job_t job_new(jobmgr_t jm, const char *label, const char *prog, const char *const *argv, const char *stdinpath); job_t job_dispatch(job_t j, bool kickstart); /* returns j on success, NULL on job removal */ bool job_active(job_t j); launch_data_t job_export(job_t j); Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/launchd_runtime.c 2007-02-19 02:03:20 UTC (rev 23082) @@ -73,6 +73,7 @@ static void *mport_demand_loop(void *arg); static void *kqueue_demand_loop(void *arg); +static void log_kevent_struct(int level, struct kevent *kev); static void async_callback(void); static kq_callback kqasync_callback = (kq_callback)async_callback; @@ -143,7 +144,51 @@ return NULL; } -static void +const char * +signal_to_C_name(unsigned int sig) +{ + static char unknown[25]; + +#define SIG2CASE(sg) case sg: return #sg + + switch (sig) { + SIG2CASE(SIGHUP); + SIG2CASE(SIGINT); + SIG2CASE(SIGQUIT); + SIG2CASE(SIGILL); + SIG2CASE(SIGTRAP); + SIG2CASE(SIGABRT); + SIG2CASE(SIGFPE); + SIG2CASE(SIGKILL); + SIG2CASE(SIGBUS); + SIG2CASE(SIGSEGV); + SIG2CASE(SIGSYS); + SIG2CASE(SIGPIPE); + SIG2CASE(SIGALRM); + SIG2CASE(SIGTERM); + SIG2CASE(SIGURG); + SIG2CASE(SIGSTOP); + SIG2CASE(SIGTSTP); + SIG2CASE(SIGCONT); + SIG2CASE(SIGCHLD); + SIG2CASE(SIGTTIN); + SIG2CASE(SIGTTOU); + SIG2CASE(SIGIO); + SIG2CASE(SIGXCPU); + SIG2CASE(SIGXFSZ); + SIG2CASE(SIGVTALRM); + SIG2CASE(SIGPROF); + SIG2CASE(SIGWINCH); + SIG2CASE(SIGINFO); + SIG2CASE(SIGUSR1); + SIG2CASE(SIGUSR2); + default: + snprintf(unknown, sizeof(unknown), "%u", sig); + return unknown; + } +} + +void log_kevent_struct(int level, struct kevent *kev) { const char *filter_str; @@ -245,42 +290,7 @@ break; case EVFILT_SIGNAL: filter_str = "EVFILT_SIGNAL"; - switch (kev->ident) { -#define SIG2CASE(sg) case sg: sprintf(ident_buf, #sg); break - SIG2CASE(SIGHUP); - SIG2CASE(SIGINT); - SIG2CASE(SIGQUIT); - SIG2CASE(SIGILL); - SIG2CASE(SIGTRAP); - SIG2CASE(SIGABRT); - SIG2CASE(SIGFPE); - SIG2CASE(SIGKILL); - SIG2CASE(SIGBUS); - SIG2CASE(SIGSEGV); - SIG2CASE(SIGSYS); - SIG2CASE(SIGPIPE); - SIG2CASE(SIGALRM); - SIG2CASE(SIGTERM); - SIG2CASE(SIGURG); - SIG2CASE(SIGSTOP); - SIG2CASE(SIGTSTP); - SIG2CASE(SIGCONT); - SIG2CASE(SIGCHLD); - SIG2CASE(SIGTTIN); - SIG2CASE(SIGTTOU); - SIG2CASE(SIGIO); - SIG2CASE(SIGXCPU); - SIG2CASE(SIGXFSZ); - SIG2CASE(SIGVTALRM); - SIG2CASE(SIGPROF); - SIG2CASE(SIGWINCH); - SIG2CASE(SIGINFO); - SIG2CASE(SIGUSR1); - SIG2CASE(SIGUSR2); - default: - sprintf(ident_buf, "%ld", kev->ident); - break; - } + strcpy(ident_buf, signal_to_C_name(kev->ident)); break; case EVFILT_TIMER: filter_str = "EVFILT_TIMER"; @@ -404,8 +414,6 @@ #endif } - launchd_post_kevent(); - return 0; } Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/launchd_runtime.h 2007-02-19 02:03:20 UTC (rev 23082) @@ -45,7 +45,7 @@ #define launchd_blame(e, b) \ (__builtin_expect(!(e), 0) ? syslog(LOG_DEBUG, "Encountered bug: %d", b), false : true) -#define launchd_assert(e) launchd_assumes(e) ? true : abort(); +#define launchd_assert(e) if (__builtin_constant_p(e)) { char __compile_time_assert__[e ? 1 : -1] __attribute__((unused)); } else if (!launchd_assumes(e)) { abort(); } void _log_launchd_bug(const char *rcs_rev, const char *path, unsigned int line, const char *test); @@ -64,6 +64,7 @@ kern_return_t runtime_remove_mport(mach_port_t name); bool runtime_get_caller_creds(struct ldcred *ldc); +const char *signal_to_C_name(unsigned int sig); int kevent_mod(uintptr_t ident, short filter, u_short flags, u_int fflags, intptr_t data, void *udata); Modified: trunk/launchd/src/launchd_unix_ipc.c =================================================================== --- trunk/launchd/src/launchd_unix_ipc.c 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/launchd_unix_ipc.c 2007-02-19 02:03:20 UTC (rev 23082) @@ -88,22 +88,17 @@ } void -ipc_server_init(int *fds, size_t fd_cnt) +ipc_server_init(void) { struct sockaddr_un sun; mode_t oldmask; int r, fd = -1; char ourdir[1024]; - size_t i; if (ipc_inited) { return; } - if (fds) { - goto add_fds; - } - memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; @@ -163,27 +158,17 @@ goto out_bad; } -add_fds: - if (fds) { - for (i = 0; i < fd_cnt; i++) { - if (kevent_mod(fds[i], EVFILT_READ, EV_ADD, 0, 0, &kqipc_listen_callback) == -1) { - syslog(LOG_ERR, "kevent_mod(%d, EVFILT_READ): %m", fds[i]); - goto out_bad; - } - } - } else if (kevent_mod(fd, EVFILT_READ, EV_ADD, 0, 0, &kqipc_listen_callback) == -1) { + if (kevent_mod(fd, EVFILT_READ, EV_ADD, 0, 0, &kqipc_listen_callback) == -1) { syslog(LOG_ERR, "kevent_mod(\"thesocket\", EVFILT_READ): %m"); goto out_bad; } ipc_inited = true; - if (!fds) { - sockdir = strdup(ourdir); - sockpath = strdup(sun.sun_path); - ipc_self = getpid(); - atexit(ipc_clean_up); - } + sockdir = strdup(ourdir); + sockpath = strdup(sun.sun_path); + ipc_self = getpid(); + atexit(ipc_clean_up); out_bad: if (!ipc_inited && fd != -1) { @@ -446,10 +431,6 @@ 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_SETSTDOUT)) { - resp = launchd_setstdio(STDOUT_FILENO, data); - } else if (!strcmp(cmd, LAUNCH_KEY_SETSTDERR)) { - resp = launchd_setstdio(STDERR_FILENO, 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/launchd_unix_ipc.h =================================================================== --- trunk/launchd/src/launchd_unix_ipc.h 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/launchd_unix_ipc.h 2007-02-19 02:03:20 UTC (rev 23082) @@ -43,6 +43,6 @@ void ipc_revoke_fds(launch_data_t o); void ipc_close_fds(launch_data_t o); void ipc_clean_up(void); -void ipc_server_init(int *, size_t); +void ipc_server_init(void); #endif Modified: trunk/launchd/src/liblaunch_private.h =================================================================== --- trunk/launchd/src/liblaunch_private.h 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/liblaunch_private.h 2007-02-19 02:03:20 UTC (rev 23082) @@ -31,8 +31,6 @@ #define LAUNCH_KEY_GETUSERENVIRONMENT "GetUserEnvironment" #define LAUNCH_KEY_SETUSERENVIRONMENT "SetUserEnvironment" #define LAUNCH_KEY_UNSETUSERENVIRONMENT "UnsetUserEnvironment" -#define LAUNCH_KEY_SETSTDOUT "SetStandardOut" -#define LAUNCH_KEY_SETSTDERR "SetStandardError" #define LAUNCH_KEY_SHUTDOWN "Shutdown" #define LAUNCH_KEY_SINGLEUSER "SingleUser" #define LAUNCH_KEY_GETRESOURCELIMITS "GetResourceLimits" @@ -76,7 +74,7 @@ * 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, ...); +pid_t create_and_switch_to_per_session_launchd(const char * /* loginname */, int flags, ...); /* Also for LoginWindow. * Modified: trunk/launchd/src/libvproc_public.h =================================================================== --- trunk/launchd/src/libvproc_public.h 2007-02-18 18:48:19 UTC (rev 23081) +++ trunk/launchd/src/libvproc_public.h 2007-02-19 02:03:20 UTC (rev 23082) @@ -26,60 +26,11 @@ typedef void * vproc_err_t; -#if 0 - typedef void * vproc_t; typedef void * vprocmgr_t; -/* By default, pass NULL for vprocmgr_t or vproc_t to get notions of self or "my manager" */ - -vproc_err_t vprocmgr_create_vproc(vprocmgr_t vpm, launch_data_t the_vproc, vproc_t *vp); - -/* If creating multiple jobs, it is wise to create them atomically with respect to each other */ -vproc_err_t vprocmgr_create_vprocs(vprocmgr_t vpm, launch_data_t *the_vprocs, vproc_t *vp, size_t cnt); - -vproc_err_t vprocmgr_delete_vproc(vprocmgr_t vpm, vproc_t vp); - -/* The virtual process managers are arranged in a hierarchy */ -vproc_err_t vprocmgr_get_parent(vprocmgr_t vpm, vprocmgr_t *vpm_parent); - -vproc_err_t vprocmgr_get_all_vprocs(vprocmgr_t vpm, vproc_t **vps, size_t *vp_cnt); - -vproc_err_t vprocmgr_lookup_vproc(vprocmgr_t vpm, const char *label, vproc_t *vp); - -vproc_err_t vprocmgr_lookup_vprocmgr_for_user(vprocmgr_t vpm, const char *user, vprocmgr_t *vpm_out); - -vproc_err_t vprocmgr_lookup_mach_service(vprocmgr_t vpm, const char *service, mach_port_t *service_port); - -/* For controlling speculative and optimistical spawning of vprocs */ -vproc_err_t vprocmgr_set_force_on_demand(vproc_mgr_t vpm, bool force); -vproc_err_t vprocmgr_get_force_on_demand(vproc_mgr_t vpm, bool *force); - -/* Only release those vprocmgr_t objects that returned from APIs. */ -vproc_err_t vprocmgr_release(vprocmgr_t vpm); - - -/* Get meta-data and IPC handles from launchd */ -vproc_err_t vproc_checkin(launch_data_t *out); - -/* Get only meta-data from launchd */ -vproc_err_t vproc_get_info(vproc_t vp, launch_data_t *out); - -/* Lookup a Mach service amongst our peers and progenitors */ -vproc_err_t vproc_lookup_mach_service(vproc_t vp, const char *service, mach_port_t *service_port); - -/* Sending signals to a program that isn't running will return an error */ -vproc_err_t vproc_send_signal(vproc_t vp, int signum); - -/* Only release those vproc_t objects that returned from APIs. */ -vproc_err_t vproc_release(vproc_t vp); - - - const char *vproc_strerror(vproc_err_t r); -#endif - __END_DECLS #endif -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070218/47eb16e6/attachment.html From source_changes at macosforge.org Sun Feb 18 21:17:07 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23083] trunk/launchd/src/launchd_runtime.c Message-ID: <20070219051707.E10C54AEF30@cvs.opensource.apple.com> Revision: 23083 http://trac.macosforge.org/projects/launchd/changeset/23083 Author: zarzycki@apple.com Date: 2007-02-18 21:17:07 -0800 (Sun, 18 Feb 2007) Log Message: ----------- More kqueue debug decoding. Modified Paths: -------------- trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-19 02:03:20 UTC (rev 23082) +++ trunk/launchd/src/launchd_runtime.c 2007-02-19 05:17:07 UTC (rev 23083) @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -320,6 +321,30 @@ break; case EVFILT_FS: filter_str = "EVFILT_FS"; + snprintf(ident_buf, sizeof(ident_buf), "0x%lx", kev->ident); + if (fflags) while (fflags) { + if (fflags_off) { + *fflags_off = '|'; + fflags_off++; + *fflags_off = '\0'; + } else { + fflags_off = fflags_buf; + } + + FFLAGIF(VQ_NOTRESP) + else FFLAGIF(VQ_NEEDAUTH) + else FFLAGIF(VQ_LOWDISK) + else FFLAGIF(VQ_MOUNT) + else FFLAGIF(VQ_UNMOUNT) + else FFLAGIF(VQ_DEAD) + else FFLAGIF(VQ_ASSIST) + else FFLAGIF(VQ_NOTRESPLOCK) + else FFLAGIF(VQ_UPDATE) + else { + fflags_off += sprintf(fflags_off, "0x%x", fflags); + fflags = 0; + } + } break; default: snprintf(filter_buf, sizeof(filter_buf), "%d", kev->filter); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070218/60be0850/attachment.html From source_changes at macosforge.org Sun Feb 18 23:32:53 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23084] trunk/launchd/src Message-ID: <20070219073253.34A104AF0EB@cvs.opensource.apple.com> Revision: 23084 http://trac.macosforge.org/projects/launchd/changeset/23084 Author: zarzycki@apple.com Date: 2007-02-18 23:32:51 -0800 (Sun, 18 Feb 2007) Log Message: ----------- More debugging. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_core_logic.h trunk/launchd/src/launchd_unix_ipc.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-19 05:17:07 UTC (rev 23083) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-19 07:32:51 UTC (rev 23084) @@ -318,7 +318,6 @@ 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))); static void job_log_bug(job_t j, const char *rcs_rev, const char *path, unsigned int line, const char *test); static kern_return_t job_handle_mpm_wait(job_t j, mach_port_t srp, int *waitstatus); Modified: trunk/launchd/src/launchd_core_logic.h =================================================================== --- trunk/launchd/src/launchd_core_logic.h 2007-02-19 05:17:07 UTC (rev 23083) +++ trunk/launchd/src/launchd_core_logic.h 2007-02-19 07:32:51 UTC (rev 23084) @@ -49,5 +49,6 @@ job_t job_mig_intran(mach_port_t mp); void job_mig_destructor(job_t j); void job_ack_no_senders(job_t j); +void job_log(job_t j, int pri, const char *msg, ...) __attribute__((format(printf, 3, 4))); #endif Modified: trunk/launchd/src/launchd_unix_ipc.c =================================================================== --- trunk/launchd/src/launchd_unix_ipc.c 2007-02-19 05:17:07 UTC (rev 23083) +++ trunk/launchd/src/launchd_unix_ipc.c 2007-02-19 07:32:51 UTC (rev 23084) @@ -329,6 +329,12 @@ return; } + if (rmc->c->j) { + job_log(rmc->c->j, LOG_DEBUG, "Unix IPC request: %s", cmd); + } else { + syslog(LOG_DEBUG, "Unix IPC request: %s", cmd); + } + if (data == NULL) { if (!strcmp(cmd, LAUNCH_KEY_CHECKIN)) { if (rmc->c->j) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070218/6bb3de5a/attachment.html From source_changes at macosforge.org Mon Feb 19 09:37:12 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23085] trunk/launchd/src/launchctl.c Message-ID: <20070219173712.C56C24AFA19@cvs.opensource.apple.com> Revision: 23085 http://trac.macosforge.org/projects/launchd/changeset/23085 Author: zarzycki@apple.com Date: 2007-02-19 09:37:12 -0800 (Mon, 19 Feb 2007) Log Message: ----------- launchctl: Missing key "LimitLoadToSessionType", defaulting value to "Aqua" Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-02-19 07:32:51 UTC (rev 23084) +++ trunk/launchd/src/launchctl.c 2007-02-19 17:37:12 UTC (rev 23085) @@ -537,8 +537,6 @@ } if (lus->session_type && !(tmpa = launch_data_dict_lookup(thejob, LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE))) { - fprintf(stderr, "%s: Missing key \"%s\", defaulting value to \"Aqua\"\n", getprogname(), - LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE); tmpa = launch_data_new_string("Aqua"); launch_data_dict_insert(thejob, tmpa, LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070219/d89962c8/attachment.html From source_changes at macosforge.org Mon Feb 19 10:04:45 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23086] trunk/launchd/src/launchctl.c Message-ID: <20070219180445.9EB9F4AFA91@cvs.opensource.apple.com> Revision: 23086 http://trac.macosforge.org/projects/launchd/changeset/23086 Author: zarzycki@apple.com Date: 2007-02-19 10:04:45 -0800 (Mon, 19 Feb 2007) Log Message: ----------- launchd to terminate BootCache directly Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-02-19 17:37:12 UTC (rev 23085) +++ trunk/launchd/src/launchctl.c 2007-02-19 18:04:45 UTC (rev 23086) @@ -1239,11 +1239,14 @@ static void very_pid2_specific_bootstrap(bool sflag) { + struct timeval tvs, tve, tvd; int hnmib[] = { CTL_KERN, KERN_HOSTNAME }; struct group *tfp_gr; do_single_user_mode(sflag); + assumes(gettimeofday(&tvs, NULL) != -1); + 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; @@ -1335,6 +1338,20 @@ do_bootroot_magic(); _vproc_set_global_on_demand(false); + + assumes(gettimeofday(&tve, NULL) != -1); + + timersub(&tve, &tvs, &tvd); + + if (!path_check("/System/Library/LoginPlugins/BootCache.loginPlugin")) { + int remaining_sec = 60 - tvd.tv_sec; + if (remaining_sec > 0) { + sleep(remaining_sec); + } + + const char *bcc_stop_tool[] = { "BootCacheControl", "stop", NULL }; + assumes(fwexec(bcc_stop_tool, true) != -1); + } } int -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070219/b6f27fa6/attachment.html From source_changes at macosforge.org Mon Feb 19 15:21:02 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23087] trunk/launchd/src Message-ID: <20070219232102.776224AFF40@cvs.opensource.apple.com> Revision: 23087 http://trac.macosforge.org/projects/launchd/changeset/23087 Author: zarzycki@apple.com Date: 2007-02-19 15:21:02 -0800 (Mon, 19 Feb 2007) Log Message: ----------- More debugging goo. Modified Paths: -------------- trunk/launchd/src/launchd.c trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c trunk/launchd/src/launchd_runtime.h trunk/launchd/src/launchd_unix_ipc.c trunk/launchd/src/liblaunch_private.h Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-02-19 18:04:45 UTC (rev 23086) +++ trunk/launchd/src/launchd.c 2007-02-19 23:21:02 UTC (rev 23087) @@ -50,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -137,9 +136,6 @@ launchd_runtime_init(); - openlog(getprogname(), LOG_PID|LOG_CONS, LOG_LAUNCHD); - setlogmask(LOG_UPTO(/* LOG_DEBUG */ LOG_NOTICE)); - for (i = 0; i < (sizeof(sigigns) / sizeof(int)); i++) { launchd_assumes(signal(sigigns[i], SIG_IGN) != SIG_ERR); } @@ -217,7 +213,7 @@ doom_why = "trying to read/write"; case SIGILL: case SIGFPE: - syslog(LOG_EMERG, "We crashed %s: %p (sent by PID %u)", doom_why, crash_addr, crash_pid); + runtime_syslog(LOG_EMERG, "We crashed %s: %p (sent by PID %u)", doom_why, crash_addr, crash_pid); sync(); sleep(3); /* the kernel will panic() when PID 1 exits */ @@ -280,7 +276,7 @@ void launchd_single_user(void) { - syslog(LOG_NOTICE, "Going to single-user mode"); + runtime_syslog(LOG_NOTICE, "Going to single-user mode"); re_exec_in_single_user_mode = true; @@ -314,7 +310,7 @@ launchd_assumes(close(tmpfd) == 0); } else { if (-1 == (tmpfd = open(path, flags | O_NOCTTY, DEFFILEMODE))) { - syslog(LOG_ERR, "open(\"%s\", ...): %m", path); + runtime_syslog(LOG_ERR, "open(\"%s\", ...): %m", path); } else if (tmpfd != fd) { launchd_assumes(dup2(tmpfd, fd) != -1); launchd_assumes(close(tmpfd) == 0); @@ -433,5 +429,5 @@ } } - syslog(LOG_NOTICE, "Bug: %s:%u (%s):%u: %s", file, line, buf, saved_errno, test); + runtime_syslog(LOG_NOTICE, "Bug: %s:%u (%s):%u: %s", file, line, buf, saved_errno, test); } Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-19 18:04:45 UTC (rev 23086) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-19 23:21:02 UTC (rev 23087) @@ -57,7 +57,6 @@ #include #include #include -#include #include #include #include @@ -225,7 +224,7 @@ static pid_t jobmgr_fork(jobmgr_t jm); static void jobmgr_setup_env_from_other_jobs(jobmgr_t jm); static struct machservice *jobmgr_lookup_service(jobmgr_t jm, const char *name, bool check_parent); -static void jobmgr_logv(jobmgr_t jm, int pri, int err, const char *msg, va_list ap); +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))); /* static void jobmgr_log_error(jobmgr_t jm, int pri, const char *msg, ...) __attribute__((format(printf, 3, 4))); */ static void jobmgr_log_bug(jobmgr_t jm, const char *rcs_rev, const char *path, unsigned int line, const char *test); @@ -274,7 +273,7 @@ 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, setnice:1, hopefully_exits_last:1, removal_pending:1, - wait4pipe_eof:1, sent_sigkill:1; + wait4pipe_eof:1, sent_sigkill:1, debug_before_kill:1; char label[0]; }; @@ -317,7 +316,7 @@ static void job_kill(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_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 kern_return_t job_handle_mpm_wait(job_t j, mach_port_t srp, int *waitstatus); @@ -536,6 +535,10 @@ } } + if (debug_shutdown_hangs && jm->parentmgr == NULL && getpid() == 1) { + jobmgr_assumes(jm, kevent_mod((uintptr_t)jm, EVFILT_TIMER, EV_ADD, NOTE_SECONDS, 3, jm) != -1); + } + return jobmgr_do_garbage_collection(jm); } @@ -577,8 +580,10 @@ if (jm->parentmgr) { SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); } else if (getpid() == 1) { + jobmgr_log(jm, LOG_DEBUG, "About to call reboot(0x%x).", jm->reboot_flags); jobmgr_assumes(jm, reboot(jm->reboot_flags) != -1); } else { + jobmgr_log(jm, LOG_DEBUG, "About to exit."); exit(EXIT_SUCCESS); } @@ -1081,6 +1086,8 @@ case 'E': if (strcasecmp(key, LAUNCH_JOBKEY_ENABLEGLOBBING) == 0) { j->globargv = value; + } else if (strcasecmp(key, LAUNCH_JOBKEY_ENTERKERNELDEBUGGERBEFOREKILL) == 0) { + j->debug_before_kill = value; } break; case 'w': @@ -1459,7 +1466,7 @@ return NULL; } else if (label[0] == '\0' || (strncasecmp(label, "", strlen("com.apple.launchd")) == 0) || (strtol(label, NULL, 10) != 0)) { - syslog(LOG_ERR, "Somebody attempted to use a reserved prefix for a label: %s", label); + jobmgr_log(root_jobmgr, LOG_ERR, "Somebody attempted to use a reserved prefix for a label: %s", label); /* the empty string, com.apple.launchd and number prefixes for labels are reserved */ errno = EINVAL; return NULL; @@ -1810,18 +1817,16 @@ } else if (&j->exit_timeout == ident) { if (j->sent_sigkill) { struct timeval tvd, tve; - double delta; job_assumes(j, gettimeofday(&tve, NULL) != -1); timersub(&tve, &j->sent_sigterm_time, &tvd); - delta = (double)tvd.tv_sec + (double)tvd.tv_usec / (double)1000000; - delta -= (double)j->exit_timeout; - job_log(j, LOG_ERR, "Did not die after sending SIGKILL %f seconds ago...", delta); - if (debug_shutdown_hangs && delta > 60) { + job_log(j, LOG_ERR, "Did not die after sending SIGKILL %lu seconds ago...", tvd.tv_sec); + } else { + job_force_sampletool(j); + if (j->debug_before_kill) { + job_log(j, LOG_NOTICE, "Exit timeout elapsed. Entering the kernel debugger."); job_assumes(j, host_reboot(mach_host_self(), HOST_REBOOT_DEBUGGER) == KERN_SUCCESS); } - } else { - job_force_sampletool(j); job_log(j, LOG_WARNING, "Exit timeout elapsed (%u seconds). Killing.", j->exit_timeout); job_kill(j); } @@ -1854,6 +1859,9 @@ return (void)jobmgr_assumes(jm, false); } break; + case EVFILT_TIMER: + jobmgr_log(jm, LOG_NOTICE, "Still alive with %u children.", total_children); + break; default: return (void)jobmgr_assumes(jm, false); } @@ -2512,7 +2520,7 @@ if (jm->parentmgr) { jobmgr_logv(jm->parentmgr, pri, 0, newmsg, ap); } else { - vsyslog(pri, newmsg, ap); + runtime_vsyslog(pri, newmsg, ap); } } @@ -3749,11 +3757,16 @@ goto out; } + job_log(j, LOG_DEBUG, "Waiting for 'sample' to finish."); + if (!job_assumes(j, waitpid(sp, &wstatus, 0) != -1)) { goto out; } - sync(); + /* + * This won't work if the VFS or filesystems are sick: + * sync(); + */ if (!job_assumes(j, WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == 0)) { goto out; @@ -3789,12 +3802,15 @@ } if (logfile_fd != -1) { + job_assumes(j, fcntl(logfile_fd, F_FULLFSYNC, 0) != -1); job_assumes(j, close(logfile_fd) != -1); } if (console_fd != -1) { job_assumes(j, close(console_fd) != -1); } + + job_log(j, LOG_DEBUG, "Finished sampling."); } bool Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-19 18:04:45 UTC (rev 23086) +++ trunk/launchd/src/launchd_runtime.c 2007-02-19 23:21:02 UTC (rev 23087) @@ -124,6 +124,9 @@ pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN); 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)); } void * @@ -352,7 +355,7 @@ break; } - syslog(level, "KEVENT: ident = %s filter = %s flags = %s fflags = %s data = 0x%x udata = %p", + runtime_syslog(level, "KEVENT: ident = %s filter = %s flags = %s fflags = %s data = 0x%lx udata = %p", ident_buf, filter_str, flags_buf, fflags_buf, kev->data, kev->udata); } @@ -849,70 +852,78 @@ } } -#if 0 - -/* For ugly debug scenarios where syslogd is long gone (for example, during system shutdown). */ - void -closelog(void) +runtime_openlog(const char *ident, int logopt, int facility) { + openlog(ident, logopt, facility); } -void -openlog(const char *ident, int logopt, int facility) -{ - ident = 0; - logopt = 0; - facility = 0; -} - int -setlogmask(int maskpri) +runtime_setlogmask(int maskpri) { - return maskpri; + return setlogmask(maskpri); } void -syslog(int priority, const char *message, ...) +runtime_syslog(int priority, const char *message, ...) { va_list ap; va_start(ap, message); - vsyslog(priority, message, ap); + runtime_vsyslog(priority, message, ap); va_end(ap); } void -vsyslog(int priority, const char *message, va_list args) +runtime_vsyslog(int priority, const char *message, va_list args) { static pthread_mutex_t ourlock = PTHREAD_MUTEX_INITIALIZER; static FILE *ourlogfile = NULL; + static struct timeval shutdown_start = { 0, 0 }; + struct timeval tvnow, tvd; int saved_errno = errno; char newmsg[10000]; + double float_time; size_t i, j; + if (!(debug_shutdown_hangs && getpid() == 1)) { + return vsyslog(priority, message, args); + } + + if (shutdown_start.tv_sec == 0) { + gettimeofday(&shutdown_start, NULL); + } + + if (gettimeofday(&tvnow, NULL) == -1) { + tvnow.tv_sec = 0; + tvnow.tv_usec = 0; + } + pthread_mutex_lock(&ourlock); if (ourlogfile == NULL) { - rename("/var/log/launchd_raw.log", "/var/log/launchd_raw-old.log"); - ourlogfile = fopen("/var/log/launchd_raw.log", "a"); - chmod("/var/log/launchd_raw.log", DEFFILEMODE); + rename("/var/log/launchd-shutdown.log", "/var/log/launchd-shutdown.log.1"); + ourlogfile = fopen("/var/log/launchd-shutdown.log", "a"); } pthread_mutex_unlock(&ourlock); if (ourlogfile == NULL) { - return; + syslog(LOG_ERR, "Couldn't open alternate log file!"); + return vsyslog(priority, message, args); } if (message == NULL) { return; } - snprintf(newmsg, sizeof(newmsg), "p%u pp%u\t", getpid(), getppid()); + timersub(&tvnow, &shutdown_start, &tvd); + float_time = (double)tvd.tv_sec + (double)tvd.tv_usec / (double)1000000; + snprintf(newmsg, sizeof(newmsg), "%f\t", float_time); + for (i = 0, j = strlen(newmsg); message[i];) { if (message[i] == '%' && message[i + 1] == 'm') { char *errs = strerror(saved_errno); @@ -932,5 +943,3 @@ fflush(ourlogfile); } - -#endif Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2007-02-19 18:04:45 UTC (rev 23086) +++ trunk/launchd/src/launchd_runtime.h 2007-02-19 23:21:02 UTC (rev 23087) @@ -24,6 +24,7 @@ #include #include #include +#include struct ldcred { uid_t euid; @@ -68,6 +69,12 @@ int kevent_mod(uintptr_t ident, short filter, u_short flags, u_int fflags, intptr_t data, void *udata); +void runtime_openlog(const char *ident, int logopt, int facility); +int runtime_setlogmask(int maskpri); +void runtime_syslog(int priority, const char *message, ...) __attribute__((format(printf, 2, 3))); +void runtime_vsyslog(int priority, const char *message, va_list args) __attribute__((format(printf, 2, 0))); + + kern_return_t launchd_set_bport(mach_port_t name); kern_return_t launchd_get_bport(mach_port_t *name); kern_return_t launchd_mport_notify_req(mach_port_t name, mach_msg_id_t which); Modified: trunk/launchd/src/launchd_unix_ipc.c =================================================================== --- trunk/launchd/src/launchd_unix_ipc.c 2007-02-19 18:04:45 UTC (rev 23086) +++ trunk/launchd/src/launchd_unix_ipc.c 2007-02-19 23:21:02 UTC (rev 23087) @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -81,9 +80,9 @@ } if (-1 == unlink(sockpath)) { - syslog(LOG_WARNING, "unlink(\"%s\"): %m", sockpath); + runtime_syslog(LOG_WARNING, "unlink(\"%s\"): %m", sockpath); } else if (-1 == rmdir(sockdir)) { - syslog(LOG_WARNING, "rmdir(\"%s\"): %m", sockdir); + runtime_syslog(LOG_WARNING, "rmdir(\"%s\"): %m", sockdir); } } @@ -115,11 +114,11 @@ stat(ourdir, &sb); if (!S_ISDIR(sb.st_mode)) { errno = EEXIST; - syslog(LOG_ERR, "mkdir(\"%s\"): %m", LAUNCHD_SOCK_PREFIX); + runtime_syslog(LOG_ERR, "mkdir(\"%s\"): %m", LAUNCHD_SOCK_PREFIX); goto out_bad; } } else { - syslog(LOG_ERR, "mkdir(\"%s\"): %m", ourdir); + runtime_syslog(LOG_ERR, "mkdir(\"%s\"): %m", ourdir); goto out_bad; } } @@ -133,7 +132,7 @@ if (unlink(sun.sun_path) == -1 && errno != ENOENT) { if (errno != EROFS) { - syslog(LOG_ERR, "unlink(\"thesocket\"): %m"); + runtime_syslog(LOG_ERR, "unlink(\"thesocket\"): %m"); } goto out_bad; } @@ -148,18 +147,18 @@ if (r == -1) { if (errno != EROFS) { - syslog(LOG_ERR, "bind(\"thesocket\"): %m"); + runtime_syslog(LOG_ERR, "bind(\"thesocket\"): %m"); } goto out_bad; } if (listen(fd, SOMAXCONN) == -1) { - syslog(LOG_ERR, "listen(\"thesocket\"): %m"); + runtime_syslog(LOG_ERR, "listen(\"thesocket\"): %m"); goto out_bad; } if (kevent_mod(fd, EVFILT_READ, EV_ADD, 0, 0, &kqipc_listen_callback) == -1) { - syslog(LOG_ERR, "kevent_mod(\"thesocket\", EVFILT_READ): %m"); + runtime_syslog(LOG_ERR, "kevent_mod(\"thesocket\", EVFILT_READ): %m"); goto out_bad; } @@ -213,7 +212,7 @@ if (kev->filter == EVFILT_READ) { if (launchd_msg_recv(c->conn, ipc_readmsg, c) == -1 && errno != EAGAIN) { if (errno != ECONNRESET) { - syslog(LOG_DEBUG, "%s(): recv: %m", __func__); + runtime_syslog(LOG_DEBUG, "%s(): recv: %m", __func__); } ipc_close(c); } @@ -221,14 +220,14 @@ r = launchd_msg_send(c->conn, NULL); if (r == -1) { if (errno != EAGAIN) { - syslog(LOG_DEBUG, "%s(): send: %m", __func__); + runtime_syslog(LOG_DEBUG, "%s(): send: %m", __func__); ipc_close(c); } } else if (r == 0) { kevent_mod(launchd_getfd(c->conn), EVFILT_WRITE, EV_DELETE, 0, 0, NULL); } } else { - syslog(LOG_DEBUG, "%s(): unknown filter type!", __func__); + runtime_syslog(LOG_DEBUG, "%s(): unknown filter type!", __func__); ipc_close(c); } } @@ -310,7 +309,7 @@ if (errno == EAGAIN) { kevent_mod(launchd_getfd(rmc.c->conn), EVFILT_WRITE, EV_ADD, 0, 0, &rmc.c->kqconn_callback); } else { - syslog(LOG_DEBUG, "launchd_msg_send() == -1: %m"); + runtime_syslog(LOG_DEBUG, "launchd_msg_send() == -1: %m"); ipc_close(rmc.c); } } @@ -332,7 +331,7 @@ if (rmc->c->j) { job_log(rmc->c->j, LOG_DEBUG, "Unix IPC request: %s", cmd); } else { - syslog(LOG_DEBUG, "Unix IPC request: %s", cmd); + runtime_syslog(LOG_DEBUG, "Unix IPC request: %s", cmd); } if (data == NULL) { @@ -471,7 +470,7 @@ ltmpsz = launch_data_get_opaque_size(in); if (ltmpsz > sizeof(l)) { - syslog(LOG_WARNING, "Too much rlimit data sent!"); + runtime_syslog(LOG_WARNING, "Too much rlimit data sent!"); ltmpsz = sizeof(l); } @@ -507,12 +506,12 @@ if (gval > 0) { launchd_assumes(sysctl(gmib, 2, NULL, NULL, &gval, sizeof(gval)) != -1); } else { - syslog(LOG_WARNING, "sysctl(\"%s\"): can't be zero", gstr); + runtime_syslog(LOG_WARNING, "sysctl(\"%s\"): can't be zero", gstr); } if (pval > 0) { launchd_assumes(sysctl(pmib, 2, NULL, NULL, &pval, sizeof(pval)) != -1); } else { - syslog(LOG_WARNING, "sysctl(\"%s\"): can't be zero", pstr); + runtime_syslog(LOG_WARNING, "sysctl(\"%s\"): can't be zero", pstr); } } launchd_assumes(setrlimit(i, ltmp + i) != -1); Modified: trunk/launchd/src/liblaunch_private.h =================================================================== --- trunk/launchd/src/liblaunch_private.h 2007-02-19 18:04:45 UTC (rev 23086) +++ trunk/launchd/src/liblaunch_private.h 2007-02-19 23:21:02 UTC (rev 23087) @@ -49,6 +49,8 @@ #define LAUNCH_KEY_BATCHCONTROL "BatchControl" #define LAUNCH_KEY_BATCHQUERY "BatchQuery" +#define LAUNCH_JOBKEY_ENTERKERNELDEBUGGERBEFOREKILL "EnterKernelDebuggerBeforeKill" + #define LAUNCH_JOBKEY_MACH_KUNCSERVER "kUNCServer" #define LAUNCH_JOBKEY_MACH_EXCEPTIONSERVER "ExceptionServer" #define LAUNCH_JOBKEY_MACH_TASKSPECIALPORT "TaskSpecialPort" -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070219/8195c155/attachment.html From source_changes at macosforge.org Mon Feb 19 15:21:44 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23088] tags/launchd-197/ Message-ID: <20070219232144.EA9E34AFF46@cvs.opensource.apple.com> Revision: 23088 http://trac.macosforge.org/projects/launchd/changeset/23088 Author: zarzycki@apple.com Date: 2007-02-19 15:21:44 -0800 (Mon, 19 Feb 2007) Log Message: ----------- "Tagging launchd-197 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-197/ Copied: tags/launchd-197 (from rev 23087, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070219/ff9c2997/attachment.html From source_changes at macosforge.org Mon Feb 19 19:02:31 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23089] trunk/launchd/src/rc.shutdown Message-ID: <20070220030231.22BB54B0412@cvs.opensource.apple.com> Revision: 23089 http://trac.macosforge.org/projects/launchd/changeset/23089 Author: zarzycki@apple.com Date: 2007-02-19 19:02:30 -0800 (Mon, 19 Feb 2007) Log Message: ----------- Dead code. Modified Paths: -------------- trunk/launchd/src/rc.shutdown Modified: trunk/launchd/src/rc.shutdown =================================================================== --- trunk/launchd/src/rc.shutdown 2007-02-19 23:21:44 UTC (rev 23088) +++ trunk/launchd/src/rc.shutdown 2007-02-20 03:02:30 UTC (rev 23089) @@ -7,8 +7,4 @@ sh /etc/rc.shutdown.local fi -SystemStarter stop - -kill -TERM 1 - -exit 0 +exec SystemStarter stop -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070219/94a051ed/attachment.html From source_changes at macosforge.org Mon Feb 19 19:03:53 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23090] tags/launchd-197.1/ Message-ID: <20070220030353.84F424B041E@cvs.opensource.apple.com> Revision: 23090 http://trac.macosforge.org/projects/launchd/changeset/23090 Author: zarzycki@apple.com Date: 2007-02-19 19:03:53 -0800 (Mon, 19 Feb 2007) Log Message: ----------- "Tagging launchd-197.1 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-197.1/ Copied: tags/launchd-197.1 (from rev 23089, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070219/bcced652/attachment.html From source_changes at macosforge.org Tue Feb 20 06:01:29 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23091] trunk/launchd/src Message-ID: <20070220140129.503B94B0E07@cvs.opensource.apple.com> Revision: 23091 http://trac.macosforge.org/projects/launchd/changeset/23091 Author: zarzycki@apple.com Date: 2007-02-20 06:01:28 -0800 (Tue, 20 Feb 2007) Log Message: ----------- More flag decoding. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c trunk/launchd/src/launchd_runtime.h Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-20 03:03:53 UTC (rev 23090) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-20 14:01:28 UTC (rev 23091) @@ -580,9 +580,12 @@ if (jm->parentmgr) { SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); } else if (getpid() == 1) { - jobmgr_log(jm, LOG_DEBUG, "About to call reboot(0x%x).", jm->reboot_flags); + jobmgr_log(jm, LOG_DEBUG, "About to call: reboot(%s)", reboot_flags_to_C_names(jm->reboot_flags)); + runtime_closelog(); jobmgr_assumes(jm, reboot(jm->reboot_flags) != -1); + runtime_closelog(); } else { + runtime_closelog(); jobmgr_log(jm, LOG_DEBUG, "About to exit."); exit(EXIT_SUCCESS); } Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-20 03:03:53 UTC (rev 23090) +++ trunk/launchd/src/launchd_runtime.c 2007-02-20 14:01:28 UTC (rev 23091) @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -149,6 +150,45 @@ } const char * +reboot_flags_to_C_names(unsigned int flags) +{ +#define MAX_RB_STR "RB_ASKNAME|RB_SINGLE|RB_NOSYNC|RB_KDB|RB_HALT|RB_INITNAME|RB_DFLTROOT|RB_ALTBOOT|RB_UNIPROC|RB_SAFEBOOT|RB_UPSDELAY|0xdeadbeeffeedface" + static char flags_buf[sizeof(MAX_RB_STR)]; + char *flags_off = NULL; + + if (flags) while (flags) { + if (flags_off) { + *flags_off = '|'; + flags_off++; + *flags_off = '\0'; + } else { + flags_off = flags_buf; + } + +#define FLAGIF(f) if (flags & f) { flags_off += sprintf(flags_off, #f); flags &= ~f; } + + FLAGIF(RB_ASKNAME) + else FLAGIF(RB_SINGLE) + else FLAGIF(RB_NOSYNC) + else FLAGIF(RB_KDB) + else FLAGIF(RB_HALT) + else FLAGIF(RB_INITNAME) + else FLAGIF(RB_DFLTROOT) + else FLAGIF(RB_ALTBOOT) + else FLAGIF(RB_UNIPROC) + else FLAGIF(RB_SAFEBOOT) + else FLAGIF(RB_UPSDELAY) + else { + flags_off += sprintf(flags_off, "0x%x", flags); + flags = 0; + } + return flags_buf; + } else { + return "RB_AUTOBOOT"; + } +} + +const char * signal_to_C_name(unsigned int sig) { static char unknown[25]; @@ -214,8 +254,6 @@ flags_off = flags_buf; } -#define FLAGIF(f) if (flags & f) { flags_off += sprintf(flags_off, #f); flags &= ~f; } - FLAGIF(EV_ADD) else FLAGIF(EV_DELETE) else FLAGIF(EV_ENABLE) @@ -852,12 +890,22 @@ } } +static FILE *ourlogfile; + void runtime_openlog(const char *ident, int logopt, int facility) { openlog(ident, logopt, facility); } +void +runtime_closelog(void) +{ + if (ourlogfile) { + fflush(ourlogfile); + } +} + int runtime_setlogmask(int maskpri) { @@ -880,7 +928,6 @@ runtime_vsyslog(int priority, const char *message, va_list args) { static pthread_mutex_t ourlock = PTHREAD_MUTEX_INITIALIZER; - static FILE *ourlogfile = NULL; static struct timeval shutdown_start = { 0, 0 }; struct timeval tvnow, tvd; int saved_errno = errno; @@ -940,6 +987,4 @@ strcpy(newmsg + j, "\n"); vfprintf(ourlogfile, newmsg, args); - - fflush(ourlogfile); } Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2007-02-20 03:03:53 UTC (rev 23090) +++ trunk/launchd/src/launchd_runtime.h 2007-02-20 14:01:28 UTC (rev 23091) @@ -66,10 +66,14 @@ bool runtime_get_caller_creds(struct ldcred *ldc); const char *signal_to_C_name(unsigned int sig); +const char *reboot_flags_to_C_names(unsigned int flags); + int kevent_mod(uintptr_t ident, short filter, u_short flags, u_int fflags, intptr_t data, void *udata); void runtime_openlog(const char *ident, int logopt, int facility); +void runtime_closelog(void); + int runtime_setlogmask(int maskpri); void runtime_syslog(int priority, const char *message, ...) __attribute__((format(printf, 2, 3))); void runtime_vsyslog(int priority, const char *message, va_list args) __attribute__((format(printf, 2, 0))); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070220/0b413eb3/attachment.html From source_changes at macosforge.org Tue Feb 20 08:57:12 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23092] trunk/launchd/src/launchd.c Message-ID: <20070220165712.46DD94B1140@cvs.opensource.apple.com> Revision: 23092 http://trac.macosforge.org/projects/launchd/changeset/23092 Author: zarzycki@apple.com Date: 2007-02-20 08:57:11 -0800 (Tue, 20 Feb 2007) Log Message: ----------- Workaround 4978696: getifaddrs() reports false ENOMEM Modified Paths: -------------- trunk/launchd/src/launchd.c Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-02-20 14:01:28 UTC (rev 23091) +++ trunk/launchd/src/launchd.c 2007-02-20 16:57:11 UTC (rev 23092) @@ -64,6 +64,7 @@ #include #include #include +#include #include "libbootstrap_public.h" #include "libvproc_public.h" @@ -341,8 +342,15 @@ { struct ifaddrs *ifa, *ifai; bool up = false; + int r; - if (!launchd_assumes(getifaddrs(&ifa) != -1)) { + /* Workaround 4978696: getifaddrs() reports false ENOMEM */ + while ((r = getifaddrs(&ifa)) == -1 && errno == ENOMEM) { + runtime_syslog(LOG_DEBUG, "Worked around bug: 4978696"); + launchd_assumes(sched_yield() != -1); + } + + if (!launchd_assumes(r != -1)) { return network_up; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070220/b4988062/attachment.html From source_changes at macosforge.org Tue Feb 20 10:15:14 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23093] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070220181514.4E2474B1296@cvs.opensource.apple.com> Revision: 23093 http://trac.macosforge.org/projects/launchd/changeset/23093 Author: zarzycki@apple.com Date: 2007-02-20 10:15:13 -0800 (Tue, 20 Feb 2007) Log Message: ----------- The kernel team requested that launchd not SIGKILL strays at shutdown (at least for Leopard). 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-02-20 16:57:11 UTC (rev 23092) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-20 18:15:13 UTC (rev 23093) @@ -3325,7 +3325,10 @@ } jobmgr_log(jm, LOG_WARNING, "Stray process at shutdown: PID %u PPID %u %s", p_i, pp_i, kp[i].kp_proc.p_comm); - jobmgr_assumes(jm, kill(p_i, SIGKILL) != -1); + /* + * The kernel team requested that I not do this for Leopard. + * jobmgr_assumes(jm, kill(p_i, SIGKILL) != -1); + */ } out: -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070220/7e38e98d/attachment.html From source_changes at macosforge.org Wed Feb 21 10:19:10 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:41 2007 Subject: [launchd-changes] [23094] trunk/launchd/src/launchd.c Message-ID: <20070221181910.873A24B295B@cvs.opensource.apple.com> Revision: 23094 http://trac.macosforge.org/projects/launchd/changeset/23094 Author: zarzycki@apple.com Date: 2007-02-21 10:19:10 -0800 (Wed, 21 Feb 2007) Log Message: ----------- It would be better if we just reboot. Modified Paths: -------------- trunk/launchd/src/launchd.c Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-02-20 18:15:13 UTC (rev 23093) +++ trunk/launchd/src/launchd.c 2007-02-21 18:19:10 UTC (rev 23094) @@ -217,11 +217,7 @@ runtime_syslog(LOG_EMERG, "We crashed %s: %p (sent by PID %u)", doom_why, crash_addr, crash_pid); sync(); sleep(3); - /* the kernel will panic() when PID 1 exits */ - _exit(EXIT_FAILURE); - /* we should never get here */ reboot(0); - /* or here either */ break; } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070221/ca42bb00/attachment.html From source_changes at macosforge.org Wed Feb 21 17:15:50 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23095] trunk/launchd/src/launchd.plist.5 Message-ID: <20070222011550.789FA4B3298@cvs.opensource.apple.com> Revision: 23095 http://trac.macosforge.org/projects/launchd/changeset/23095 Author: zarzycki@apple.com Date: 2007-02-21 17:15:50 -0800 (Wed, 21 Feb 2007) Log Message: ----------- nit: launchd.plist man page typo Modified Paths: -------------- trunk/launchd/src/launchd.plist.5 Modified: trunk/launchd/src/launchd.plist.5 =================================================================== --- trunk/launchd/src/launchd.plist.5 2007-02-21 18:19:10 UTC (rev 23094) +++ trunk/launchd/src/launchd.plist.5 2007-02-22 01:15:50 UTC (rev 23095) @@ -315,7 +315,7 @@ consider all descriptors of a given key to be to be effectively equivalent, even though each file descriptor likely represents a different networking protocol which conforms to the criteria specified in the job configuration file. .Pp -The paramters below are used as inputs to call +The parameters below are used as inputs to call .Xr getaddrinfo 3 . .Bl -ohang -offset indent .It Sy SockType -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070221/34301c7e/attachment.html From source_changes at macosforge.org Wed Feb 21 17:34:11 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23096] trunk/launchd/src/launchctl.c Message-ID: <20070222013411.ECEE54B32F8@cvs.opensource.apple.com> Revision: 23096 http://trac.macosforge.org/projects/launchd/changeset/23096 Author: zarzycki@apple.com Date: 2007-02-21 17:34:11 -0800 (Wed, 21 Feb 2007) Log Message: ----------- Workaround securityd not using kqueue to track execve() transitions Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-02-22 01:15:50 UTC (rev 23095) +++ trunk/launchd/src/launchctl.c 2007-02-22 01:34:11 UTC (rev 23096) @@ -2337,9 +2337,12 @@ setgid(getgid()); setuid(getuid()); - execvp(argv[2], argv + 2); - fprintf(stderr, "execvp(): %s\n", strerror(errno)); - return 1; + if (fwexec((const char *const *)argv + 2, true) == -1) { + fprintf(stderr, "%s bsexec failed: %s\n", getprogname(), strerror(errno)); + return 1; + } + + return 0; } int -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070221/e2cd1b7b/attachment.html From source_changes at macosforge.org Thu Feb 22 10:22:47 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23097] trunk/launchd/src Message-ID: <20070222182247.826854B40E3@cvs.opensource.apple.com> Revision: 23097 http://trac.macosforge.org/projects/launchd/changeset/23097 Author: zarzycki@apple.com Date: 2007-02-22 10:22:46 -0800 (Thu, 22 Feb 2007) Log Message: ----------- Step one of 4746572 (seatbelt stuff) Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/libbootstrap.c trunk/launchd/src/protocol_job.defs Added Paths: ----------- trunk/launchd/src/libbootstrap_private.h Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-02-22 01:34:11 UTC (rev 23096) +++ trunk/launchd/src/Makefile.am 2007-02-22 18:22:46 UTC (rev 23097) @@ -70,22 +70,23 @@ install-data-hook: mkdir -p $(DESTDIR)/usr/libexec + mkdir -p $(DESTDIR)/usr/include/servers + mkdir -p $(DESTDIR)/usr/local/include + mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init.d + mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init_per_user.d + mkdir -p $(DESTDIR)/Library/LaunchDaemons + mkdir -p $(DESTDIR)/Library/LaunchAgents + mkdir -p $(DESTDIR)/System/Library/LaunchAgents + mkdir -p $(DESTDIR)/System/Library/LaunchDaemons cp $(srcdir)/StartupItemContext $(DESTDIR)/usr/libexec - mkdir -p $(DESTDIR)/usr/include/servers cp $(srcdir)/liblaunch_public.h $(DESTDIR)/usr/include/launch.h cp $(srcdir)/libvproc_public.h $(DESTDIR)/usr/include/vproc.h cp $(srcdir)/libbootstrap_public.h $(DESTDIR)/usr/include/servers/bootstrap.h cp $(srcdir)/libbootstrap_public.h $(DESTDIR)/usr/include/servers/bootstrap_defs.h - mkdir -p $(DESTDIR)/usr/local/include + cp $(srcdir)/libbootstrap_private.h $(DESTDIR)/usr/local/include/bootstrap_priv.h cp $(srcdir)/liblaunch_private.h $(DESTDIR)/usr/local/include/launch_priv.h cp $(srcdir)/libvproc_private.h $(DESTDIR)/usr/local/include/vproc_priv.h cp $(srcdir)/reboot2.h $(DESTDIR)/usr/local/include/reboot2.h - mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init.d - mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init_per_user.d - mkdir -p $(DESTDIR)/Library/LaunchDaemons - mkdir -p $(DESTDIR)/Library/LaunchAgents - mkdir -p $(DESTDIR)/System/Library/LaunchAgents - mkdir -p $(DESTDIR)/System/Library/LaunchDaemons cp $(srcdir)/com.apple.SystemStarter.plist $(DESTDIR)/System/Library/LaunchDaemons endif Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-02-22 01:34:11 UTC (rev 23096) +++ trunk/launchd/src/Makefile.in 2007-02-22 18:22:46 UTC (rev 23097) @@ -1060,22 +1060,23 @@ @LIBS_ONLY_FALSE@install-data-hook: @LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/usr/libexec +@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/usr/include/servers +@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/usr/local/include +@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init.d +@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init_per_user.d +@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/Library/LaunchDaemons +@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/Library/LaunchAgents +@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/System/Library/LaunchAgents +@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/System/Library/LaunchDaemons @LIBS_ONLY_FALSE@ cp $(srcdir)/StartupItemContext $(DESTDIR)/usr/libexec -@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/usr/include/servers @LIBS_ONLY_FALSE@ cp $(srcdir)/liblaunch_public.h $(DESTDIR)/usr/include/launch.h @LIBS_ONLY_FALSE@ cp $(srcdir)/libvproc_public.h $(DESTDIR)/usr/include/vproc.h @LIBS_ONLY_FALSE@ cp $(srcdir)/libbootstrap_public.h $(DESTDIR)/usr/include/servers/bootstrap.h @LIBS_ONLY_FALSE@ cp $(srcdir)/libbootstrap_public.h $(DESTDIR)/usr/include/servers/bootstrap_defs.h -@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/usr/local/include +@LIBS_ONLY_FALSE@ cp $(srcdir)/libbootstrap_private.h $(DESTDIR)/usr/local/include/bootstrap_priv.h @LIBS_ONLY_FALSE@ cp $(srcdir)/liblaunch_private.h $(DESTDIR)/usr/local/include/launch_priv.h @LIBS_ONLY_FALSE@ cp $(srcdir)/libvproc_private.h $(DESTDIR)/usr/local/include/vproc_priv.h @LIBS_ONLY_FALSE@ cp $(srcdir)/reboot2.h $(DESTDIR)/usr/local/include/reboot2.h -@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init.d -@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/$(sysconfdir)/mach_init_per_user.d -@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/Library/LaunchDaemons -@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/Library/LaunchAgents -@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/System/Library/LaunchAgents -@LIBS_ONLY_FALSE@ mkdir -p $(DESTDIR)/System/Library/LaunchDaemons @LIBS_ONLY_FALSE@ cp $(srcdir)/com.apple.SystemStarter.plist $(DESTDIR)/System/Library/LaunchDaemons # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-22 01:34:11 UTC (rev 23096) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-22 18:22:46 UTC (rev 23097) @@ -76,6 +76,7 @@ #include "liblaunch_public.h" #include "liblaunch_private.h" #include "libbootstrap_public.h" +#include "libbootstrap_private.h" #include "libvproc_public.h" #include "libvproc_internal.h" @@ -101,14 +102,14 @@ SLIST_ENTRY(machservice) sle; job_t job; mach_port_name_t port; - unsigned int isActive:1, reset:1, recv:1, hide:1, kUNCServer:1, must_match_uid:1, debug_on_close:1; + unsigned int isActive:1, reset:1, recv:1, hide:1, kUNCServer:1, must_match_uid:1, debug_on_close:1, per_pid:1; char name[0]; }; static void machservice_setup(launch_data_t obj, const char *key, void *context); 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 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(struct machservice *); @@ -223,7 +224,7 @@ static void jobmgr_callback(void *obj, struct kevent *kev); static pid_t jobmgr_fork(jobmgr_t jm); static void jobmgr_setup_env_from_other_jobs(jobmgr_t jm); -static struct machservice *jobmgr_lookup_service(jobmgr_t jm, const char *name, bool check_parent); +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))); /* static void jobmgr_log_error(jobmgr_t jm, int pri, const char *msg, ...) __attribute__((format(printf, 3, 4))); */ @@ -3097,7 +3098,7 @@ } struct machservice * -machservice_new(job_t j, const char *name, mach_port_t *serviceport) +machservice_new(job_t j, const char *name, mach_port_t *serviceport, bool pid_local) { struct machservice *ms; @@ -3107,6 +3108,7 @@ strcpy(ms->name, name); ms->job = j; + ms->per_pid = pid_local; if (*serviceport == MACH_PORT_NULL) { if (!job_assumes(j, launchd_mport_create_recv(&ms->port) == KERN_SUCCESS)) { @@ -3236,12 +3238,12 @@ struct machservice *ms; mach_port_t p = MACH_PORT_NULL; - if ((ms = jobmgr_lookup_service(j->mgr, key, false))) { + if ((ms = jobmgr_lookup_service(j->mgr, key, false, 0))) { job_log(j, LOG_WARNING, "Conflict with job: %s over Mach service: %s", ms->job->label, key); return; } - if ((ms = machservice_new(j, key, &p)) == NULL) { + if ((ms = machservice_new(j, key, &p, false)) == NULL) { job_log_error(j, LOG_WARNING, "Cannot add service: %s", key); return; } @@ -3516,13 +3518,23 @@ } struct machservice * -jobmgr_lookup_service(jobmgr_t jm, const char *name, bool check_parent) +jobmgr_lookup_service(jobmgr_t jm, const char *name, bool check_parent, pid_t target_pid) { struct machservice *ms; job_t ji; + if (target_pid) { + jobmgr_assumes(jm, !check_parent); + } + TAILQ_FOREACH(ji, &jm->jobs, sle) { + if (target_pid && (ji->p != target_pid)) { + continue; + } SLIST_FOREACH(ms, &ji->machservices, sle) { + if (target_pid && !ms->per_pid) { + continue; + } if (strcmp(name, ms->name) == 0) { return ms; } @@ -3537,7 +3549,7 @@ return NULL; } - return jobmgr_lookup_service(jm->parentmgr, name, true); + return jobmgr_lookup_service(jm->parentmgr, name, true, 0); } mach_port_t @@ -4270,7 +4282,7 @@ ji->mach_uid = which_user; - if ((ms = machservice_new(ji, lbuf, up_cont)) == NULL) { + if ((ms = machservice_new(ji, lbuf, up_cont, false)) == NULL) { job_remove(ji); return BOOTSTRAP_NO_MEMORY; } @@ -4301,7 +4313,7 @@ runtime_get_caller_creds(&ldc); - ms = jobmgr_lookup_service(j->mgr, servicename, true); + ms = jobmgr_lookup_service(j->mgr, servicename, true, 0); if (ms == NULL) { job_log(j, LOG_DEBUG, "Check-in of Mach service failed. Unknown: %s", servicename); @@ -4329,7 +4341,7 @@ } kern_return_t -job_mig_register(job_t j, name_t servicename, mach_port_t serviceport) +job_mig_register2(job_t j, name_t servicename, mach_port_t serviceport, uint64_t flags) { struct machservice *ms; struct ldcred ldc; @@ -4344,7 +4356,7 @@ job_log(j, LOG_NOTICE, "bootstrap_register() is deprecated. PID: %u Service: %s", ldc.pid, servicename); #endif - job_log(j, LOG_DEBUG, "Mach service registration attempt: %s", servicename); + job_log(j, LOG_DEBUG, "%sMach service registration attempt: %s", flags & BOOTSTRAP_PER_PID_SERVICE ? "Per PID " : "", servicename); /* * From a per-user/session launchd's perspective, SecurityAgent (UID @@ -4359,7 +4371,7 @@ } } - ms = jobmgr_lookup_service(j->mgr, servicename, false); + ms = jobmgr_lookup_service(j->mgr, servicename, false, flags & BOOTSTRAP_PER_PID_SERVICE ? ldc.pid : 0); if (ms) { if (machservice_job(ms) != j) { @@ -4374,7 +4386,7 @@ } if (serviceport != MACH_PORT_NULL) { - if ((ms = machservice_new(j, servicename, &serviceport))) { + if ((ms = machservice_new(j, servicename, &serviceport, flags & BOOTSTRAP_PER_PID_SERVICE ? true : false))) { machservice_request_notifications(ms); } else { return BOOTSTRAP_NO_MEMORY; @@ -4385,7 +4397,7 @@ } kern_return_t -job_mig_look_up(job_t j, name_t servicename, mach_port_t *serviceportp, mach_msg_type_name_t *ptype) +job_mig_look_up2(job_t j, name_t servicename, mach_port_t *serviceportp, mach_msg_type_name_t *ptype, pid_t target_pid, uint64_t flags) { struct machservice *ms; struct ldcred ldc; @@ -4400,7 +4412,11 @@ return VPROC_ERR_TRY_PER_USER; } - ms = jobmgr_lookup_service(j->mgr, servicename, true); + if (flags & BOOTSTRAP_PER_PID_SERVICE) { + ms = jobmgr_lookup_service(j->mgr, servicename, false, target_pid); + } else { + ms = jobmgr_lookup_service(j->mgr, servicename, true, 0); + } if (ms && machservice_hidden(ms) && !job_active(machservice_job(ms))) { ms = NULL; @@ -4410,16 +4426,16 @@ if (ms) { launchd_assumes(machservice_port(ms) != MACH_PORT_NULL); - job_log(j, LOG_DEBUG, "Mach service lookup (by PID %d): %s", ldc.pid, servicename); + job_log(j, LOG_DEBUG, "%sMach service lookup (by PID %d): %s", flags & BOOTSTRAP_PER_PID_SERVICE ? "Per PID " : "", ldc.pid, servicename); *serviceportp = machservice_port(ms); *ptype = MACH_MSG_TYPE_COPY_SEND; return BOOTSTRAP_SUCCESS; - } else if (inherited_bootstrap_port != MACH_PORT_NULL) { + } else if (!(flags & BOOTSTRAP_PER_PID_SERVICE) && (inherited_bootstrap_port != MACH_PORT_NULL)) { job_log(j, LOG_DEBUG, "Mach service lookup (by PID %d) forwarded: %s", ldc.pid, servicename); *ptype = MACH_MSG_TYPE_MOVE_SEND; return bootstrap_look_up(inherited_bootstrap_port, servicename, serviceportp); } else { - job_log(j, LOG_DEBUG, "Mach service lookup (by PID %d) failed: %s", ldc.pid, servicename); + job_log(j, LOG_DEBUG, "%sMach service lookup (by PID %d) failed: %s", flags & BOOTSTRAP_PER_PID_SERVICE ? "Per PID " : "", ldc.pid, servicename); return BOOTSTRAP_UNKNOWN_SERVICE; } } @@ -4572,7 +4588,7 @@ for (l2l_i = 0; l2l_i < l2l_name_cnt; l2l_i++) { struct machservice *ms; - if ((ms = machservice_new(jmr->anonj, l2l_names[l2l_i], &l2l_ports[l2l_i]))) { + if ((ms = machservice_new(jmr->anonj, l2l_names[l2l_i], &l2l_ports[l2l_i], false))) { machservice_request_notifications(ms); } } @@ -4721,7 +4737,7 @@ return BOOTSTRAP_NOT_PRIVILEGED; } - ms = jobmgr_lookup_service(j->mgr, servicename, false); + ms = jobmgr_lookup_service(j->mgr, servicename, false, 0); if (ms) { job_log(j, LOG_DEBUG, "Mach service creation attempt for failed. Already exists: %s", servicename); return BOOTSTRAP_NAME_IN_USE; @@ -4730,7 +4746,7 @@ job_checkin(j); *serviceportp = MACH_PORT_NULL; - ms = machservice_new(j, servicename, serviceportp); + ms = machservice_new(j, servicename, serviceportp, false); if (!launchd_assumes(ms != NULL)) { goto out_bad; Modified: trunk/launchd/src/libbootstrap.c =================================================================== --- trunk/launchd/src/libbootstrap.c 2007-02-22 01:34:11 UTC (rev 23096) +++ trunk/launchd/src/libbootstrap.c 2007-02-22 18:22:46 UTC (rev 23097) @@ -20,6 +20,7 @@ #include "config.h" #include "libbootstrap_public.h" +#include "libbootstrap_private.h" #include "libvproc_public.h" #include "libvproc_private.h" @@ -66,13 +67,19 @@ kern_return_t bootstrap_register(mach_port_t bp, name_t service_name, mach_port_t sp) { - kern_return_t kr = vproc_mig_register(bp, service_name, sp); + return bootstrap_register2(bp, service_name, sp, 0); +} +kern_return_t +bootstrap_register2(mach_port_t bp, name_t service_name, mach_port_t sp, uint64_t flags) +{ + kern_return_t kr = vproc_mig_register2(bp, service_name, sp, flags); + if (kr == VPROC_ERR_TRY_PER_USER) { mach_port_t puc; if (vproc_mig_lookup_per_user_context(bp, 0, &puc) == 0) { - kr = vproc_mig_register(puc, service_name, sp); + kr = vproc_mig_register2(puc, service_name, sp, flags); mach_port_deallocate(mach_task_self(), puc); } } @@ -95,10 +102,16 @@ kern_return_t bootstrap_look_up(mach_port_t bp, name_t service_name, mach_port_t *sp) { + return bootstrap_look_up2(bp, service_name, sp, 0, 0); +} + +kern_return_t +bootstrap_look_up2(mach_port_t bp, name_t service_name, mach_port_t *sp, pid_t target_pid, uint64_t flags) +{ kern_return_t kr; mach_port_t puc; - if ((kr = vproc_mig_look_up(bp, service_name, sp)) != VPROC_ERR_TRY_PER_USER) { + if ((kr = vproc_mig_look_up2(bp, service_name, sp, target_pid, flags)) != VPROC_ERR_TRY_PER_USER) { return kr; } @@ -106,7 +119,7 @@ return kr; } - kr = vproc_mig_look_up(puc, service_name, sp); + kr = vproc_mig_look_up2(puc, service_name, sp, target_pid, flags); mach_port_deallocate(mach_task_self(), puc); return kr; Added: trunk/launchd/src/libbootstrap_private.h =================================================================== --- trunk/launchd/src/libbootstrap_private.h (rev 0) +++ trunk/launchd/src/libbootstrap_private.h 2007-02-22 18:22:46 UTC (rev 23097) @@ -0,0 +1,40 @@ +#ifndef _BOOTSTRAP_PRIVATE_H_ +#define _BOOTSTRAP_PRIVATE_H_ +/* + * Copyright (c) 2007 Apple 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@ + */ + +#include +#include + +__BEGIN_DECLS + +#pragma GCC visibility push(default) + +#define BOOTSTRAP_PER_PID_SERVICE 1 + +kern_return_t bootstrap_register2(mach_port_t bp, name_t service_name, mach_port_t sp, uint64_t flags); + +kern_return_t bootstrap_look_up2(mach_port_t bp, name_t service_name, mach_port_t *sp, pid_t target_pid, uint64_t flags); + +#pragma GCC visibility pop + +__END_DECLS + +#endif Modified: trunk/launchd/src/protocol_job.defs =================================================================== --- trunk/launchd/src/protocol_job.defs 2007-02-22 01:34:11 UTC (rev 23096) +++ trunk/launchd/src/protocol_job.defs 2007-02-22 18:22:46 UTC (rev 23097) @@ -54,15 +54,18 @@ __service_name : name_t; out __service_port : mach_port_move_receive_t); -routine register( +routine register2( __bs_port : job_t; __service_name : name_t; - __service_port : mach_port_t); + __service_port : mach_port_t; + __flags : uint64_t); -routine look_up( +routine look_up2( __bs_port : job_t; __service_name : name_t; - out __service_port : mach_port_send_t); + out __service_port : mach_port_send_t; + __target_pid : pid_t; + __flags : uint64_t); skip; /* last used in 10.4 */ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070222/a680b397/attachment.html From source_changes at macosforge.org Thu Feb 22 14:41:39 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23098] trunk/launchd/src/launchctl.c Message-ID: <20070222224139.24DB64B4812@cvs.opensource.apple.com> Revision: 23098 http://trac.macosforge.org/projects/launchd/changeset/23098 Author: zarzycki@apple.com Date: 2007-02-22 14:41:38 -0800 (Thu, 22 Feb 2007) Log Message: ----------- I shot myself in the foot with the 'bootstrap' subcommand. This makes it possible to run from single user mode again. Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-02-22 18:22:46 UTC (rev 23097) +++ trunk/launchd/src/launchctl.c 2007-02-22 22:41:38 UTC (rev 23098) @@ -1345,9 +1345,10 @@ if (!path_check("/System/Library/LoginPlugins/BootCache.loginPlugin")) { int remaining_sec = 60 - tvd.tv_sec; + if (remaining_sec > 0) { sleep(remaining_sec); - } + } const char *bcc_stop_tool[] = { "BootCacheControl", "stop", NULL }; assumes(fwexec(bcc_stop_tool, true) != -1); @@ -1357,9 +1358,9 @@ int bootstrap_cmd(int argc, char *const argv[] __attribute__((unused))) { - if (getpid() == 2 && getuid() == 0) { + if (getuid() == 0) { very_pid2_specific_bootstrap(argc == 2); - } else if (getuid() != 0) { + } else { char *load_launchd_items[] = { "load", "-D", "all", "-S", "Background", NULL }; if (is_safeboot()) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070222/0d50629e/attachment.html From source_changes at macosforge.org Thu Feb 22 15:31:44 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23099] trunk/launchd/src Message-ID: <20070222233144.8F4D64B491A@cvs.opensource.apple.com> Revision: 23099 http://trac.macosforge.org/projects/launchd/changeset/23099 Author: zarzycki@apple.com Date: 2007-02-22 15:31:44 -0800 (Thu, 22 Feb 2007) Log Message: ----------- Small bug fixes in the per-job Mach service concept. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/liblaunch_private.h Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-22 22:41:38 UTC (rev 23098) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-22 23:31:44 UTC (rev 23099) @@ -502,13 +502,29 @@ if (!SLIST_EMPTY(&j->machservices) && (tmp = launch_data_alloc(LAUNCH_DATA_DICTIONARY))) { struct machservice *ms; + + tmp3 = NULL; SLIST_FOREACH(ms, &j->machservices, sle) { - tmp2 = launch_data_new_machport(MACH_PORT_NULL); - launch_data_dict_insert(tmp, tmp2, ms->name); + if (ms->per_pid) { + if (tmp3 == NULL) { + tmp3 = launch_data_alloc(LAUNCH_DATA_DICTIONARY); + } + if (tmp3) { + tmp2 = launch_data_new_machport(MACH_PORT_NULL); + launch_data_dict_insert(tmp3, tmp2, ms->name); + } + } else { + tmp2 = launch_data_new_machport(MACH_PORT_NULL); + launch_data_dict_insert(tmp, tmp2, ms->name); + } } launch_data_dict_insert(r, tmp, LAUNCH_JOBKEY_MACHSERVICES); + + if (tmp3) { + launch_data_dict_insert(r, tmp3, LAUNCH_JOBKEY_PERJOBMACHSERVICES); + } } return r; @@ -3532,12 +3548,11 @@ continue; } SLIST_FOREACH(ms, &ji->machservices, sle) { - if (target_pid && !ms->per_pid) { - continue; + if ((target_pid && ms->per_pid) || (!target_pid && !ms->per_pid)) { + if (strcmp(name, ms->name) == 0) { + return ms; + } } - if (strcmp(name, ms->name) == 0) { - return ms; - } } } @@ -4482,7 +4497,9 @@ TAILQ_FOREACH(ji, &jm->jobs, sle) { SLIST_FOREACH(ms, &ji->machservices, sle) { - cnt++; + if (!ms->per_pid) { + cnt++; + } } } @@ -4502,9 +4519,11 @@ TAILQ_FOREACH(ji, &jm->jobs, sle) { SLIST_FOREACH(ms, &ji->machservices, sle) { - strlcpy(service_names[cnt2], machservice_name(ms), sizeof(service_names[0])); - service_actives[cnt2] = machservice_status(ms); - cnt2++; + if (!ms->per_pid) { + strlcpy(service_names[cnt2], machservice_name(ms), sizeof(service_names[0])); + service_actives[cnt2] = machservice_status(ms); + cnt2++; + } } } Modified: trunk/launchd/src/liblaunch_private.h =================================================================== --- trunk/launchd/src/liblaunch_private.h 2007-02-22 22:41:38 UTC (rev 23098) +++ trunk/launchd/src/liblaunch_private.h 2007-02-22 23:31:44 UTC (rev 23099) @@ -50,6 +50,7 @@ #define LAUNCH_KEY_BATCHQUERY "BatchQuery" #define LAUNCH_JOBKEY_ENTERKERNELDEBUGGERBEFOREKILL "EnterKernelDebuggerBeforeKill" +#define LAUNCH_JOBKEY_PERJOBMACHSERVICES "PerJobMachServices" #define LAUNCH_JOBKEY_MACH_KUNCSERVER "kUNCServer" #define LAUNCH_JOBKEY_MACH_EXCEPTIONSERVER "ExceptionServer" -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070222/bde082ac/attachment.html From source_changes at macosforge.org Thu Feb 22 15:38:58 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23100] trunk/launchd/src Message-ID: <20070222233858.4092B4B4954@cvs.opensource.apple.com> Revision: 23100 http://trac.macosforge.org/projects/launchd/changeset/23100 Author: zarzycki@apple.com Date: 2007-02-22 15:38:57 -0800 (Thu, 22 Feb 2007) Log Message: ----------- Ensure that c->j is always set. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_core_logic.h trunk/launchd/src/launchd_unix_ipc.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-22 23:31:44 UTC (rev 23099) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-22 23:38:57 UTC (rev 23100) @@ -218,7 +218,6 @@ static void jobmgr_log_stray_children(jobmgr_t jm); static void jobmgr_remove(jobmgr_t jm); static void jobmgr_dispatch_all(jobmgr_t jm); -static job_t jobmgr_new_anonymous(jobmgr_t jm); 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); @@ -911,11 +910,15 @@ } job_t -jobmgr_new_anonymous(jobmgr_t jm) +jobmgr_get_anonymous(jobmgr_t jm) { char newlabel[1000], *procname = "unknown"; job_t jr; + if (jm->anonj) { + return jm->anonj; + } + snprintf(newlabel, sizeof(newlabel), "%u.anonymous", MACH_PORT_INDEX(jm->jm_port)); if ((jr = job_new(jm, newlabel, procname, NULL))) { @@ -3474,7 +3477,7 @@ goto out_bad; } - jobmgr_assumes(jmr, (jmr->anonj = jobmgr_new_anonymous(jmr)) != NULL); + jobmgr_assumes(jmr, (jmr->anonj = jobmgr_get_anonymous(jmr)) != NULL); bootstrapper = job_new(jmr, "com.apple.launchctld", NULL, bootstrap_tool); Modified: trunk/launchd/src/launchd_core_logic.h =================================================================== --- trunk/launchd/src/launchd_core_logic.h 2007-02-22 23:31:44 UTC (rev 23099) +++ trunk/launchd/src/launchd_core_logic.h 2007-02-22 23:38:57 UTC (rev 23100) @@ -31,6 +31,7 @@ void jobmgr_init(bool); jobmgr_t jobmgr_shutdown(jobmgr_t jm); void jobmgr_dispatch_all_semaphores(jobmgr_t jm); +job_t jobmgr_get_anonymous(jobmgr_t jm); job_t jobmgr_find(jobmgr_t jm, const char *label); jobmgr_t jobmgr_delete_anything_with_port(jobmgr_t jm, mach_port_t port); bool jobmgr_ack_port_destruction(jobmgr_t jm, mach_port_t p); Modified: trunk/launchd/src/launchd_unix_ipc.c =================================================================== --- trunk/launchd/src/launchd_unix_ipc.c 2007-02-22 23:31:44 UTC (rev 23099) +++ trunk/launchd/src/launchd_unix_ipc.c 2007-02-22 23:38:57 UTC (rev 23100) @@ -184,7 +184,7 @@ c->kqconn_callback = ipc_callback; c->conn = launchd_fdopen(fd); - c->j = j; + c->j = j ? j : jobmgr_get_anonymous(root_jobmgr); SLIST_INSERT_HEAD(&connections, c, sle); kevent_mod(fd, EVFILT_READ, EV_ADD, 0, 0, &c->kqconn_callback); } @@ -328,11 +328,7 @@ return; } - if (rmc->c->j) { - job_log(rmc->c->j, LOG_DEBUG, "Unix IPC request: %s", cmd); - } else { - runtime_syslog(LOG_DEBUG, "Unix IPC request: %s", cmd); - } + job_log(rmc->c->j, LOG_DEBUG, "Unix IPC request: %s", cmd); if (data == NULL) { if (!strcmp(cmd, LAUNCH_KEY_CHECKIN)) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070222/ec892f95/attachment.html From source_changes at macosforge.org Thu Feb 22 16:43:06 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23101] trunk/launchd/src/liblaunch.c Message-ID: <20070223004306.06CA94B4B68@cvs.opensource.apple.com> Revision: 23101 http://trac.macosforge.org/projects/launchd/changeset/23101 Author: zarzycki@apple.com Date: 2007-02-22 16:43:05 -0800 (Thu, 22 Feb 2007) Log Message: ----------- 64-bit daemon fails to connect to launchd Modified Paths: -------------- trunk/launchd/src/liblaunch.c Modified: trunk/launchd/src/liblaunch.c =================================================================== --- trunk/launchd/src/liblaunch.c 2007-02-22 23:38:57 UTC (rev 23100) +++ trunk/launchd/src/liblaunch.c 2007-02-23 00:43:05 UTC (rev 23101) @@ -623,9 +623,9 @@ 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(launch_data_t))); - memcpy(*where + *len, d->_array, d->_array_cnt * sizeof(launch_data_t)); - *len += d->_array_cnt * sizeof(launch_data_t); + *where = realloc(*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); for (i = 0; i < d->_array_cnt; i++) launch_data_pack(d->_array[i], where, len, fd_where, fdcnt); @@ -649,12 +649,12 @@ case LAUNCH_DATA_DICTIONARY: case LAUNCH_DATA_ARRAY: tmpcnt = big2host(r->_array_cnt); - if ((conn->recvlen - *data_offset) < (tmpcnt * sizeof(launch_data_t))) { + if ((conn->recvlen - *data_offset) < (tmpcnt * sizeof(uint64_t))) { errno = EAGAIN; return NULL; } r->_array = conn->recvbuf + *data_offset; - *data_offset += tmpcnt * sizeof(launch_data_t); + *data_offset += tmpcnt * sizeof(uint64_t); for (i = 0; i < tmpcnt; i++) { r->_array[i] = launch_data_unpack(conn, data_offset, fdoffset); if (r->_array[i] == NULL) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070222/1f5bb6f1/attachment.html From source_changes at macosforge.org Fri Feb 23 08:35:28 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23102] trunk/launchd/src Message-ID: <20070223163528.A7E994B580B@cvs.opensource.apple.com> Revision: 23102 http://trac.macosforge.org/projects/launchd/changeset/23102 Author: zarzycki@apple.com Date: 2007-02-23 08:35:27 -0800 (Fri, 23 Feb 2007) Log Message: ----------- [Kernel Extensions] Regression on load order Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/SystemStarter.c Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-02-23 00:43:05 UTC (rev 23101) +++ trunk/launchd/src/Makefile.am 2007-02-23 16:35:27 UTC (rev 23102) @@ -40,7 +40,7 @@ launchctl_LDFLAGS = -framework CoreFoundation -framework IOKit -weak_library /usr/lib/libedit.dylib SystemStarter_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -SystemStarter_LDFLAGS = -framework CoreFoundation +SystemStarter_LDFLAGS = -framework CoreFoundation -framework IOKit SystemStarter_SOURCES = StartupItems.c IPC.c SystemStarter.c launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -Wno-unused-parameter Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-02-23 00:43:05 UTC (rev 23101) +++ trunk/launchd/src/Makefile.in 2007-02-23 16:35:27 UTC (rev 23102) @@ -239,7 +239,7 @@ @LIBS_ONLY_FALSE@launchctl_CFLAGS = $(AM_CFLAGS) -I/System/Library/Frameworks/System.framework/PrivateHeaders @LIBS_ONLY_FALSE@launchctl_LDFLAGS = -framework CoreFoundation -framework IOKit -weak_library /usr/lib/libedit.dylib @LIBS_ONLY_FALSE@SystemStarter_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -@LIBS_ONLY_FALSE@SystemStarter_LDFLAGS = -framework CoreFoundation +@LIBS_ONLY_FALSE@SystemStarter_LDFLAGS = -framework CoreFoundation -framework IOKit @LIBS_ONLY_FALSE@SystemStarter_SOURCES = StartupItems.c IPC.c SystemStarter.c @LIBS_ONLY_FALSE@launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -Wno-unused-parameter @LIBS_ONLY_FALSE@launchd_LDFLAGS = -lbsm Modified: trunk/launchd/src/SystemStarter.c =================================================================== --- trunk/launchd/src/SystemStarter.c 2007-02-23 00:43:05 UTC (rev 23101) +++ trunk/launchd/src/SystemStarter.c 2007-02-23 16:35:27 UTC (rev 23102) @@ -22,6 +22,7 @@ * @APPLE_APACHE_LICENSE_HEADER_END@ **/ +#include #include #include #include @@ -115,6 +116,8 @@ } else if (!gDebugFlag && anAction != kActionStop) { const char *ipw_cmd[] = { "/usr/sbin/ipconfig", "waitall", NULL }; const char *adm_cmd[] = { "/sbin/autodiskmount", "-va", NULL }; + mach_timespec_t w = { 600, 0 }; + kern_return_t kr; /* Too many old StartupItems had implicit dependancies on * "Network" via other StartupItems that are now no-ops. @@ -123,6 +126,11 @@ * so we'll stall here to deal with this legacy dependancy * problem. */ + + if ((kr = IOKitWaitQuiet(kIOMasterPortDefault, &w)) != kIOReturnSuccess) { + syslog(LOG_NOTICE, "IOKitWaitQuiet: %d\n", kr); + } + fwexec(ipw_cmd, true); fwexec(adm_cmd, true); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070223/51e27f27/attachment.html From source_changes at macosforge.org Fri Feb 23 08:53:43 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23103] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070223165343.E0AE14B582F@cvs.opensource.apple.com> Revision: 23103 http://trac.macosforge.org/projects/launchd/changeset/23103 Author: zarzycki@apple.com Date: 2007-02-23 08:53:43 -0800 (Fri, 23 Feb 2007) Log Message: ----------- More 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-02-23 16:35:27 UTC (rev 23102) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-23 16:53:43 UTC (rev 23103) @@ -2256,8 +2256,7 @@ SLIST_FOREACH(li, &j->limits, sle) { struct rlimit rl; - if (getrlimit(li->which, &rl) == -1) { - job_log_error(j, LOG_WARNING, "getrlimit()"); + if (!job_assumes(j, getrlimit(li->which, &rl) != -1)) { continue; } @@ -2278,19 +2277,17 @@ } if (j->low_pri_io) { - if (setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_THROTTLE) == -1) { - job_log_error(j, LOG_WARNING, "setiopolicy_np()"); - } + job_assumes(j, setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_THROTTLE) != -1); } if (j->rootdir) { - chroot(j->rootdir); - chdir("."); + job_assumes(j, chroot(j->rootdir) != -1); + job_assumes(j, chdir(".") != -1); } job_postfork_become_user(j); if (j->workingdir) { - chdir(j->workingdir); + job_assumes(j, chdir(j->workingdir) != -1); } if (j->setmask) { @@ -2306,7 +2303,7 @@ setenv(ei->key, ei->value, 1); } - setsid(); + job_assumes(j, setsid() != -1); } void -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070223/b9d4e373/attachment.html From source_changes at macosforge.org Fri Feb 23 09:40:11 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23104] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070223174011.014564B58BE@cvs.opensource.apple.com> Revision: 23104 http://trac.macosforge.org/projects/launchd/changeset/23104 Author: zarzycki@apple.com Date: 2007-02-23 09:40:11 -0800 (Fri, 23 Feb 2007) Log Message: ----------- launchd plist doesn't respect soft resource limit on max files. 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-02-23 16:53:43 UTC (rev 23103) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-23 17:40:11 UTC (rev 23104) @@ -2862,6 +2862,8 @@ return false; } + SLIST_INSERT_HEAD(&j->limits, li, sle); + li->which = w; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070223/075b58ef/attachment.html From source_changes at macosforge.org Fri Feb 23 11:44:36 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23105] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070223194436.4426E4B5A67@cvs.opensource.apple.com> Revision: 23105 http://trac.macosforge.org/projects/launchd/changeset/23105 Author: zarzycki@apple.com Date: 2007-02-23 11:44:35 -0800 (Fri, 23 Feb 2007) Log Message: ----------- Documentation of launchd.plist does not specify month is 0-11 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-02-23 17:40:11 UTC (rev 23104) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-23 19:44:35 UTC (rev 23105) @@ -2660,6 +2660,7 @@ } if ((tmp_k = launch_data_dict_lookup(obj, LAUNCH_JOBKEY_CAL_MONTH))) { tmptm.tm_mon = launch_data_get_integer(tmp_k); + tmptm.tm_mon -= 1; /* 4798263 cron compatibility */ } return calendarinterval_new(j, &tmptm); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070223/50e4852a/attachment.html From source_changes at macosforge.org Fri Feb 23 14:02:02 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23106] tags/launchd-198/ Message-ID: <20070223220202.EF12A4B5CA4@cvs.opensource.apple.com> Revision: 23106 http://trac.macosforge.org/projects/launchd/changeset/23106 Author: zarzycki@apple.com Date: 2007-02-23 14:02:02 -0800 (Fri, 23 Feb 2007) Log Message: ----------- "Tagging launchd-198 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-198/ Copied: tags/launchd-198 (from rev 23105, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070223/3603d487/attachment.html From source_changes at macosforge.org Fri Feb 23 14:57:42 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23107] trunk/launchd/src/launchctl.c Message-ID: <20070223225742.423C74B5E3C@cvs.opensource.apple.com> Revision: 23107 http://trac.macosforge.org/projects/launchd/changeset/23107 Author: zarzycki@apple.com Date: 2007-02-23 14:57:41 -0800 (Fri, 23 Feb 2007) Log Message: ----------- Move some code to a better place. Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-02-23 22:02:02 UTC (rev 23106) +++ trunk/launchd/src/launchctl.c 2007-02-23 22:57:41 UTC (rev 23107) @@ -205,8 +205,6 @@ { char *l; - do_sysversion_sysctl(); - istty = isatty(STDIN_FILENO); argc--, argv++; @@ -1243,6 +1241,8 @@ int hnmib[] = { CTL_KERN, KERN_HOSTNAME }; struct group *tfp_gr; + do_sysversion_sysctl(); + do_single_user_mode(sflag); assumes(gettimeofday(&tvs, NULL) != -1); @@ -2717,9 +2717,6 @@ /* ER: launchd should set kern.osversion very early in boot */ - if (getuid() != 0) - return; - if (sysctl(mib, 2, buf, &bufsz, NULL, 0) == -1) { fprintf(stderr, "sysctl(): %s\n", strerror(errno)); return; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070223/859eca5d/attachment.html From source_changes at macosforge.org Sun Feb 25 15:32:43 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23108] trunk/launchd/src/launchctl.c Message-ID: <20070225233243.9952B4B8874@cvs.opensource.apple.com> Revision: 23108 http://trac.macosforge.org/projects/launchd/changeset/23108 Author: zarzycki@apple.com Date: 2007-02-25 15:32:43 -0800 (Sun, 25 Feb 2007) Log Message: ----------- Be a little more greedy about when we stop the BootCache at boot up. Be a little more defensive against a shutdown or reboot shortly after boot up. Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-02-23 22:57:41 UTC (rev 23107) +++ trunk/launchd/src/launchctl.c 2007-02-25 23:32:43 UTC (rev 23108) @@ -1237,16 +1237,25 @@ static void very_pid2_specific_bootstrap(bool sflag) { - struct timeval tvs, tve, tvd; int hnmib[] = { CTL_KERN, KERN_HOSTNAME }; struct group *tfp_gr; + struct kevent kev; + int kq; + do_sysversion_sysctl(); do_single_user_mode(sflag); - assumes(gettimeofday(&tvs, NULL) != -1); + assumes((kq = kqueue()) != -1); + EV_SET(&kev, 0, EVFILT_TIMER, EV_ADD|EV_ONESHOT, NOTE_SECONDS, 90, 0); + assumes(kevent(kq, &kev, 1, NULL, 0, NULL) != -1); + assumes(signal(SIGTERM, SIG_IGN) != SIG_ERR); + + EV_SET(&kev, SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, 0); + assumes(kevent(kq, &kev, 1, NULL, 0, NULL) != -1); + 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; @@ -1339,20 +1348,14 @@ _vproc_set_global_on_demand(false); - assumes(gettimeofday(&tve, NULL) != -1); - - timersub(&tve, &tvs, &tvd); - if (!path_check("/System/Library/LoginPlugins/BootCache.loginPlugin")) { - int remaining_sec = 60 - tvd.tv_sec; + assumes(kevent(kq, NULL, 0, &kev, 1, NULL) == 1); - if (remaining_sec > 0) { - sleep(remaining_sec); - } - const char *bcc_stop_tool[] = { "BootCacheControl", "stop", NULL }; assumes(fwexec(bcc_stop_tool, true) != -1); } + + assumes(close(kq) != -1); } int -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070225/1974af55/attachment.html From source_changes at macosforge.org Sun Feb 25 15:43:11 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23109] trunk/launchd/src/wait4path.c Message-ID: <20070225234311.452B84B88A0@cvs.opensource.apple.com> Revision: 23109 http://trac.macosforge.org/projects/launchd/changeset/23109 Author: zarzycki@apple.com Date: 2007-02-25 15:43:10 -0800 (Sun, 25 Feb 2007) Log Message: ----------- Fix a small race (never seen in practice). Modified Paths: -------------- trunk/launchd/src/wait4path.c Modified: trunk/launchd/src/wait4path.c =================================================================== --- trunk/launchd/src/wait4path.c 2007-02-25 23:32:43 UTC (rev 23108) +++ trunk/launchd/src/wait4path.c 2007-02-25 23:43:10 UTC (rev 23109) @@ -39,9 +39,6 @@ exit(EXIT_FAILURE); } - if (stat(argv[1], &sb) == 0) - exit(EXIT_SUCCESS); - EV_SET(&kev, 0, EVFILT_FS, EV_ADD, 0, 0, 0); if (kevent(kq, &kev, 1, NULL, 0, NULL) == -1) { @@ -49,10 +46,15 @@ exit(EXIT_FAILURE); } + if (stat(argv[1], &sb) == 0) { + exit(EXIT_SUCCESS); + } + for (;;) { kevent(kq, NULL, 0, &kev, 1, NULL); - if (stat(argv[1], &sb) == 0) + if (stat(argv[1], &sb) == 0) { break; + } } exit(EXIT_SUCCESS); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070225/f06bc756/attachment.html From source_changes at macosforge.org Tue Feb 27 09:38:36 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23110] trunk/launchd/src/service Message-ID: <20070227173836.95B464BC8E4@cvs.opensource.apple.com> Revision: 23110 http://trac.macosforge.org/projects/launchd/changeset/23110 Author: zarzycki@apple.com Date: 2007-02-27 09:38:36 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Dead code deletion. Modified Paths: -------------- trunk/launchd/src/service Modified: trunk/launchd/src/service =================================================================== --- trunk/launchd/src/service 2007-02-25 23:43:10 UTC (rev 23109) +++ trunk/launchd/src/service 2007-02-27 17:38:36 UTC (rev 23110) @@ -20,8 +20,6 @@ if [ "$1" == "--list" ] then - echo smtp - echo fax-receive cd /System/Library/LaunchDaemons 2>/dev/null ls -1 | egrep '.plist$' | sed 's,.plist$,,g' exit 0 @@ -37,74 +35,15 @@ exit 0 fi fi - if [ "$2" = "smtp" ] - then - egrep '^MAILSERVER.*-YES-' /etc/hostconfig >/dev/null 2>&1 - exit $? - fi - if [ "$2" = "fax-receive" ] - then - egrep '^fax.*unknown.*on$' /etc/ttys >/dev/null 2>&1 - exit $? - fi exit 1 elif [ "$1" == "--test-if-available" ] then [ -f /System/Library/LaunchDaemons/$2.plist ] && exit 0 - [ "$2" = "smtp" ] && exit 0 - [ "$2" = "fax-receive" ] && exit 0 - exit 0 + exit 1 elif [ -f "/System/Library/LaunchDaemons/$1.plist" ] then [ "$2" == start ] && launchctl load -w /System/Library/LaunchDaemons/$1.plist [ "$2" == stop ] && launchctl unload -w /System/Library/LaunchDaemons/$1.plist -elif [ "$1" = "smtp" ] -then - if [ $UID != 0 ] - then - echo "You must be root to run this option" >&2 - exit 1 - fi - TMPFILE=$(mktemp /var/run/xinetd.tmp.$$.XXXXXX) - cp -f /etc/hostconfig $TMPFILE - if [ "$2" == start ] - then - if grep -q MAILSERVER=-NO- /etc/hostconfig ; then - sed 's,^MAILSERVER=-NO-,MAILSERVER=-YES-,g' < $TMPFILE > /etc/hostconfig - fi - postfix start - postfix flush - elif [ "$2" == stop ] - then - if grep -q MAILSERVER=-YES- /etc/hostconfig ; then - sed 's,^MAILSERVER=-YES-,MAILSERVER=-NO-,g' < $TMPFILE > /etc/hostconfig - fi - postfix stop - else - echo "No such service command" >&2 - fi - rm -f $TMPFILE -elif [ "$1" = "fax-receive" ] -then - if [ $UID != 0 ] - then - echo "You must be root to run this option" >&2 - exit 1 - fi - TMPFILE=$(mktemp /var/run/xinetd.tmp.$$.XXXXXX) - cp -f /etc/ttys $TMPFILE - if [ "$2" == start ] - then - sed 's,^fax\(.*\)off$,fax\1on,g' < $TMPFILE > /etc/ttys - kill -HUP 1 - elif [ "$2" == stop ] - then - sed 's,^fax\(.*\)on$,fax\1off,g' < $TMPFILE > /etc/ttys - kill -HUP 1 - else - echo "No such service command" >&2 - fi - rm -f $TMPFILE else echo "No such service $1" >&2 exit 1 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070227/a61aa0d3/attachment.html From source_changes at macosforge.org Tue Feb 27 10:27:05 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23111] trunk/launchd/src/launchctl.c Message-ID: <20070227182705.31B0B4BCAC5@cvs.opensource.apple.com> Revision: 23111 http://trac.macosforge.org/projects/launchd/changeset/23111 Author: zarzycki@apple.com Date: 2007-02-27 10:27:04 -0800 (Tue, 27 Feb 2007) Log Message: ----------- launchd should always pass '-f' to BootCacheControl Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-02-27 17:38:36 UTC (rev 23110) +++ trunk/launchd/src/launchctl.c 2007-02-27 18:27:04 UTC (rev 23111) @@ -141,6 +141,14 @@ static void do_single_user_mode(bool); static bool do_single_user_mode2(void); +typedef enum { + BOOTCACHE_START = 1, + BOOTCACHE_TAG, + BOOTCACHE_STOP, +} BootCache_action_t; + +static void do_BootCache_magic(BootCache_action_t what); + static int bootstrap_cmd(int argc, char *const argv[]); static int load_and_unload_cmd(int argc, char *const argv[]); //static int reload_cmd(int argc, char *const argv[]); @@ -1326,8 +1334,7 @@ assumes(fwexec(audit_tool, true) != -1); } - const char *bcc_tool[] = { "BootCacheControl", "start", NULL }; - assumes(fwexec(bcc_tool, true) != -1); + do_BootCache_magic(BOOTCACHE_START); preheat_page_cache_hack(); @@ -1341,8 +1348,7 @@ assumes(load_and_unload_cmd(4, load_launchd_items) == 0); - const char *bcc_tag_tool[] = { "BootCacheControl", "tag", NULL }; - assumes(fwexec(bcc_tag_tool, true) != -1); + do_BootCache_magic(BOOTCACHE_TAG); do_bootroot_magic(); @@ -1351,13 +1357,35 @@ if (!path_check("/System/Library/LoginPlugins/BootCache.loginPlugin")) { assumes(kevent(kq, NULL, 0, &kev, 1, NULL) == 1); - const char *bcc_stop_tool[] = { "BootCacheControl", "stop", NULL }; - assumes(fwexec(bcc_stop_tool, true) != -1); + do_BootCache_magic(BOOTCACHE_STOP); } assumes(close(kq) != -1); } +void +do_BootCache_magic(BootCache_action_t what) +{ + const char *bcc_tool[] = { "BootCacheControl", "-f", "/var/db/BootCache.playlist", NULL, NULL }; + + switch (what) { + case BOOTCACHE_START: + bcc_tool[3] = "start"; + break; + case BOOTCACHE_TAG: + bcc_tool[3] = "tag"; + break; + case BOOTCACHE_STOP: + bcc_tool[3] = "stop"; + break; + default: + assumes(false); + return; + } + + assumes(fwexec(bcc_tool, true) != -1); +} + int bootstrap_cmd(int argc, char *const argv[] __attribute__((unused))) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070227/14c7d713/attachment.html From source_changes at macosforge.org Tue Feb 27 10:34:14 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23112] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070227183414.E5F564BCB68@cvs.opensource.apple.com> Revision: 23112 http://trac.macosforge.org/projects/launchd/changeset/23112 Author: zarzycki@apple.com Date: 2007-02-27 10:34:14 -0800 (Tue, 27 Feb 2007) Log Message: ----------- launchd passess BonjourFDs on checkin 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-02-27 18:27:04 UTC (rev 23111) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-27 18:34:14 UTC (rev 23112) @@ -486,6 +486,9 @@ int i; SLIST_FOREACH(sg, &j->sockets, sle) { + if (sg->junkfds) { + continue; + } if ((tmp2 = launch_data_alloc(LAUNCH_DATA_ARRAY))) { for (i = 0; i < sg->fd_cnt; i++) { if ((tmp3 = launch_data_new_fd(sg->fds[i]))) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070227/e203a200/attachment.html From source_changes at macosforge.org Tue Feb 27 11:52:05 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23113] trunk/launchd/src Message-ID: <20070227195205.36BBE4BCE32@cvs.opensource.apple.com> Revision: 23113 http://trac.macosforge.org/projects/launchd/changeset/23113 Author: zarzycki@apple.com Date: 2007-02-27 11:52:04 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Only run SystemStarter when StartupItems exist Modified Paths: -------------- trunk/launchd/src/SystemStarter.c trunk/launchd/src/com.apple.SystemStarter.plist trunk/launchd/src/launchctl.c trunk/launchd/src/rc.shutdown Modified: trunk/launchd/src/SystemStarter.c =================================================================== --- trunk/launchd/src/SystemStarter.c 2007-02-27 18:34:14 UTC (rev 23112) +++ trunk/launchd/src/SystemStarter.c 2007-02-27 19:52:04 UTC (rev 23113) @@ -24,12 +24,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include #include #include "IPC.h" @@ -44,16 +46,21 @@ static void usage(void) __attribute__((noreturn)); static int system_starter(Action anAction, const char *aService); static void displayErrorMessages(StartupContext aStartupContext); -static void doCFnote(void); static pid_t fwexec(const char *const *argv, bool _wait); int main(int argc, char *argv[]) { + struct kevent kev; Action anAction = kActionStart; - char *aService = NULL; - int ch; + int ch, kq; + assert((kq = kqueue()) != -1); + + EV_SET(&kev, SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, 0); + assert(kevent(kq, &kev, 1, NULL, 0, NULL) != -1); + assert(signal(SIGTERM, SIG_IGN) != SIG_ERR); + while ((ch = getopt(argc, argv, "gvxirdDqn?")) != -1) { switch (ch) { case 'v': @@ -80,15 +87,18 @@ argc -= optind; argv += optind; - if (argc > 2) + if (argc > 2) { usage(); + } openlog(getprogname(), LOG_PID|LOG_CONS|(gDebugFlag ? LOG_PERROR : 0), LOG_DAEMON); - setlogmask(LOG_UPTO(LOG_NOTICE)); - if (gVerboseFlag) - setlogmask(LOG_UPTO(LOG_INFO)); - if (gDebugFlag) + if (gDebugFlag) { setlogmask(LOG_UPTO(LOG_DEBUG)); + } else if (gVerboseFlag) { + setlogmask(LOG_UPTO(LOG_INFO)); + } else { + setlogmask(LOG_UPTO(LOG_NOTICE)); + } if (!gNoRunFlag && (getuid() != 0)) { syslog(LOG_ERR, "must be root to run"); @@ -107,55 +117,53 @@ } } - atexit(doCFnote); + if (argc == 2) { + exit(system_starter(anAction, argv[1])); + } unlink(kFixerPath); - if (argc == 2) { - aService = argv[1]; - } else if (!gDebugFlag && anAction != kActionStop) { - const char *ipw_cmd[] = { "/usr/sbin/ipconfig", "waitall", NULL }; - const char *adm_cmd[] = { "/sbin/autodiskmount", "-va", NULL }; - mach_timespec_t w = { 600, 0 }; - kern_return_t kr; + const char *ipw_cmd[] = { "/usr/sbin/ipconfig", "waitall", NULL }; + const char *adm_cmd[] = { "/sbin/autodiskmount", "-va", NULL }; + mach_timespec_t w = { 600, 0 }; + kern_return_t kr; + struct stat sb; - /* Too many old StartupItems had implicit dependancies on - * "Network" via other StartupItems that are now no-ops. - * - * SystemStarter is not on the critical path for boot up, - * so we'll stall here to deal with this legacy dependancy - * problem. - */ + /* + * Too many old StartupItems had implicit dependancies on "Network" via + * other StartupItems that are now no-ops. + * + * SystemStarter is not on the critical path for boot up, so we'll + * stall here to deal with this legacy dependancy problem. + */ - if ((kr = IOKitWaitQuiet(kIOMasterPortDefault, &w)) != kIOReturnSuccess) { - syslog(LOG_NOTICE, "IOKitWaitQuiet: %d\n", kr); - } - - fwexec(ipw_cmd, true); - fwexec(adm_cmd, true); + if ((kr = IOKitWaitQuiet(kIOMasterPortDefault, &w)) != kIOReturnSuccess) { + syslog(LOG_NOTICE, "IOKitWaitQuiet: %d\n", kr); } - int ssec = system_starter(anAction, aService); - struct stat sb; + fwexec(ipw_cmd, true); + fwexec(adm_cmd, true); - if (anAction == kActionStart && stat("/etc/rc.local", &sb) != -1) { - int wstatus; - pid_t rclp; + system_starter(kActionStart, NULL); - switch ((rclp = fork())) { - case -1: - break; - case 0: - execlp(_PATH_BSHELL, _PATH_BSHELL, "/etc/rc.local", NULL); - _exit(EXIT_FAILURE); - break; - default: - waitpid(rclp, &wstatus, 0); - break; - } + if (stat("/etc/rc.local", &sb) != -1) { + const char *rc_local_cmd[] = { "_PATH_BSHELL", "/etc/rc.local", NULL }; + + fwexec(rc_local_cmd, true); } - exit(ssec); + CFNotificationCenterPostNotificationWithOptions( + CFNotificationCenterGetDistributedCenter(), + CFSTR("com.apple.startupitems.completed"), + NULL, NULL, + kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); + + assert(kevent(kq, NULL, 0, &kev, 1, NULL) != -1); + assert(kev.filter == EVFILT_SIGNAL && kev.ident == SIGTERM); + + system_starter(kActionStop, NULL); + + exit(EXIT_SUCCESS); } @@ -383,15 +391,6 @@ exit(EXIT_FAILURE); } -static void doCFnote(void) -{ - CFNotificationCenterPostNotificationWithOptions( - CFNotificationCenterGetDistributedCenter(), - CFSTR("com.apple.startupitems.completed"), - NULL, NULL, - kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); -} - pid_t fwexec(const char *const *argv, bool _wait) { Modified: trunk/launchd/src/com.apple.SystemStarter.plist =================================================================== --- trunk/launchd/src/com.apple.SystemStarter.plist 2007-02-27 18:34:14 UTC (rev 23112) +++ trunk/launchd/src/com.apple.SystemStarter.plist 2007-02-27 19:52:04 UTC (rev 23113) @@ -6,7 +6,18 @@ com.apple.SystemStarter Program /sbin/SystemStarter - RunAtLoad - + KeepAlive + + KeepAlive + + /etc/rc.local + + + + QueueDirectories + + /Library/StartupItems + /System/Library/StartupItems + Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-02-27 18:34:14 UTC (rev 23112) +++ trunk/launchd/src/launchctl.c 2007-02-27 19:52:04 UTC (rev 23113) @@ -1259,10 +1259,10 @@ EV_SET(&kev, 0, EVFILT_TIMER, EV_ADD|EV_ONESHOT, NOTE_SECONDS, 90, 0); assumes(kevent(kq, &kev, 1, NULL, 0, NULL) != -1); - assumes(signal(SIGTERM, SIG_IGN) != SIG_ERR); EV_SET(&kev, SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, 0); 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 }; Modified: trunk/launchd/src/rc.shutdown =================================================================== --- trunk/launchd/src/rc.shutdown 2007-02-27 18:34:14 UTC (rev 23112) +++ trunk/launchd/src/rc.shutdown 2007-02-27 19:52:04 UTC (rev 23113) @@ -4,7 +4,5 @@ . /etc/rc.common if [ -f /etc/rc.shutdown.local ]; then - sh /etc/rc.shutdown.local + exec sh /etc/rc.shutdown.local fi - -exec SystemStarter stop -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070227/3d332699/attachment.html From source_changes at macosforge.org Tue Feb 27 12:08:06 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23114] trunk Message-ID: <20070227200806.C7ADC4BCECF@cvs.opensource.apple.com> Revision: 23114 http://trac.macosforge.org/projects/launchd/changeset/23114 Author: zarzycki@apple.com Date: 2007-02-27 12:08:06 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Only run SystemStarter when StartupItems exist Modified Paths: -------------- trunk/Makefile trunk/launchd/src/SystemStarter.c Modified: trunk/Makefile =================================================================== --- trunk/Makefile 2007-02-27 19:52:04 UTC (rev 23113) +++ trunk/Makefile 2007-02-27 20:08:06 UTC (rev 23114) @@ -12,6 +12,8 @@ else mkdir -p $(DSTROOT)/Library/StartupItems chmod 755 $(DSTROOT)/Library/StartupItems + mkdir -p $(DSTROOT)/System/Library/StartupItems + chmod 755 $(DSTROOT)/System/Library/StartupItems rm -rf $(DSTROOT)/usr/local/lib/system cp $(OBJROOT)/src/launchd $(SYMROOT) cp $(OBJROOT)/src/launchctl $(SYMROOT) Modified: trunk/launchd/src/SystemStarter.c =================================================================== --- trunk/launchd/src/SystemStarter.c 2007-02-27 19:52:04 UTC (rev 23113) +++ trunk/launchd/src/SystemStarter.c 2007-02-27 20:08:06 UTC (rev 23114) @@ -53,13 +53,14 @@ { struct kevent kev; Action anAction = kActionStart; - int ch, kq; + int ch, r, kq = kqueue(); - assert((kq = kqueue()) != -1); + assert(kq != -1); EV_SET(&kev, SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, 0); - assert(kevent(kq, &kev, 1, NULL, 0, NULL) != -1); - assert(signal(SIGTERM, SIG_IGN) != SIG_ERR); + r = kevent(kq, &kev, 1, NULL, 0, NULL); + assert(r != -1); + signal(SIGTERM, SIG_IGN); while ((ch = getopt(argc, argv, "gvxirdDqn?")) != -1) { switch (ch) { @@ -158,7 +159,8 @@ NULL, NULL, kCFNotificationDeliverImmediately | kCFNotificationPostToAllSessions); - assert(kevent(kq, NULL, 0, &kev, 1, NULL) != -1); + r = kevent(kq, NULL, 0, &kev, 1, NULL); + assert(r != -1); assert(kev.filter == EVFILT_SIGNAL && kev.ident == SIGTERM); system_starter(kActionStop, NULL); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070227/1c62bb39/attachment.html From source_changes at macosforge.org Tue Feb 27 12:28:31 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23115] trunk/launchd/src/launchd_core_logic.c Message-ID: <20070227202831.9BF104BCF69@cvs.opensource.apple.com> Revision: 23115 http://trac.macosforge.org/projects/launchd/changeset/23115 Author: zarzycki@apple.com Date: 2007-02-27 12:28:31 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Bug: launchd_core_logic.c:562 (23087):2: TAILQ_NEXT(ji, sle) == NULL 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-02-27 20:08:06 UTC (rev 23114) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-27 20:28:31 UTC (rev 23115) @@ -1648,7 +1648,7 @@ job_log(j, LOG_DEBUG, "Reaping"); - if (j->log_redirect_fd && !j->wait4pipe_eof) { + if (j->log_redirect_fd && (!j->wait4pipe_eof || j->mgr->shutting_down)) { job_assumes(j, close(j->log_redirect_fd) != -1); j->log_redirect_fd = 0; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070227/41c93b0b/attachment.html From source_changes at macosforge.org Tue Feb 27 12:39:13 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23116] trunk/launchd/src Message-ID: <20070227203913.A89314BD00E@cvs.opensource.apple.com> Revision: 23116 http://trac.macosforge.org/projects/launchd/changeset/23116 Author: zarzycki@apple.com Date: 2007-02-27 12:39:13 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Leopard9A377: /SourceCache/xnu/xnu-1051/bsd/kern/kern_exit.c:247 "init died\nState at Last Exc Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_unix_ipc.c trunk/launchd/src/launchd_unix_ipc.h Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-02-27 20:28:31 UTC (rev 23115) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-27 20:39:13 UTC (rev 23116) @@ -633,6 +633,8 @@ return; } + ipc_close_all_with_job(j); + if (j->forced_peers_to_demand_mode) { job_set_global_on_demand(j, false); } Modified: trunk/launchd/src/launchd_unix_ipc.c =================================================================== --- trunk/launchd/src/launchd_unix_ipc.c 2007-02-27 20:28:31 UTC (rev 23115) +++ trunk/launchd/src/launchd_unix_ipc.c 2007-02-27 20:39:13 UTC (rev 23116) @@ -238,6 +238,18 @@ } void +ipc_close_all_with_job(job_t j) +{ + struct conncb *ci, *cin; + + SLIST_FOREACH_SAFE(ci, &connections, sle, cin) { + if (ci->j == j) { + ipc_close(ci); + } + } +} + +void ipc_close_fds(launch_data_t o) { size_t i; Modified: trunk/launchd/src/launchd_unix_ipc.h =================================================================== --- trunk/launchd/src/launchd_unix_ipc.h 2007-02-27 20:28:31 UTC (rev 23115) +++ trunk/launchd/src/launchd_unix_ipc.h 2007-02-27 20:39:13 UTC (rev 23116) @@ -37,6 +37,7 @@ extern char *sockpath; void ipc_open(int fd, job_t j); +void ipc_close_all_with_job(job_t j); void ipc_close(struct conncb *c); void ipc_callback(void *, struct kevent *); void ipc_readmsg(launch_data_t msg, void *context); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070227/4c24270d/attachment.html From source_changes at macosforge.org Tue Feb 27 14:28:29 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23117] tags/launchd-199/ Message-ID: <20070227222829.9692A4BD29F@cvs.opensource.apple.com> Revision: 23117 http://trac.macosforge.org/projects/launchd/changeset/23117 Author: zarzycki@apple.com Date: 2007-02-27 14:28:29 -0800 (Tue, 27 Feb 2007) Log Message: ----------- "Tagging launchd-199 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-199/ Copied: tags/launchd-199 (from rev 23116, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070227/5e9196b8/attachment.html From source_changes at macosforge.org Wed Feb 28 15:39:19 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:42 2007 Subject: [launchd-changes] [23118] trunk/launchd/src Message-ID: <20070228233919.5357F4BEDE0@cvs.opensource.apple.com> Revision: 23118 http://trac.macosforge.org/projects/launchd/changeset/23118 Author: zarzycki@apple.com Date: 2007-02-28 15:39:18 -0800 (Wed, 28 Feb 2007) Log Message: ----------- Delete all code referring to /etc/rc.shutdown Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/SystemStarter.c trunk/launchd/src/com.apple.SystemStarter.plist Removed Paths: ------------- trunk/launchd/src/rc.shutdown Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-02-27 22:28:29 UTC (rev 23117) +++ trunk/launchd/src/Makefile.am 2007-02-28 23:39:18 UTC (rev 23118) @@ -34,7 +34,7 @@ sbin_PROGRAMS = launchd SystemStarter libexec_PROGRAMS = launchproxy -sysconf_DATA = hostconfig rc.common rc.netboot rc.shutdown +sysconf_DATA = hostconfig rc.common rc.netboot launchctl_CFLAGS = $(AM_CFLAGS) -I/System/Library/Frameworks/System.framework/PrivateHeaders launchctl_LDFLAGS = -framework CoreFoundation -framework IOKit -weak_library /usr/lib/libedit.dylib Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-02-27 22:28:29 UTC (rev 23117) +++ trunk/launchd/src/Makefile.in 2007-02-28 23:39:18 UTC (rev 23118) @@ -235,7 +235,7 @@ @LIBS_ONLY_TRUE@liblaunch_profile_a_CFLAGS = -pg $(AM_CFLAGS) @LIBS_ONLY_TRUE@liblaunch_profile_a_SOURCES = liblaunch.c libvproc.c libbootstrap.c protocol_vprocUser.c @LIBS_ONLY_FALSE@sbin_SCRIPTS = service -@LIBS_ONLY_FALSE@sysconf_DATA = hostconfig rc.common rc.netboot rc.shutdown +@LIBS_ONLY_FALSE@sysconf_DATA = hostconfig rc.common rc.netboot @LIBS_ONLY_FALSE@launchctl_CFLAGS = $(AM_CFLAGS) -I/System/Library/Frameworks/System.framework/PrivateHeaders @LIBS_ONLY_FALSE@launchctl_LDFLAGS = -framework CoreFoundation -framework IOKit -weak_library /usr/lib/libedit.dylib @LIBS_ONLY_FALSE@SystemStarter_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) Modified: trunk/launchd/src/SystemStarter.c =================================================================== --- trunk/launchd/src/SystemStarter.c 2007-02-27 22:28:29 UTC (rev 23117) +++ trunk/launchd/src/SystemStarter.c 2007-02-28 23:39:18 UTC (rev 23118) @@ -163,6 +163,12 @@ assert(r != -1); assert(kev.filter == EVFILT_SIGNAL && kev.ident == SIGTERM); + if (stat("/etc/rc.shutdown.local", &sb) != -1) { + const char *rc_shutdown_local_cmd[] = { "_PATH_BSHELL", "/etc/rc.shutdown.local", NULL }; + + fwexec(rc_shutdown_local_cmd, true); + } + system_starter(kActionStop, NULL); exit(EXIT_SUCCESS); Modified: trunk/launchd/src/com.apple.SystemStarter.plist =================================================================== --- trunk/launchd/src/com.apple.SystemStarter.plist 2007-02-27 22:28:29 UTC (rev 23117) +++ trunk/launchd/src/com.apple.SystemStarter.plist 2007-02-28 23:39:18 UTC (rev 23118) @@ -12,6 +12,8 @@ /etc/rc.local + /etc/rc.shutdown.local + QueueDirectories Deleted: trunk/launchd/src/rc.shutdown =================================================================== --- trunk/launchd/src/rc.shutdown 2007-02-27 22:28:29 UTC (rev 23117) +++ trunk/launchd/src/rc.shutdown 2007-02-28 23:39:18 UTC (rev 23118) @@ -1,8 +0,0 @@ -#!/bin/sh -# Copyright 1997-2004 Apple Computer, Inc. - -. /etc/rc.common - -if [ -f /etc/rc.shutdown.local ]; then - exec sh /etc/rc.shutdown.local -fi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20070228/3f76585d/attachment.html