From source_changes at macosforge.org Mon Oct 1 08:20:34 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:55 2007 Subject: [launchd-changes] [23433] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071001152034.7F4948206A9@cvs.opensource.apple.com> Revision: 23433 http://trac.macosforge.org/projects/launchd/changeset/23433 Author: zarzycki@apple.com Date: 2007-10-01 08:20:34 -0700 (Mon, 01 Oct 2007) Log Message: ----------- Bug: launchd_core_logic.c:3857 (23417):0: j->wait4pipe_eof 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-09-27 17:02:23 UTC (rev 23432) +++ trunk/launchd/src/launchd_core_logic.c 2007-10-01 15:20:34 UTC (rev 23433) @@ -2221,6 +2221,7 @@ job_log_stdouterr(job_t j) { char *msg, *bufindex, *buf = malloc(BIG_PIPE_SIZE + 1); + bool close_log_redir = false; ssize_t rsz; if (!job_assumes(j, buf != NULL)) { @@ -2233,10 +2234,10 @@ if (rsz == 0) { job_log(j, LOG_DEBUG, "Standard out/error pipe closed"); - job_assumes(j, runtime_close(j->log_redirect_fd) != -1); - j->log_redirect_fd = 0; - job_dispatch(j, false); - } else if (job_assumes(j, rsz != -1)) { + close_log_redir = true; + } else if (!job_assumes(j, rsz != -1)) { + close_log_redir = true; + } else { buf[rsz] = '\0'; while ((msg = strsep(&bufindex, "\n\r"))) { @@ -2247,6 +2248,12 @@ } free(buf); + + if (close_log_redir) { + job_assumes(j, runtime_close(j->log_redirect_fd) != -1); + j->log_redirect_fd = 0; + job_dispatch(j, false); + } } void @@ -3886,8 +3893,12 @@ } if (j->log_redirect_fd) { - job_assumes(j, j->wait4pipe_eof); - return "Standard out/error is still valid"; + if (job_assumes(j, j->wait4pipe_eof)) { + return "Standard out/error is still valid"; + } else { + job_assumes(j, runtime_close(j->log_redirect_fd) != -1); + j->log_redirect_fd = 0; + } } if (j->priv_port_has_senders) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071001/4805777d/attachment.html From source_changes at macosforge.org Mon Oct 1 13:10:59 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:55 2007 Subject: [launchd-changes] [23434] tags/launchd-257/ Message-ID: <20071001201059.0EA87820FB4@cvs.opensource.apple.com> Revision: 23434 http://trac.macosforge.org/projects/launchd/changeset/23434 Author: zarzycki@apple.com Date: 2007-10-01 13:10:58 -0700 (Mon, 01 Oct 2007) Log Message: ----------- "Tagging launchd-257 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-257/ Copied: tags/launchd-257 (from rev 23433, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071001/dcd6004e/attachment.html From source_changes at macosforge.org Thu Oct 4 13:39:01 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:55 2007 Subject: [launchd-changes] [23436] trunk/launchd/src/launchd_runtime.c Message-ID: <20071004203901.95E728379C1@cvs.opensource.apple.com> Revision: 23436 http://trac.macosforge.org/projects/launchd/changeset/23436 Author: zarzycki@apple.com Date: 2007-10-04 13:39:01 -0700 (Thu, 04 Oct 2007) Log Message: ----------- Bug: launchd_core_logic.c:4548 (23433):4: launchd_mport_notify_req(ms->port, which) == KERN_SUCCESS Modified Paths: -------------- trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-10-02 20:48:50 UTC (rev 23435) +++ trunk/launchd/src/launchd_runtime.c 2007-10-04 20:39:01 UTC (rev 23436) @@ -647,7 +647,7 @@ kern_return_t launchd_mport_notify_req(mach_port_t name, mach_msg_id_t which) { - mach_port_mscount_t msgc = (which == MACH_NOTIFY_NO_SENDERS) ? 1 : 0; + mach_port_mscount_t msgc = (which == MACH_NOTIFY_PORT_DESTROYED) ? 0 : 1; mach_port_t previous, where = (which == MACH_NOTIFY_NO_SENDERS) ? name : launchd_internal_port; if (which == MACH_NOTIFY_NO_SENDERS) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071004/6098a819/attachment.html From source_changes at macosforge.org Thu Oct 4 13:56:16 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:55 2007 Subject: [launchd-changes] [23437] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071004205616.4BB5D837AB5@cvs.opensource.apple.com> Revision: 23437 http://trac.macosforge.org/projects/launchd/changeset/23437 Author: zarzycki@apple.com Date: 2007-10-04 13:56:15 -0700 (Thu, 04 Oct 2007) Log Message: ----------- Bug: launchd_core_logic.c:6450 (23433):35: jr->p 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-10-04 20:39:01 UTC (rev 23436) +++ trunk/launchd/src/launchd_core_logic.c 2007-10-04 20:56:15 UTC (rev 23437) @@ -2515,6 +2515,11 @@ job_assumes(j, runtime_close(spair[0]) == 0); job_assumes(j, runtime_close(spair[1]) == 0); } + if (!j->legacy_mach_job) { + job_assumes(j, runtime_close(oepair[0]) != -1); + job_assumes(j, runtime_close(oepair[1]) != -1); + j->log_redirect_fd = 0; + } break; case 0: if (_vproc_post_fork_ping()) { @@ -6447,7 +6452,10 @@ return BOOTSTRAP_NO_MEMORY; } - job_assumes(jr, jr->p); + if (!job_assumes(jr, jr->p)) { + job_remove(jr); + return BOOTSTRAP_NO_MEMORY; + } if (!job_setup_machport(jr)) { job_remove(jr); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071004/6a326d68/attachment.html From source_changes at macosforge.org Fri Oct 5 13:31:10 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:55 2007 Subject: [launchd-changes] [23438] tags/launchd-258/ Message-ID: <20071005203110.C26988413D1@cvs.opensource.apple.com> Revision: 23438 http://trac.macosforge.org/projects/launchd/changeset/23438 Author: zarzycki@apple.com Date: 2007-10-05 13:31:10 -0700 (Fri, 05 Oct 2007) Log Message: ----------- "Tagging launchd-258 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-258/ Copied: tags/launchd-258 (from rev 23437, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071005/b0acff2e/attachment.html From source_changes at macosforge.org Mon Oct 8 09:27:14 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:55 2007 Subject: [launchd-changes] [23439] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071008162714.E66A784C170@cvs.opensource.apple.com> Revision: 23439 http://trac.macosforge.org/projects/launchd/changeset/23439 Author: zarzycki@apple.com Date: 2007-10-08 09:27:13 -0700 (Mon, 08 Oct 2007) Log Message: ----------- Just in case... 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-10-05 20:31:10 UTC (rev 23438) +++ trunk/launchd/src/launchd_core_logic.c 2007-10-08 16:27:13 UTC (rev 23439) @@ -4147,6 +4147,7 @@ * when the last PID dies and not wait for the associated resources to reset. */ if (getpid() == 1 && jm->parentmgr == NULL && total_children == 0) { + jobmgr_log_stray_children(jm); jobmgr_log(jm, LOG_DEBUG, "About to force a call to: reboot(%s)", reboot_flags_to_C_names(jm->reboot_flags)); runtime_closelog(); jobmgr_assumes(jm, reboot(jm->reboot_flags) != -1); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071008/c5c197ff/attachment.html From source_changes at macosforge.org Mon Oct 8 09:48:45 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:55 2007 Subject: [launchd-changes] [23440] trunk/launchd/src/launchd_runtime.c Message-ID: <20071008164845.CD0EF84C1AE@cvs.opensource.apple.com> Revision: 23440 http://trac.macosforge.org/projects/launchd/changeset/23440 Author: zarzycki@apple.com Date: 2007-10-08 09:48:45 -0700 (Mon, 08 Oct 2007) Log Message: ----------- Be more conservative about the cost of generating debug log messages Modified Paths: -------------- trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-10-08 16:27:13 UTC (rev 23439) +++ trunk/launchd/src/launchd_runtime.c 2007-10-08 16:48:45 UTC (rev 23440) @@ -115,6 +115,10 @@ }; static sigset_t sigign_set; +static int internal_mask_pri = LOG_UPTO(LOG_NOTICE); +//static int internal_mask_pri = LOG_UPTO(LOG_DEBUG); + + void launchd_runtime_init(void) { @@ -247,7 +251,7 @@ 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" +#define MAX_RB_STR "RB_ASKNAME|RB_SINGLE|RB_NOSYNC|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; @@ -263,7 +267,6 @@ 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) @@ -338,6 +341,10 @@ unsigned short flags = kev->flags; unsigned int fflags = kev->fflags; + if (!(LOG_MASK(level) & internal_mask_pri)) { + return; + } + if (flags) while (flags) { if (flags_off) { *flags_off = '|'; @@ -1118,9 +1125,6 @@ } } -static int internal_mask_pri = LOG_UPTO(LOG_NOTICE); -//static int internal_mask_pri = LOG_UPTO(LOG_DEBUG); - int runtime_setlogmask(int maskpri) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071008/f7c17fa5/attachment.html From source_changes at macosforge.org Tue Oct 2 13:48:50 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 9 16:25:55 2007 Subject: [launchd-changes] [23435] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071002204850.E5B21822FCB@cvs.opensource.apple.com> Revision: 23435 http://trac.macosforge.org/projects/launchd/changeset/23435 Author: zarzycki@apple.com Date: 2007-10-02 13:48:50 -0700 (Tue, 02 Oct 2007) Log Message: ----------- We meant to use 'jr' and not 'j' for this call. 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-10-01 20:10:58 UTC (rev 23434) +++ trunk/launchd/src/launchd_core_logic.c 2007-10-02 20:48:50 UTC (rev 23435) @@ -6454,7 +6454,7 @@ return BOOTSTRAP_NO_MEMORY; } - job_log(j, LOG_INFO, "Spawned"); + job_log(jr, LOG_DEBUG, "Spawned by PID %u: %s", j->p, j->label); *child_pid = jr->p; *obsvr_port = jr->j_port; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071002/10bd7ba4/attachment.html From source_changes at macosforge.org Fri Oct 12 13:26:35 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Sat Oct 13 17:32:01 2007 Subject: [launchd-changes] [23441] trunk/launchd/src/launchproxy.c Message-ID: <20071012202635.E8CB386D369@cvs.opensource.apple.com> Revision: 23441 http://trac.macosforge.org/projects/launchd/changeset/23441 Author: zarzycki@apple.com Date: 2007-10-12 13:26:35 -0700 (Fri, 12 Oct 2007) Log Message: ----------- rsh jobs wait for backgrounded processes Modified Paths: -------------- trunk/launchd/src/launchproxy.c Modified: trunk/launchd/src/launchproxy.c =================================================================== --- trunk/launchd/src/launchproxy.c 2007-10-08 16:48:45 UTC (rev 23440) +++ trunk/launchd/src/launchproxy.c 2007-10-12 20:26:35 UTC (rev 23441) @@ -194,6 +194,7 @@ } } fcntl(r, F_SETFL, 0); + fcntl(r, F_SETFD, 1); dup2(r, STDIN_FILENO); if (dupstdout) dup2(r, STDOUT_FILENO); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071012/0ebdc16a/attachment.html From source_changes at macosforge.org Tue Oct 23 08:29:04 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 23 08:38:42 2007 Subject: [launchd-changes] [23442] branches/SULeopard/ Message-ID: <20071023152904.7C9388F2DF9@cvs.opensource.apple.com> Revision: 23442 http://trac.macosforge.org/projects/launchd/changeset/23442 Author: zarzycki@apple.com Date: 2007-10-23 08:29:03 -0700 (Tue, 23 Oct 2007) Log Message: ----------- "Branch for SULeopard from https://svn.macosforge.org/repository/launchd/tags/launchd-258" Added Paths: ----------- branches/SULeopard/ Copied: branches/SULeopard (from rev 23441, tags/launchd-258) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071023/3608c6ef/attachment.html From source_changes at macosforge.org Tue Oct 23 08:40:55 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 23 08:51:00 2007 Subject: [launchd-changes] [23443] trunk/launchd/src Message-ID: <20071023154055.5732A8F2F00@cvs.opensource.apple.com> Revision: 23443 http://trac.macosforge.org/projects/launchd/changeset/23443 Author: zarzycki@apple.com Date: 2007-10-23 08:40:55 -0700 (Tue, 23 Oct 2007) Log Message: ----------- Short circuit MIG replies when forwarding queries. Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/protocol_job.defs Added Paths: ----------- trunk/launchd/src/protocol_job_forward.defs Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-10-23 15:29:03 UTC (rev 23442) +++ trunk/launchd/src/Makefile.am 2007-10-23 15:40:55 UTC (rev 23443) @@ -48,13 +48,16 @@ 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 protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.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_kill.c job_forwardUser.c launchd_runtime.c:: notifyServer.h launchd_internal.h -launchd_core_logic.c:: protocol_vproc.h job_reply.h protocol_vprocServer.h +launchd_core_logic.c:: protocol_vproc.h job_reply.h protocol_vprocServer.h job_forward.h launchproxy_LDFLAGS = -weak_framework Security +job_forwardUser.c job_forward.h: $(srcdir)/protocol_job_forward.defs + mig $(MIGFLAGS) -sheader /dev/null -server /dev/null $(srcdir)/protocol_job_forward.defs + notifyServer.c notifyServer.h: /usr/include/mach/notify.defs mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader notifyServer.h /usr/include/mach/notify.defs Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-10-23 15:29:03 UTC (rev 23442) +++ trunk/launchd/src/Makefile.in 2007-10-23 15:40:55 UTC (rev 23443) @@ -96,7 +96,8 @@ am__launchd_SOURCES_DIST = 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_kill.c + job_replyUser.c launchd_runtime.c launchd_runtime_kill.c \ + job_forwardUser.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) \ @@ -106,7 +107,8 @@ @LIBS_ONLY_FALSE@ launchd-launchd_internalServer.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-job_replyUser.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-launchd_runtime.$(OBJEXT) \ -@LIBS_ONLY_FALSE@ launchd-launchd_runtime_kill.$(OBJEXT) +@LIBS_ONLY_FALSE@ launchd-launchd_runtime_kill.$(OBJEXT) \ +@LIBS_ONLY_FALSE@ launchd-job_forwardUser.$(OBJEXT) launchd_OBJECTS = $(am_launchd_OBJECTS) launchd_LDADD = $(LDADD) launchd_LINK = $(CCLD) $(launchd_CFLAGS) $(CFLAGS) $(launchd_LDFLAGS) \ @@ -253,7 +255,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 protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.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 launchd_runtime_kill.c job_forwardUser.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 @@ -415,6 +417,7 @@ @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-job_forwardUser.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@ @@ -787,6 +790,20 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='launchd_runtime_kill.c' object='launchd-launchd_runtime_kill.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-launchd_runtime_kill.obj `if test -f 'launchd_runtime_kill.c'; then $(CYGPATH_W) 'launchd_runtime_kill.c'; else $(CYGPATH_W) '$(srcdir)/launchd_runtime_kill.c'; fi` + +launchd-job_forwardUser.o: job_forwardUser.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-job_forwardUser.o -MD -MP -MF $(DEPDIR)/launchd-job_forwardUser.Tpo -c -o launchd-job_forwardUser.o `test -f 'job_forwardUser.c' || echo '$(srcdir)/'`job_forwardUser.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/launchd-job_forwardUser.Tpo $(DEPDIR)/launchd-job_forwardUser.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='job_forwardUser.c' object='launchd-job_forwardUser.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-job_forwardUser.o `test -f 'job_forwardUser.c' || echo '$(srcdir)/'`job_forwardUser.c + +launchd-job_forwardUser.obj: job_forwardUser.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-job_forwardUser.obj -MD -MP -MF $(DEPDIR)/launchd-job_forwardUser.Tpo -c -o launchd-job_forwardUser.obj `if test -f 'job_forwardUser.c'; then $(CYGPATH_W) 'job_forwardUser.c'; else $(CYGPATH_W) '$(srcdir)/job_forwardUser.c'; fi` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/launchd-job_forwardUser.Tpo $(DEPDIR)/launchd-job_forwardUser.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='job_forwardUser.c' object='launchd-job_forwardUser.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-job_forwardUser.obj `if test -f 'job_forwardUser.c'; then $(CYGPATH_W) 'job_forwardUser.c'; else $(CYGPATH_W) '$(srcdir)/job_forwardUser.c'; fi` install-man1: $(man1_MANS) $(man_MANS) @$(NORMAL_INSTALL) test -z "$(man1dir)" || $(MKDIR_P) "$(DESTDIR)$(man1dir)" @@ -1149,8 +1166,11 @@ @LIBS_ONLY_TRUE@ cp liblaunch_profile.a $(DESTDIR)/usr/local/lib/system/liblaunch_profile.a @LIBS_ONLY_FALSE@launchd_runtime.c:: notifyServer.h launchd_internal.h -@LIBS_ONLY_FALSE@launchd_core_logic.c:: protocol_vproc.h job_reply.h protocol_vprocServer.h +@LIBS_ONLY_FALSE@launchd_core_logic.c:: protocol_vproc.h job_reply.h protocol_vprocServer.h job_forward.h +@LIBS_ONLY_FALSE@job_forwardUser.c job_forward.h: $(srcdir)/protocol_job_forward.defs +@LIBS_ONLY_FALSE@ mig $(MIGFLAGS) -sheader /dev/null -server /dev/null $(srcdir)/protocol_job_forward.defs + @LIBS_ONLY_FALSE@notifyServer.c notifyServer.h: /usr/include/mach/notify.defs @LIBS_ONLY_FALSE@ mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader notifyServer.h /usr/include/mach/notify.defs Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-10-23 15:29:03 UTC (rev 23442) +++ trunk/launchd/src/launchd_core_logic.c 2007-10-23 15:40:55 UTC (rev 23443) @@ -91,6 +91,7 @@ #include "protocol_vproc.h" #include "protocol_vprocServer.h" #include "job_reply.h" +#include "job_forward.h" #define LAUNCHD_MIN_JOB_RUN_TIME 10 #define LAUNCHD_DEFAULT_EXIT_TIMEOUT 20 @@ -5741,7 +5742,7 @@ } kern_return_t -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) +job_mig_look_up2(job_t j, mach_port_t srp, name_t servicename, mach_port_t *serviceportp, pid_t target_pid, uint64_t flags) { struct machservice *ms; struct ldcred ldc; @@ -5788,12 +5789,12 @@ j->lastlookup_gennum = ms->gen_num; #endif *serviceportp = machservice_port(ms); - *ptype = MACH_MSG_TYPE_COPY_SEND; kr = BOOTSTRAP_SUCCESS; } else if (!(flags & BOOTSTRAP_PER_PID_SERVICE) && (inherited_bootstrap_port != MACH_PORT_NULL)) { job_log(j, LOG_DEBUG, "Mach service lookup forwarded: %s", servicename); - *ptype = MACH_MSG_TYPE_MOVE_SEND; - kr = bootstrap_look_up(inherited_bootstrap_port, servicename, serviceportp); + job_assumes(j, vproc_mig_look_up2_forward(inherited_bootstrap_port, srp, servicename, 0, 0) == 0); + /* The previous routine moved the reply port, we're forced to return MIG_NO_REPLY now */ + return MIG_NO_REPLY; } else if (getpid() == 1 && j->anonymous && ldc.euid >= 500 && strcasecmp(job_get_bs(j)->name, VPROCMGR_SESSION_LOGINWINDOW) == 0) { /* * 5240036 Should start background session when a lookup of CCacheServer occurs @@ -5811,7 +5812,7 @@ } kern_return_t -job_mig_parent(job_t j, mach_port_t *parentport, mach_msg_type_name_t *pptype) +job_mig_parent(job_t j, mach_port_t srp, mach_port_t *parentport) { if (!launchd_assumes(j != NULL)) { return BOOTSTRAP_NO_MEMORY; @@ -5820,15 +5821,14 @@ job_log(j, LOG_DEBUG, "Requested parent bootstrap port"); jobmgr_t jm = j->mgr; - *pptype = MACH_MSG_TYPE_MAKE_SEND; - if (jobmgr_parent(jm)) { *parentport = jobmgr_parent(jm)->jm_port; } else if (MACH_PORT_NULL == inherited_bootstrap_port) { *parentport = jm->jm_port; } else { - *pptype = MACH_MSG_TYPE_COPY_SEND; - *parentport = inherited_bootstrap_port; + job_assumes(j, vproc_mig_parent_forward(inherited_bootstrap_port, srp) == 0); + /* The previous routine moved the reply port, we're forced to return MIG_NO_REPLY now */ + return MIG_NO_REPLY; } return BOOTSTRAP_SUCCESS; } Modified: trunk/launchd/src/protocol_job.defs =================================================================== --- trunk/launchd/src/protocol_job.defs 2007-10-23 15:29:03 UTC (rev 23442) +++ trunk/launchd/src/protocol_job.defs 2007-10-23 15:40:55 UTC (rev 23443) @@ -63,8 +63,9 @@ routine look_up2( __bs_port : job_t; + sreplyport __rport : mach_port_make_send_once_t; __service_name : name_t; - out __service_port : mach_port_send_t; + out __service_port : mach_port_t; __target_pid : pid_t; __flags : uint64_t); @@ -76,7 +77,8 @@ routine parent( __bs_port : job_t; - out __parent_port : mach_port_send_t); + sreplyport __rport : mach_port_make_send_once_t; + out __parent_port : mach_port_make_send_t); routine post_fork_ping( __bs_port : job_t; Added: trunk/launchd/src/protocol_job_forward.defs =================================================================== --- trunk/launchd/src/protocol_job_forward.defs (rev 0) +++ trunk/launchd/src/protocol_job_forward.defs 2007-10-23 15:40:55 UTC (rev 23443) @@ -0,0 +1,53 @@ +/* + * 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@ + */ + +subsystem job_forward 400; + +#include +#include +#include "launchd_mig_types.defs" +import "libvproc_public.h"; +import "libvproc_private.h"; +import "libvproc_internal.h"; + +userprefix vproc_mig_; +serverprefix job_mig_; + +skip; /* create_server */ + +skip; /* reboot2 */ + +skip; /* check_in */ + +skip; /* register2 */ + +simpleroutine look_up2_forward( + __bs_port : job_t; + replyport __rport : mach_port_move_send_once_t; + __service_name : name_t; + __target_pid : pid_t; + __flags : uint64_t); + +skip; /* send_signal */ + +simpleroutine parent_forward( + __bs_port : job_t; + replyport __rport : mach_port_move_send_once_t); + -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071023/4c2c5881/attachment-0001.html From source_changes at macosforge.org Tue Oct 23 08:41:40 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 23 08:51:17 2007 Subject: [launchd-changes] [23444] trunk/launchd/src Message-ID: <20071023154140.0244C8F2F10@cvs.opensource.apple.com> Revision: 23444 http://trac.macosforge.org/projects/launchd/changeset/23444 Author: zarzycki@apple.com Date: 2007-10-23 08:41:39 -0700 (Tue, 23 Oct 2007) Log Message: ----------- Misc updates. Modified Paths: -------------- trunk/launchd/src/launchd_runtime.c trunk/launchd/src/launchd_runtime.h Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-10-23 15:40:55 UTC (rev 23443) +++ trunk/launchd/src/launchd_runtime.c 2007-10-23 15:41:39 UTC (rev 23444) @@ -959,7 +959,7 @@ audit_token_to_au32(*au_tok, /* audit UID */ NULL, &ldc->euid, &ldc->egid, &ldc->uid, &ldc->gid, &ldc->pid, - &ldc->asid, /* au_tid_t */ NULL); + /* au_asid_t */ NULL, /* au_tid_t */ NULL); return true; } Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2007-10-23 15:40:55 UTC (rev 23443) +++ trunk/launchd/src/launchd_runtime.h 2007-10-23 15:41:39 UTC (rev 23444) @@ -24,17 +24,59 @@ #include #include #include +#include +#include #include #include "launchd_runtime_kill.h" +#if 0 + +/* I need to do more testing of these macros */ + +#define min_of_type(x) \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), long double), LDBL_MIN, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), double), DBL_MIN, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), float), FLT_MIN, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), char), 0, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), signed char), INT8_MIN, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), short), INT16_MIN, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), int), INT32_MIN, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), long), (__builtin_choose_expr(sizeof(x) == 4, INT32_MIN, INT64_MIN)), \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), long long), INT64_MIN, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), unsigned char), 0, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), unsigned short), 0, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), unsigned int), 0, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), unsigned long), 0, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), unsigned long long), 0, \ + (void)0)))))))))))))) + +#define max_of_type(x) \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), long double), LDBL_MAX, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), double), DBL_MAX, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), float), FLT_MAX, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), char), UINT8_MAX, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), signed char), INT8_MAX, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), short), INT16_MIN, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), int), INT32_MAX, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), long), (__builtin_choose_expr(sizeof(x) == 4, INT32_MAX, INT64_MAX)), \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), long long), INT64_MAX, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), unsigned char), UINT8_MAX, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), unsigned short), UINT16_MAX, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), unsigned int), UINT32_MAX, \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), unsigned long), (__builtin_choose_expr(sizeof(x) == 4, UINT32_MAX, UINT64_MAX)), \ + __builtin_choose_expr(__builtin_types_compatible_p(typeof(x), unsigned long long), UINT64_MAX, \ + (void)0)))))))))))))) + +#endif + + struct ldcred { uid_t euid; uid_t uid; gid_t egid; gid_t gid; pid_t pid; - au_asid_t asid; }; /* -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071023/7736a2e2/attachment.html From source_changes at macosforge.org Tue Oct 23 08:47:02 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 23 08:56:40 2007 Subject: [launchd-changes] [23445] trunk/launchd/src Message-ID: <20071023154702.3769B8F30E4@cvs.opensource.apple.com> Revision: 23445 http://trac.macosforge.org/projects/launchd/changeset/23445 Author: zarzycki@apple.com Date: 2007-10-23 08:47:01 -0700 (Tue, 23 Oct 2007) Log Message: ----------- ER: Provide a way for launchd to NULL out a tasks exception report when launched Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c trunk/launchd/src/launchd_runtime.h trunk/launchd/src/liblaunch_private.h Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-10-23 15:41:39 UTC (rev 23444) +++ trunk/launchd/src/Makefile.am 2007-10-23 15:47:01 UTC (rev 23445) @@ -2,7 +2,7 @@ CLEANFILES = protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h \ launchd_internal.h launchd_internalServer.h launchd_internalServer.c launchd_internalUser.c \ - notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c + notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c mach_excServer.c mach_excServer.h protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h: $(srcdir)/protocol_job.defs mig $(MIGFLAGS) -sheader protocol_vprocServer.h $(srcdir)/protocol_job.defs @@ -48,9 +48,9 @@ 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 protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.c job_forwardUser.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_kill.c job_forwardUser.c mach_excServer.c -launchd_runtime.c:: notifyServer.h launchd_internal.h +launchd_runtime.c:: notifyServer.h launchd_internal.h mach_excServer.h launchd_core_logic.c:: protocol_vproc.h job_reply.h protocol_vprocServer.h job_forward.h launchproxy_LDFLAGS = -weak_framework Security @@ -61,6 +61,9 @@ notifyServer.c notifyServer.h: /usr/include/mach/notify.defs mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader notifyServer.h /usr/include/mach/notify.defs +mach_excServer.c mach_excServer.h: /usr/include/mach/mach_exc.defs + mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader mach_excServer.h /usr/include/mach/mach_exc.defs + job_replyUser.c job_reply.h: $(srcdir)/protocol_job_reply.defs mig $(MIGFLAGS) -sheader /dev/null -server /dev/null $(srcdir)/protocol_job_reply.defs Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-10-23 15:41:39 UTC (rev 23444) +++ trunk/launchd/src/Makefile.in 2007-10-23 15:47:01 UTC (rev 23445) @@ -97,7 +97,7 @@ launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c \ launchd_internalUser.c launchd_internalServer.c \ job_replyUser.c launchd_runtime.c launchd_runtime_kill.c \ - job_forwardUser.c + job_forwardUser.c mach_excServer.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) \ @@ -108,7 +108,8 @@ @LIBS_ONLY_FALSE@ launchd-job_replyUser.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-launchd_runtime.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-launchd_runtime_kill.$(OBJEXT) \ -@LIBS_ONLY_FALSE@ launchd-job_forwardUser.$(OBJEXT) +@LIBS_ONLY_FALSE@ launchd-job_forwardUser.$(OBJEXT) \ +@LIBS_ONLY_FALSE@ launchd-mach_excServer.$(OBJEXT) launchd_OBJECTS = $(am_launchd_OBJECTS) launchd_LDADD = $(LDADD) launchd_LINK = $(CCLD) $(launchd_CFLAGS) $(CFLAGS) $(launchd_LDFLAGS) \ @@ -240,7 +241,7 @@ AM_CFLAGS = -no-cpp-precomp -F/System/Library/PrivateFrameworks -Wall -Wextra -Waggregate-return -Wshadow -Wmissing-prototypes -Wmissing-declarations -Werror -D__MigTypeCheck=1 -fvisibility=hidden -Dmig_external=__private_extern__ CLEANFILES = protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h \ launchd_internal.h launchd_internalServer.h launchd_internalServer.c launchd_internalUser.c \ - notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c + notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c mach_excServer.c mach_excServer.h @LIBS_ONLY_TRUE@noinst_LIBRARIES = liblaunch.a liblaunch_profile.a @LIBS_ONLY_TRUE@liblaunch_a_CFLAGS = -D__DARWIN_NON_CANCELABLE=1 $(AM_CFLAGS) @@ -255,7 +256,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 protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.c job_forwardUser.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 launchd_runtime_kill.c job_forwardUser.c mach_excServer.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 @@ -426,6 +427,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-launchd_runtime.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-launchd_runtime_kill.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-launchd_unix_ipc.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-mach_excServer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-notifyServer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-protocol_vprocServer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchproxy.Po@am__quote@ @@ -804,6 +806,20 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='job_forwardUser.c' object='launchd-job_forwardUser.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-job_forwardUser.obj `if test -f 'job_forwardUser.c'; then $(CYGPATH_W) 'job_forwardUser.c'; else $(CYGPATH_W) '$(srcdir)/job_forwardUser.c'; fi` + +launchd-mach_excServer.o: mach_excServer.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-mach_excServer.o -MD -MP -MF $(DEPDIR)/launchd-mach_excServer.Tpo -c -o launchd-mach_excServer.o `test -f 'mach_excServer.c' || echo '$(srcdir)/'`mach_excServer.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/launchd-mach_excServer.Tpo $(DEPDIR)/launchd-mach_excServer.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='mach_excServer.c' object='launchd-mach_excServer.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-mach_excServer.o `test -f 'mach_excServer.c' || echo '$(srcdir)/'`mach_excServer.c + +launchd-mach_excServer.obj: mach_excServer.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-mach_excServer.obj -MD -MP -MF $(DEPDIR)/launchd-mach_excServer.Tpo -c -o launchd-mach_excServer.obj `if test -f 'mach_excServer.c'; then $(CYGPATH_W) 'mach_excServer.c'; else $(CYGPATH_W) '$(srcdir)/mach_excServer.c'; fi` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/launchd-mach_excServer.Tpo $(DEPDIR)/launchd-mach_excServer.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='mach_excServer.c' object='launchd-mach_excServer.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-mach_excServer.obj `if test -f 'mach_excServer.c'; then $(CYGPATH_W) 'mach_excServer.c'; else $(CYGPATH_W) '$(srcdir)/mach_excServer.c'; fi` install-man1: $(man1_MANS) $(man_MANS) @$(NORMAL_INSTALL) test -z "$(man1dir)" || $(MKDIR_P) "$(DESTDIR)$(man1dir)" @@ -1165,7 +1181,7 @@ @LIBS_ONLY_TRUE@ cp liblaunch.a $(DESTDIR)/usr/local/lib/system/liblaunch_debug.a @LIBS_ONLY_TRUE@ cp liblaunch_profile.a $(DESTDIR)/usr/local/lib/system/liblaunch_profile.a -@LIBS_ONLY_FALSE@launchd_runtime.c:: notifyServer.h launchd_internal.h +@LIBS_ONLY_FALSE@launchd_runtime.c:: notifyServer.h launchd_internal.h mach_excServer.h @LIBS_ONLY_FALSE@launchd_core_logic.c:: protocol_vproc.h job_reply.h protocol_vprocServer.h job_forward.h @LIBS_ONLY_FALSE@job_forwardUser.c job_forward.h: $(srcdir)/protocol_job_forward.defs @@ -1174,6 +1190,9 @@ @LIBS_ONLY_FALSE@notifyServer.c notifyServer.h: /usr/include/mach/notify.defs @LIBS_ONLY_FALSE@ mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader notifyServer.h /usr/include/mach/notify.defs +@LIBS_ONLY_FALSE@mach_excServer.c mach_excServer.h: /usr/include/mach/mach_exc.defs +@LIBS_ONLY_FALSE@ mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader mach_excServer.h /usr/include/mach/mach_exc.defs + @LIBS_ONLY_FALSE@job_replyUser.c job_reply.h: $(srcdir)/protocol_job_reply.defs @LIBS_ONLY_FALSE@ mig $(MIGFLAGS) -sheader /dev/null -server /dev/null $(srcdir)/protocol_job_reply.defs Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-10-23 15:41:39 UTC (rev 23444) +++ trunk/launchd/src/launchd_core_logic.c 2007-10-23 15:47:01 UTC (rev 23445) @@ -334,6 +334,7 @@ char *groupname; char *stdoutpath; char *stderrpath; + char *alt_exc_handler; struct machservice *lastlookup; unsigned int lastlookup_gennum; char *seatbelt_profile; @@ -361,7 +362,7 @@ currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1, hopefully_exits_last:1, removal_pending:1, wait4pipe_eof:1, sent_sigkill:1, debug_before_kill:1, weird_bootstrap:1, start_on_mount:1, per_user:1, hopefully_exits_first:1, deny_unknown_mslookups:1, unload_at_mig_return:1, abandon_pg:1, - poll_for_vfs_changes:1; + poll_for_vfs_changes:1, internal_exc_handler:1; const char label[0]; }; @@ -862,6 +863,9 @@ if (j->stderrpath) { free(j->stderrpath); } + if (j->alt_exc_handler) { + free(j->alt_exc_handler); + } if (j->seatbelt_profile) { free(j->seatbelt_profile); } @@ -1324,6 +1328,13 @@ found_key = true; } break; + case 'm': + case 'M': + if (strcasecmp(key, LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER) == 0) { + j->internal_exc_handler = value; + found_key = true; + } + break; case 'i': case 'I': if (strcasecmp(key, LAUNCH_JOBKEY_INITGROUPS) == 0) { @@ -1377,6 +1388,12 @@ char **where2put = NULL; switch (key[0]) { + case 'm': + case 'M': + if (strcasecmp(key, LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER) == 0) { + where2put = &j->alt_exc_handler; + } + break; case 'p': case 'P': if (strcasecmp(key, LAUNCH_JOBKEY_PROGRAM) == 0) { @@ -4003,9 +4020,20 @@ void job_setup_exception_port(job_t j, task_t target_task) { + struct machservice *ms; thread_state_flavor_t f = 0; + mach_port_t exc_port = the_exception_server; - if (!the_exception_server) { + if (j->alt_exc_handler) { + ms = jobmgr_lookup_service(j->mgr, j->alt_exc_handler, true, 0); + if (ms) { + exc_port = machservice_port(ms); + } else { + job_log(j, LOG_WARNING, "Falling back to default Mach exception handler. Could not find: %s", j->alt_exc_handler); + } + } else if (j->internal_exc_handler) { + exc_port = runtime_get_kernel_port(); + } else if (!exc_port) { return; } @@ -4016,9 +4044,9 @@ #endif if (target_task) { - job_assumes(j, task_set_exception_ports(target_task, EXC_MASK_CRASH, the_exception_server, + job_assumes(j, task_set_exception_ports(target_task, EXC_MASK_CRASH, exc_port, EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); - } else if (getpid() == 1) { + } else if (getpid() == 1 && the_exception_server) { mach_port_t mhp = mach_host_self(); job_assumes(j, host_set_exception_ports(mhp, EXC_MASK_CRASH, the_exception_server, EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-10-23 15:41:39 UTC (rev 23444) +++ trunk/launchd/src/launchd_runtime.c 2007-10-23 15:47:01 UTC (rev 23445) @@ -61,6 +61,7 @@ #include "launchd_internalServer.h" #include "launchd_internal.h" #include "notifyServer.h" +#include "mach_excServer.h" /* We shouldn't be including these */ #include "launch.h" @@ -86,6 +87,7 @@ static void *kqueue_demand_loop(void *arg); static void log_kevent_struct(int level, struct kevent *kev, int indx); +static boolean_t launchd_internal_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply); static void record_caller_creds(mach_msg_header_t *mh); static void launchd_runtime2(mach_msg_size_t msg_size, mig_reply_error_t *bufRequest, mig_reply_error_t *bufReply); static mach_msg_size_t max_msg_size; @@ -115,6 +117,12 @@ }; static sigset_t sigign_set; +mach_port_t +runtime_get_kernel_port(void) +{ + return launchd_internal_port; +} + static int internal_mask_pri = LOG_UPTO(LOG_NOTICE); //static int internal_mask_pri = LOG_UPTO(LOG_DEBUG); @@ -850,9 +858,11 @@ { if (launchd_internal_server_routine(Request)) { return launchd_internal_server(Request, Reply); + } else if (notify_server_routine(Request)) { + return notify_server(Request, Reply); + } else { + return mach_exc_server(Request, Reply); } - - return notify_server(Request, Reply); } kern_return_t @@ -1451,3 +1461,57 @@ { runtime_busy_cnt--; } + +kern_return_t +catch_mach_exception_raise(mach_port_t exception_port, mach_port_t thread, mach_port_t task, + exception_type_t exception, mach_exception_data_t code, mach_msg_type_number_t codeCnt) +{ + pid_t p4t = -1; + + launchd_assumes(pid_for_task(task, &p4t) == 0); + + runtime_syslog(LOG_NOTICE, "%s(): PID: %u thread: 0x%x type: 0x%x code: %p codeCnt: 0x%x", + __func__, p4t, thread, exception, code, codeCnt); + + launchd_assumes(launchd_mport_deallocate(thread) == KERN_SUCCESS); + launchd_assumes(launchd_mport_deallocate(task) == KERN_SUCCESS); + + return 0; +} + +kern_return_t +catch_mach_exception_raise_state(mach_port_t exception_port, + exception_type_t exception, const mach_exception_data_t code, mach_msg_type_number_t codeCnt, + int *flavor, const thread_state_t old_state, mach_msg_type_number_t old_stateCnt, + thread_state_t new_state, mach_msg_type_number_t *new_stateCnt) +{ + runtime_syslog(LOG_NOTICE, "%s(): type: 0x%x code: %p codeCnt: 0x%x flavor: %p old_state: %p old_stateCnt: 0x%x new_state: %p new_stateCnt: %p", + __func__, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); + + memcpy(new_state, old_state, old_stateCnt * sizeof(old_state[0])); + *new_stateCnt = old_stateCnt; + + return 0; +} + +kern_return_t +catch_mach_exception_raise_state_identity(mach_port_t exception_port, mach_port_t thread, mach_port_t task, + exception_type_t exception, mach_exception_data_t code, mach_msg_type_number_t codeCnt, + int *flavor, thread_state_t old_state, mach_msg_type_number_t old_stateCnt, + thread_state_t new_state, mach_msg_type_number_t *new_stateCnt) +{ + pid_t p4t = -1; + + launchd_assumes(pid_for_task(task, &p4t) == 0); + + runtime_syslog(LOG_NOTICE, "%s(): PID: %u thread: 0x%x type: 0x%x code: %p codeCnt: 0x%x flavor: %p old_state: %p old_stateCnt: 0x%x new_state: %p new_stateCnt: %p", + __func__, p4t, thread, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); + + memcpy(new_state, old_state, old_stateCnt * sizeof(old_state[0])); + *new_stateCnt = old_stateCnt; + + launchd_assumes(launchd_mport_deallocate(thread) == KERN_SUCCESS); + launchd_assumes(launchd_mport_deallocate(task) == KERN_SUCCESS); + + return 0; +} Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2007-10-23 15:41:39 UTC (rev 23444) +++ trunk/launchd/src/launchd_runtime.h 2007-10-23 15:47:01 UTC (rev 23445) @@ -98,7 +98,7 @@ typedef boolean_t (*mig_callback)(mach_msg_header_t *, mach_msg_header_t *); typedef void (*timeout_callback)(void); -boolean_t launchd_internal_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply); +mach_port_t runtime_get_kernel_port(void); void runtime_add_ref(void); void runtime_del_ref(void); Modified: trunk/launchd/src/liblaunch_private.h =================================================================== --- trunk/launchd/src/liblaunch_private.h 2007-10-23 15:41:39 UTC (rev 23444) +++ trunk/launchd/src/liblaunch_private.h 2007-10-23 15:47:01 UTC (rev 23445) @@ -55,6 +55,7 @@ #define LAUNCH_JOBKEY_PERJOBMACHSERVICES "PerJobMachServices" #define LAUNCH_JOBKEY_SERVICEIPC "ServiceIPC" #define LAUNCH_JOBKEY_BINARYORDERPREFERENCE "BinaryOrderPreference" +#define LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER "MachExceptionHandler" #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/20071023/ceb1fa96/attachment-0001.html From source_changes at macosforge.org Tue Oct 23 13:37:24 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 23 13:47:03 2007 Subject: [launchd-changes] [23446] trunk/launchd/src Message-ID: <20071023203724.4E9AE8F4081@cvs.opensource.apple.com> Revision: 23446 http://trac.macosforge.org/projects/launchd/changeset/23446 Author: zarzycki@apple.com Date: 2007-10-23 13:37:23 -0700 (Tue, 23 Oct 2007) Log Message: ----------- Aggressive logging. Modified Paths: -------------- trunk/launchd/src/launchctl.c trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-10-23 15:47:01 UTC (rev 23445) +++ trunk/launchd/src/launchctl.c 2007-10-23 20:37:23 UTC (rev 23446) @@ -74,8 +74,11 @@ #include #include #include +#include +extern char **environ; + #define LAUNCH_SECDIR "/tmp/launch-XXXXXX" #define MACHINIT_JOBKEY_ONDEMAND "OnDemand" @@ -132,7 +135,7 @@ static void _log_launchctl_bug(const char *rcs_rev, const char *path, unsigned int line, const char *test); static void loopback_setup_ipv4(void); static void loopback_setup_ipv6(void); -static pid_t fwexec(const char *const *argv, bool _wait); +static pid_t fwexec(const char *const *argv, int *wstatus); static void do_potential_fsck(void); static bool path_check(const char *path); static bool is_safeboot(void); @@ -1404,19 +1407,19 @@ if (path_check("/etc/rc.server")) { const char *rcserver_tool[] = { _PATH_BSHELL, "/etc/rc.server", NULL }; - assumes(fwexec(rcserver_tool, true) != -1); + assumes(fwexec(rcserver_tool, NULL) != -1); } apply_sysctls_from_file("/etc/sysctl.conf"); if (path_check("/etc/rc.cdrom")) { const char *rccdrom_tool[] = { _PATH_BSHELL, "/etc/rc.cdrom", "multiuser", NULL }; - assumes(fwexec(rccdrom_tool, true) != -1); + assumes(fwexec(rccdrom_tool, NULL) != -1); assumes(reboot(RB_HALT) != -1); _exit(EXIT_FAILURE); } else if (is_netboot()) { const char *rcnetboot_tool[] = { _PATH_BSHELL, "/etc/rc.netboot", "init", NULL }; - if (!assumes(fwexec(rcnetboot_tool, true) != -1)) { + if (!assumes(fwexec(rcnetboot_tool, NULL) != -1)) { assumes(reboot(RB_HALT) != -1); _exit(EXIT_FAILURE); } @@ -1432,12 +1435,12 @@ if (path_check("/etc/fstab")) { const char *mount_tool[] = { "mount", "-vat", "nonfs", NULL }; - assumes(fwexec(mount_tool, true) != -1); + assumes(fwexec(mount_tool, NULL) != -1); } if (path_check("/etc/rc.installer_cleanup")) { const char *rccleanup_tool[] = { _PATH_BSHELL, "/etc/rc.installer_cleanup", "multiuser", NULL }; - assumes(fwexec(rccleanup_tool, true) != -1); + assumes(fwexec(rccleanup_tool, NULL) != -1); } empty_dir(_PATH_VARRUN, NULL); @@ -1446,7 +1449,7 @@ if (path_check("/usr/libexec/dirhelper")) { const char *dirhelper_tool[] = { "/usr/libexec/dirhelper", "-machineBoot", NULL }; - assumes(fwexec(dirhelper_tool, true) != -1); + assumes(fwexec(dirhelper_tool, NULL) != -1); } assumes(touch_file(_PATH_UTMPX, DEFFILEMODE) != -1); @@ -1454,7 +1457,7 @@ if (path_check("/etc/security/rc.audit")) { const char *audit_tool[] = { _PATH_BSHELL, "/etc/security/rc.audit", NULL }; - assumes(fwexec(audit_tool, true) != -1); + assumes(fwexec(audit_tool, NULL) != -1); } do_BootCache_magic(BOOTCACHE_START); @@ -1553,7 +1556,7 @@ return; } - fwexec(bcc_tool, true); + fwexec(bcc_tool, NULL); } int @@ -2556,7 +2559,7 @@ setgid(getgid()); setuid(getuid()); - if (fwexec((const char *const *)argv + 2, true) == -1) { + if (fwexec((const char *const *)argv + 2, NULL) == -1) { fprintf(stderr, "%s bsexec failed: %s\n", getprogname(), strerror(errno)); return 1; } @@ -2703,31 +2706,27 @@ } pid_t -fwexec(const char *const *argv, bool _wait) +fwexec(const char *const *argv, int *wstatus) { - int wstatus; + int wstatus2; pid_t p; - switch ((p = fork())) { - case -1: - break; - case 0: - if (!_wait) { - setsid(); - } - execvp(argv[0], (char *const *)argv); - _exit(EXIT_FAILURE); - break; - default: - if (!_wait) - return p; - if (p == waitpid(p, &wstatus, 0)) { - if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == EXIT_SUCCESS) - return p; - } - break; + errno = posix_spawnp(&p, argv[0], NULL, NULL, (char **)argv, environ); + + if (errno) { + return -1; } + if (waitpid(p, wstatus ? wstatus : &wstatus2, 0) == -1) { + return -1; + } + + if (wstatus) { + return p; + } else if (WIFEXITED(wstatus2) && WEXITSTATUS(wstatus2) == EXIT_SUCCESS) { + return p; + } + return -1; } @@ -2755,12 +2754,12 @@ } #endif - if (fwexec(fsck_tool, true) != -1) { + if (fwexec(fsck_tool, NULL) != -1) { goto out; } } - if (fwexec(safe_fsck_tool, true) != -1) { + if (fwexec(safe_fsck_tool, NULL) != -1) { goto out; } @@ -2778,7 +2777,7 @@ * assumes(mount(sfs.f_fstypename, "/", MNT_UPDATE, NULL) != -1); */ - assumes(fwexec(remount_tool, true) != -1); + assumes(fwexec(remount_tool, NULL) != -1); } bool @@ -2930,7 +2929,7 @@ goto skip_sysctl_tool; } sysctl_tool[2] = val; - assumes(fwexec(sysctl_tool, true) != -1); + assumes(fwexec(sysctl_tool, NULL) != -1); skip_sysctl_tool: free(tmpstr); } @@ -3097,14 +3096,10 @@ CFRelease(bootrootProp); - if (!assumes((p = fwexec(kextcache_tool, false)) != -1)) { + if (!assumes((p = fwexec(kextcache_tool, &wstatus)) != -1)) { return; } - if (!assumes(waitpid(p, &wstatus, 0) != -1)) { - return; - } - if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == EX_OSFILE) { assumes(reboot(RB_AUTOBOOT) != -1); } Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-10-23 15:47:01 UTC (rev 23445) +++ trunk/launchd/src/launchd_core_logic.c 2007-10-23 20:37:23 UTC (rev 23446) @@ -132,7 +132,6 @@ LIST_ENTRY(machservice) name_hash_sle; LIST_ENTRY(machservice) port_hash_sle; job_t job; - uint64_t bad_perf_cnt; unsigned int gen_num; mach_port_name_t port; unsigned int isActive:1, reset:1, recv:1, hide:1, kUNCServer:1, per_user_hack:1, debug_on_close:1, per_pid:1, special_port_num:10; @@ -358,11 +357,11 @@ 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, start_pending:1; mode_t mask; - unsigned int globargv:1, wait4debugger:1, unload_at_exit:1, stall_before_exec:1, only_once:1, + unsigned int globargv:1, wait4debugger:1, internal_exc_handler:1, stall_before_exec:1, only_once:1, currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1, hopefully_exits_last:1, removal_pending:1, - wait4pipe_eof:1, sent_sigkill:1, debug_before_kill:1, weird_bootstrap:1, start_on_mount:1, + legacy_LS_job:1, sent_sigkill:1, debug_before_kill:1, weird_bootstrap:1, start_on_mount:1, per_user:1, hopefully_exits_first:1, deny_unknown_mslookups:1, unload_at_mig_return:1, abandon_pg:1, - poll_for_vfs_changes:1, internal_exc_handler:1; + poll_for_vfs_changes:1; const char label[0]; }; @@ -396,7 +395,7 @@ static bool job_setup_machport(job_t j); static void job_setup_fd(job_t j, int target_fd, const char *path, int flags); static void job_postfork_become_user(job_t j); -static void job_find_and_blame_pids_with_weird_uids(job_t j); +static void job_log_pids_with_weird_uids(job_t j); static void job_force_sampletool(job_t j); static void job_setup_exception_port(job_t j, task_t target_task); static void job_reparent_hack(job_t j, const char *where); @@ -405,6 +404,7 @@ static void job_callback_timer(job_t j, void *ident); static void job_callback_read(job_t j, int ident); static void job_log_stray_pg(job_t j); +static void job_log_chidren_without_exec(job_t j); static job_t job_new_anonymous(jobmgr_t jm, pid_t anonpid); static job_t job_new(jobmgr_t jm, const char *label, const char *prog, const char *const *argv); static job_t job_new_via_mach_init(job_t j, const char *cmd, uid_t uid, bool ond); @@ -1034,9 +1034,10 @@ int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, anonpid }; struct kinfo_proc kp; size_t len = sizeof(kp); - const char *zombie = NULL; bool shutdown_state; job_t jp = NULL, jr = NULL; + uid_t kp_euid, kp_uid, kp_svuid; + gid_t kp_egid, kp_gid, kp_svgid; if (!jobmgr_assumes(jm, anonpid != 0)) { return NULL; @@ -1061,10 +1062,25 @@ } if (kp.kp_proc.p_stat == SZOMB) { - jobmgr_log(jm, LOG_DEBUG, "Tried to create an anonymous job for zombie PID: %u", anonpid); - zombie = "zombie"; + jobmgr_log(jm, LOG_DEBUG, "Tried to create an anonymous job for zombie PID %u: %s", anonpid, kp.kp_proc.p_comm); } + if (kp.kp_proc.p_flag & P_SUGID) { + jobmgr_log(jm, LOG_APPLEONLY, "Inconsistency: P_SUGID is set on PID %u: %s", anonpid, kp.kp_proc.p_comm); + } + + kp_euid = kp.kp_eproc.e_ucred.cr_uid; + kp_uid = kp.kp_eproc.e_pcred.p_ruid; + kp_svuid = kp.kp_eproc.e_pcred.p_svuid; + kp_egid = kp.kp_eproc.e_ucred.cr_gid; + kp_gid = kp.kp_eproc.e_pcred.p_rgid; + kp_svgid = kp.kp_eproc.e_pcred.p_svgid; + + if (kp_euid != kp_uid || kp_euid != kp_svuid || kp_uid != kp_svuid || kp_egid != kp_gid || kp_egid != kp_svgid || kp_gid != kp_svgid) { + jobmgr_log(jm, LOG_APPLEONLY, "Inconsistency: Mixed credentials (e/r/s UID %u/%u/%u GID %u/%u/%u) detected on PID %u: %s", + kp_euid, kp_uid, kp_svuid, kp_egid, kp_gid, kp_svgid, anonpid, kp.kp_proc.p_comm); + } + switch (kp.kp_eproc.e_ppid) { case 0: /* the kernel */ @@ -1081,13 +1097,18 @@ break; } + if (jp && !jp->anonymous && !(kp.kp_proc.p_flag & P_EXEC)) { + job_log(jp, LOG_APPLEONLY, "Performance and sanity: fork() without exec*(). Please switch to posix_spawn()"); + } + + /* A total hack: Normally, job_new() returns an error during shutdown, but anonymous jobs are special. */ if ((shutdown_state = jm->shutting_down)) { jm->shutting_down = false; } - if (jobmgr_assumes(jm, (jr = job_new(jm, AUTO_PICK_LEGACY_LABEL, zombie ? zombie : kp.kp_proc.p_comm, NULL)) != NULL)) { - u_int proc_fflags = NOTE_EXEC|NOTE_EXIT /* |NOTE_REAP */; + if (jobmgr_assumes(jm, (jr = job_new(jm, AUTO_PICK_LEGACY_LABEL, kp.kp_proc.p_comm, NULL)) != NULL)) { + u_int proc_fflags = NOTE_EXEC|NOTE_FORK|NOTE_EXIT /* |NOTE_REAP */; total_anon_children++; jr->anonymous = true; @@ -1107,7 +1128,7 @@ } if (shutdown_state && jm->hopefully_first_cnt == 0) { - job_log(jr, LOG_APPLEONLY, "This process showed up to the party while all the guests were leaving. Odds are that it will have a miserable time"); + job_log(jr, LOG_APPLEONLY, "This process showed up to the party while all the guests were leaving. Odds are that it will have a miserable time."); } job_log(jr, LOG_DEBUG, "Created PID %u anonymously by PPID %u%s%s", anonpid, kp.kp_eproc.e_ppid, jp ? ": " : "", jp ? jp->label : ""); @@ -2044,7 +2065,7 @@ j->weird_bootstrap = false; } - if (j->log_redirect_fd && !j->wait4pipe_eof) { + if (j->log_redirect_fd && !j->legacy_LS_job) { job_assumes(j, runtime_close(j->log_redirect_fd) != -1); j->log_redirect_fd = 0; } @@ -2292,28 +2313,73 @@ } void +job_log_chidren_without_exec(job_t j) +{ + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL }; + size_t i, kp_cnt, len = 10*1024*1024; + struct kinfo_proc *kp; + + if (j->anonymous || j->per_user) { + return; + } + + if (!job_assumes(j, (kp = malloc(len)) != NULL)) { + return; + } + if (!job_assumes(j, sysctl(mib, 3, kp, &len, NULL, 0) != -1)) { + goto out; + } + + kp_cnt = len / sizeof(struct kinfo_proc); + + for (i = 0; i < kp_cnt; i++) { + if (kp[i].kp_eproc.e_ppid != j->p) { + continue; + } else if (kp[i].kp_proc.p_flag & P_EXEC) { + continue; + } + + job_log(j, LOG_APPLEONLY, "Performance and sanity: fork() without exec*(). Please switch to posix_spawn()"); + } + +out: + free(kp); +} + +void job_callback_proc(job_t j, int flags, int fflags) { - if ((fflags & NOTE_EXEC) && j->anonymous) { - int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, j->p }; - struct kinfo_proc kp; - size_t len = sizeof(kp); + bool program_changed = false; - if (job_assumes(j, sysctl(mib, 4, &kp, &len, NULL, 0) != -1)) { - char newlabel[1000]; + if (fflags & NOTE_EXEC) { + program_changed = true; - snprintf(newlabel, sizeof(newlabel), "%p.%s", j, kp.kp_proc.p_comm); + if (j->anonymous) { + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, j->p }; + struct kinfo_proc kp; + size_t len = sizeof(kp); - job_log(j, LOG_DEBUG, "Program changed. Updating the label to: %s", newlabel); + if (job_assumes(j, sysctl(mib, 4, &kp, &len, NULL, 0) != -1) && job_assumes(j, len == sizeof(kp))) { + char newlabel[1000]; - LIST_REMOVE(j, label_hash_sle); - strcpy((char *)j->label, newlabel); - LIST_INSERT_HEAD(&label_hash[hash_label(j->label)], j, label_hash_sle); + snprintf(newlabel, sizeof(newlabel), "%p.%s", j, kp.kp_proc.p_comm); + + job_log(j, LOG_INFO, "Program changed. Updating the label to: %s", newlabel); + j->lastlookup = NULL; + j->lastlookup_gennum = 0; + + LIST_REMOVE(j, label_hash_sle); + strcpy((char *)j->label, newlabel); + LIST_INSERT_HEAD(&label_hash[hash_label(j->label)], j, label_hash_sle); + } + } else { + job_log(j, LOG_DEBUG, "Program changed"); } } if (fflags & NOTE_FORK) { - job_log(j, LOG_DEBUG, "Called fork()"); + job_log(j, LOG_DEBUG, "fork()ed%s", program_changed ? ". For this message only: We don't know whether this event happened before or after execve()." : ""); + job_log_chidren_without_exec(j); } if (fflags & NOTE_EXIT) { @@ -2467,7 +2533,7 @@ char nbuf[64]; pid_t c; bool sipc = false; - u_int proc_fflags = /* NOTE_EXEC|NOTE_FORK| */ NOTE_EXIT /* |NOTE_REAP */; + u_int proc_fflags = NOTE_EXIT|NOTE_FORK|NOTE_EXEC /* NOTE_REAP */; if (!job_assumes(j, j->mgr != NULL)) { return; @@ -2762,7 +2828,7 @@ } void -job_find_and_blame_pids_with_weird_uids(job_t j) +job_log_pids_with_weird_uids(job_t j) { int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL }; size_t i, kp_cnt, len = 10*1024*1024; @@ -2834,7 +2900,7 @@ } else if (j->mach_uid) { if ((pwe = getpwuid(j->mach_uid)) == NULL) { job_log(j, LOG_ERR, "getpwuid(\"%u\") failed", j->mach_uid); - job_find_and_blame_pids_with_weird_uids(j); + job_log_pids_with_weird_uids(j); _exit(EXIT_FAILURE); } } else { @@ -3750,10 +3816,8 @@ bool job_useless(job_t j) { - /* Yes, j->unload_at_exit and j->only_once seem the same, but they'll differ someday... */ - - if ((j->unload_at_exit || j->only_once) && j->start_time != 0) { - if (j->unload_at_exit && j->j_port) { + if ((j->legacy_LS_job || j->only_once) && j->start_time != 0) { + if (j->legacy_LS_job && j->j_port) { return false; } job_log(j, LOG_INFO, "Exited. Was only configured to run once."); @@ -3916,7 +3980,7 @@ } if (j->log_redirect_fd) { - if (job_assumes(j, j->wait4pipe_eof)) { + if (job_assumes(j, j->legacy_LS_job)) { return "Standard out/error is still valid"; } else { job_assumes(j, runtime_close(j->log_redirect_fd) != -1); @@ -3974,6 +4038,7 @@ strcpy((char *)ms->name, name); ms->job = j; + ms->gen_num = 1; ms->per_pid = pid_local; if (*serviceport == MACH_PORT_NULL) { @@ -5725,9 +5790,9 @@ runtime_get_caller_creds(&ldc); -#if 0 - job_log(j, LOG_APPLEONLY, "bootstrap_register() is deprecated. Service: %s", servicename); -#endif + if (!(flags & BOOTSTRAP_PER_PID_SERVICE) && !j->legacy_LS_job) { + job_log(j, LOG_APPLEONLY, "Performance: bootstrap_register() is deprecated. Service: %s", servicename); + } job_log(j, LOG_DEBUG, "%sMach service registration attempt: %s", flags & BOOTSTRAP_PER_PID_SERVICE ? "Per PID " : "", servicename); @@ -5806,17 +5871,16 @@ if (ms) { launchd_assumes(machservice_port(ms) != MACH_PORT_NULL); job_log(j, LOG_DEBUG, "%sMach service lookup: %s", flags & BOOTSTRAP_PER_PID_SERVICE ? "Per PID " : "", servicename); -#if 0 - /* After Leopard ships, we should enable this */ + if (j->lastlookup == ms && j->lastlookup_gennum == ms->gen_num && !j->per_user) { - ms->bad_perf_cnt++; - job_log(j, LOG_APPLEONLY, "Performance opportunity: Number of bootstrap_lookup(... \"%s\" ...) calls that should have been cached: %llu", - servicename, ms->bad_perf_cnt); + job_log(ms->job, LOG_APPLEONLY, "Performance: Please fix the framework to cache the Mach port for service: %s", servicename); } + j->lastlookup = ms; j->lastlookup_gennum = ms->gen_num; -#endif + *serviceportp = machservice_port(ms); + kr = BOOTSTRAP_SUCCESS; } else if (!(flags & BOOTSTRAP_PER_PID_SERVICE) && (inherited_bootstrap_port != MACH_PORT_NULL)) { job_log(j, LOG_DEBUG, "Mach service lookup forwarded: %s", servicename); @@ -6469,8 +6533,7 @@ jr->mach_uid = ldc.uid; } - jr->unload_at_exit = true; - jr->wait4pipe_eof = true; + jr->legacy_LS_job = true; jr->abandon_pg = true; jr->stall_before_exec = jr->wait4debugger; jr->wait4debugger = false; Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-10-23 15:47:01 UTC (rev 23445) +++ trunk/launchd/src/launchd_runtime.c 2007-10-23 20:37:23 UTC (rev 23446) @@ -1173,22 +1173,23 @@ char newmsg[10000]; size_t i, j; - if (!(LOG_MASK(attr->priority) & internal_mask_pri)) { - goto out; - } - if (apple_internal_logging == 1) { apple_internal_logging = stat("/AppleInternal", &sb); } + if (attr->priority == LOG_APPLEONLY) { + if (apple_internal_logging == 0) { + attr->priority = LOG_NOTICE; + } else { + return; + } + } + if (!(LOG_MASK(attr->priority) & internal_mask_pri)) { + goto out; + } + if (!(debug_shutdown_hangs && getpid() == 1)) { - if (attr->priority == LOG_APPLEONLY) { - if (apple_internal_logging == -1) { - goto out; - } - attr->priority = LOG_NOTICE; - } vsnprintf(newmsg, sizeof(newmsg), message, args); logmsg_add(attr, saved_errno, newmsg); goto out; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071023/4d121018/attachment-0001.html From source_changes at macosforge.org Tue Oct 30 14:41:05 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Tue Oct 30 14:51:34 2007 Subject: [launchd-changes] [23447] trunk/launchd/testing/our_kill_is_busted.c Message-ID: <20071030214105.8D0739099F8@cvs.opensource.apple.com> Revision: 23447 http://trac.macosforge.org/projects/launchd/changeset/23447 Author: zarzycki@apple.com Date: 2007-10-30 14:41:05 -0700 (Tue, 30 Oct 2007) Log Message: ----------- 5487498 Added Paths: ----------- trunk/launchd/testing/our_kill_is_busted.c Added: trunk/launchd/testing/our_kill_is_busted.c =================================================================== --- trunk/launchd/testing/our_kill_is_busted.c (rev 0) +++ trunk/launchd/testing/our_kill_is_busted.c 2007-10-30 21:41:05 UTC (rev 23447) @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int +main(void) +{ + int wstatus; + pid_t p, wr; + int kill_r, killpg_r, r; + int kill_e, killpg_e; + + p = fork(); + assert(p != -1); + + if (p == 0) { + r = setsid(); + assert(r != -1); + _exit(EXIT_SUCCESS); + } + + sleep(1); + + errno = 0; + kill_r = kill(p, SIGTERM); + kill_e = errno; + + errno = 0; + killpg_r = kill(-(p), SIGTERM); + killpg_e = errno; + + if (kill_r != killpg_r) { + fprintf(stderr, "Bug. kill() is inconsistent.\n"); + fprintf(stderr, "kill( p, SIGTERM) returned %d and errno == %d\n", kill_r, kill_e); + fprintf(stderr, "kill(-(p), SIGTERM) returned %d and errno == %d\n", killpg_r, killpg_e); + if (kill_e == EPERM || killpg_e == EPERM) { + fprintf(stderr, "The kernel lied. We should have the right to kill 'p' and it returned EPERM.\n"); + } + if (kill_e == ESRCH || killpg_e == ESRCH) { + fprintf(stderr, "The kernel is confused. PID 'p' exists, but the kernel couldn't find it.\n"); + } + + exit(EXIT_FAILURE); + } + + wr = waitpid(p, &wstatus, 0); + assert(wr == p); + + exit(EXIT_SUCCESS); +} -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071030/43ea45ba/attachment.html