From source_changes at macosforge.org Tue Sep 2 11:53:29 2008 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 2 Sep 2008 11:53:29 -0700 (PDT) Subject: [launchd-changes] [23710] trunk/launchd/src/launchd_core_logic.c Message-ID: <20080902185330.1C3CE2EE1C5@beta.macosforge.org> Revision: 23710 http://trac.macosforge.org/projects/launchd/changeset/23710 Author: dsorresso at apple.com Date: 2008-09-02 11:53:29 -0700 (Tue, 02 Sep 2008) Log Message: ----------- Fix for rdar://problem/5982485. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2008-08-30 00:01:50 UTC (rev 23709) +++ trunk/launchd/src/launchd_core_logic.c 2008-09-02 18:53:29 UTC (rev 23710) @@ -7133,25 +7133,32 @@ job_mig_set_service_policy(job_t j, pid_t target_pid, uint64_t flags, name_t target_service) { struct ldcred *ldc = runtime_get_caller_creds(); - job_t target_j; + job_t target_j = NULL; if (!launchd_assumes(j != NULL)) { return BOOTSTRAP_NO_MEMORY; } + target_j = jobmgr_find_by_pid(j->mgr, target_pid, true); + if (ldc->euid && (ldc->euid != getuid())) { int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, target_pid }; struct kinfo_proc kp; size_t len = sizeof(kp); job_assumes(j, sysctl(mib, 4, &kp, &len, NULL, 0) != -1); + job_assumes(j, len == sizeof(kp)); uid_t kp_euid = kp.kp_eproc.e_ucred.cr_uid; uid_t kp_uid = kp.kp_eproc.e_pcred.p_ruid; - job_log(j, LOG_ERR, "Denied Mach service policy update requested by UID/EUID %u/%u against PID %u with UID/EUID %u/%u due to mismatched credentials.", ldc->uid, ldc->euid, target_pid, kp_uid, kp_euid); + if( ldc->euid == kp_euid ) { + job_log(j, LOG_WARNING, "Working around rdar://problem/5982485 and allowing job to set policy for PID %u. We should discuss having %s run under a per-user launchd.", target_pid, target_j->label); + } else { + job_log(j, LOG_ERR, "Denied Mach service policy update requested by UID/EUID %u/%u against PID %u with UID/EUID %u/%u due to mismatched credentials.", ldc->uid, ldc->euid, target_pid, kp_uid, kp_euid); - return BOOTSTRAP_NOT_PRIVILEGED; + return BOOTSTRAP_NOT_PRIVILEGED; + } } if (unlikely(!SLIST_EMPTY(&j->mspolicies))) { @@ -7159,8 +7166,6 @@ return BOOTSTRAP_NOT_PRIVILEGED; } - target_j = jobmgr_find_by_pid(j->mgr, target_pid, true); - if (unlikely(target_j == NULL)) { if (job_assumes(j, errno == ESRCH)) { job_log(j, LOG_ERR, "Could not find PID %u while trying to set Mach bootstrap service policy: %s", target_pid, target_service); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20080902/82e1efe7/attachment.html From source_changes at macosforge.org Tue Sep 2 17:08:00 2008 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 2 Sep 2008 17:08:00 -0700 (PDT) Subject: [launchd-changes] [23711] tags/launchd-283/ Message-ID: <20080903000801.DB0CD2F06A9@beta.macosforge.org> Revision: 23711 http://trac.macosforge.org/projects/launchd/changeset/23711 Author: dsorresso at apple.com Date: 2008-09-02 17:07:58 -0700 (Tue, 02 Sep 2008) Log Message: ----------- "Tagging launchd-283 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-283/ Property changes on: tags/launchd-283 ___________________________________________________________________ Added: svn:mergeinfo + /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20080902/d94f62ea/attachment.html From source_changes at macosforge.org Wed Sep 17 11:41:19 2008 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Wed, 17 Sep 2008 11:41:19 -0700 (PDT) Subject: [launchd-changes] [23712] trunk/launchd/src Message-ID: <20080917184120.46B13378E5D@beta.macosforge.org> Revision: 23712 http://trac.macosforge.org/projects/launchd/changeset/23712 Author: dsorresso at apple.com Date: 2008-09-17 11:41:18 -0700 (Wed, 17 Sep 2008) Log Message: ----------- Instant Off: SPIs and functionality for tool reporting clean state violations 5858547Blocker: calling vproc_standby_end core dumps 10A127: com.apple.launchctl.System causes 20s stall at installer shutdown vproc_transaction_{begin,end} should be declared AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER per-user launchd "Shutdown began at" messages are confusing Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in 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_runtime.c trunk/launchd/src/launchd_runtime.h trunk/launchd/src/liblaunch.c trunk/launchd/src/liblaunch_private.h trunk/launchd/src/liblaunch_public.h trunk/launchd/src/libvproc.c trunk/launchd/src/libvproc_private.h Added Paths: ----------- trunk/launchd/src/launchd_ktrace.c trunk/launchd/src/launchd_ktrace.h Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/Makefile.am 2008-09-17 18:41:18 UTC (rev 23712) @@ -16,10 +16,10 @@ noinst_LIBRARIES = liblaunch.a liblaunch_profile.a liblaunch_a_CFLAGS = -D__DARWIN_NON_CANCELABLE=1 $(AM_CFLAGS) -liblaunch_a_SOURCES = liblaunch.c libvproc.c libbootstrap.c protocol_vprocUser.c __version.c +liblaunch_a_SOURCES = liblaunch.c libvproc.c libbootstrap.c protocol_vprocUser.c launchd_ktrace.c __version.c liblaunch_profile_a_CFLAGS = -pg -D__DARWIN_NON_CANCELABLE=1 $(AM_CFLAGS) -liblaunch_profile_a_SOURCES = liblaunch.c libvproc.c libbootstrap.c protocol_vprocUser.c __version.c +liblaunch_profile_a_SOURCES = liblaunch.c libvproc.c libbootstrap.c protocol_vprocUser.c launchd_ktrace.c __version.c $(srcdir)/libvproc.c:: protocol_vproc.h @@ -59,7 +59,7 @@ launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) launchd_LDFLAGS = $(AM_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 mach_excServer.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_ktrace.c 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 Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/Makefile.in 2008-09-17 18:41:18 UTC (rev 23712) @@ -55,23 +55,26 @@ liblaunch_a_AR = $(AR) $(ARFLAGS) liblaunch_a_LIBADD = am__liblaunch_a_SOURCES_DIST = liblaunch.c libvproc.c libbootstrap.c \ - protocol_vprocUser.c __version.c + protocol_vprocUser.c launchd_ktrace.c __version.c @LIBS_ONLY_TRUE at am_liblaunch_a_OBJECTS = \ @LIBS_ONLY_TRUE@ liblaunch_a-liblaunch.$(OBJEXT) \ @LIBS_ONLY_TRUE@ liblaunch_a-libvproc.$(OBJEXT) \ @LIBS_ONLY_TRUE@ liblaunch_a-libbootstrap.$(OBJEXT) \ @LIBS_ONLY_TRUE@ liblaunch_a-protocol_vprocUser.$(OBJEXT) \ + at LIBS_ONLY_TRUE@ liblaunch_a-launchd_ktrace.$(OBJEXT) \ @LIBS_ONLY_TRUE@ liblaunch_a-__version.$(OBJEXT) liblaunch_a_OBJECTS = $(am_liblaunch_a_OBJECTS) liblaunch_profile_a_AR = $(AR) $(ARFLAGS) liblaunch_profile_a_LIBADD = am__liblaunch_profile_a_SOURCES_DIST = liblaunch.c libvproc.c \ - libbootstrap.c protocol_vprocUser.c __version.c + libbootstrap.c protocol_vprocUser.c launchd_ktrace.c \ + __version.c @LIBS_ONLY_TRUE at am_liblaunch_profile_a_OBJECTS = \ @LIBS_ONLY_TRUE@ liblaunch_profile_a-liblaunch.$(OBJEXT) \ @LIBS_ONLY_TRUE@ liblaunch_profile_a-libvproc.$(OBJEXT) \ @LIBS_ONLY_TRUE@ liblaunch_profile_a-libbootstrap.$(OBJEXT) \ @LIBS_ONLY_TRUE@ liblaunch_profile_a-protocol_vprocUser.$(OBJEXT) \ + at LIBS_ONLY_TRUE@ liblaunch_profile_a-launchd_ktrace.$(OBJEXT) \ @LIBS_ONLY_TRUE@ liblaunch_profile_a-__version.$(OBJEXT) liblaunch_profile_a_OBJECTS = $(am_liblaunch_profile_a_OBJECTS) am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(libexecdir)" \ @@ -99,7 +102,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 mach_excServer.c + job_forwardUser.c mach_excServer.c launchd_ktrace.c @LIBS_ONLY_FALSE at am_launchd_OBJECTS = launchd-launchd.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-launchd_core_logic.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-launchd_unix_ipc.$(OBJEXT) \ @@ -111,7 +114,8 @@ @LIBS_ONLY_FALSE@ launchd-launchd_runtime.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-launchd_runtime_kill.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-job_forwardUser.$(OBJEXT) \ - at LIBS_ONLY_FALSE@ launchd-mach_excServer.$(OBJEXT) + at LIBS_ONLY_FALSE@ launchd-mach_excServer.$(OBJEXT) \ + at LIBS_ONLY_FALSE@ launchd-launchd_ktrace.$(OBJEXT) launchd_OBJECTS = $(am_launchd_OBJECTS) launchd_LDADD = $(LDADD) launchd_LINK = $(CCLD) $(launchd_CFLAGS) $(CFLAGS) $(launchd_LDFLAGS) \ @@ -253,9 +257,9 @@ @LIBS_ONLY_TRUE at noinst_LIBRARIES = liblaunch.a liblaunch_profile.a @LIBS_ONLY_TRUE at liblaunch_a_CFLAGS = -D__DARWIN_NON_CANCELABLE=1 $(AM_CFLAGS) - at LIBS_ONLY_TRUE@liblaunch_a_SOURCES = liblaunch.c libvproc.c libbootstrap.c protocol_vprocUser.c __version.c + at LIBS_ONLY_TRUE@liblaunch_a_SOURCES = liblaunch.c libvproc.c libbootstrap.c protocol_vprocUser.c launchd_ktrace.c __version.c @LIBS_ONLY_TRUE at liblaunch_profile_a_CFLAGS = -pg -D__DARWIN_NON_CANCELABLE=1 $(AM_CFLAGS) - at LIBS_ONLY_TRUE@liblaunch_profile_a_SOURCES = liblaunch.c libvproc.c libbootstrap.c protocol_vprocUser.c __version.c + at LIBS_ONLY_TRUE@liblaunch_profile_a_SOURCES = liblaunch.c libvproc.c libbootstrap.c protocol_vprocUser.c launchd_ktrace.c __version.c @LIBS_ONLY_FALSE at sysconf_DATA = hostconfig rc.common rc.netboot @LIBS_ONLY_FALSE at launchctl_CFLAGS = $(AM_CFLAGS) -isystem $(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders @LIBS_ONLY_FALSE at launchctl_LDFLAGS = $(AM_LDFLAGS) -framework CoreFoundation -framework IOKit $(LIBS_SECURITY) -weak_library /usr/lib/libedit.dylib @@ -264,7 +268,7 @@ @DO_EMBEDDED_MAGIC_FALSE@@LIBS_ONLY_FALSE at SystemStarter_SOURCES = StartupItems.c IPC.c SystemStarter.c @LIBS_ONLY_FALSE at launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) @LIBS_ONLY_FALSE at launchd_LDFLAGS = $(AM_LDFLAGS) -lbsm - at 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 + at 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 launchd_ktrace.c @LIBS_ONLY_FALSE at launchproxy_LDFLAGS = $(AM_LDFLAGS) $(LIBS_SECURITY) @LIBS_ONLY_FALSE at man1_MANS = wait4path.1 launchctl.1 @LIBS_ONLY_FALSE at man5_MANS = launchd.plist.5 launchd.conf.5 @@ -433,6 +437,7 @@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/launchd-launchd_core_logic.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/launchd-launchd_internalServer.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/launchd-launchd_internalUser.Po at am__quote@ + at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/launchd-launchd_ktrace.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/launchd-launchd_runtime.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/launchd-launchd_runtime_kill.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/launchd-launchd_unix_ipc.Po at am__quote@ @@ -441,11 +446,13 @@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/launchd-protocol_vprocServer.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/launchproxy.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/liblaunch_a-__version.Po at am__quote@ + at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/liblaunch_a-launchd_ktrace.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/liblaunch_a-libbootstrap.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/liblaunch_a-liblaunch.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/liblaunch_a-libvproc.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/liblaunch_a-protocol_vprocUser.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/liblaunch_profile_a-__version.Po at am__quote@ + at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/liblaunch_profile_a-launchd_ktrace.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/liblaunch_profile_a-libbootstrap.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/liblaunch_profile_a-liblaunch.Po at am__quote@ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/liblaunch_profile_a-libvproc.Po at am__quote@ @@ -522,6 +529,20 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liblaunch_a_CFLAGS) $(CFLAGS) -c -o liblaunch_a-protocol_vprocUser.obj `if test -f 'protocol_vprocUser.c'; then $(CYGPATH_W) 'protocol_vprocUser.c'; else $(CYGPATH_W) '$(srcdir)/protocol_vprocUser.c'; fi` +liblaunch_a-launchd_ktrace.o: launchd_ktrace.c + at am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liblaunch_a_CFLAGS) $(CFLAGS) -MT liblaunch_a-launchd_ktrace.o -MD -MP -MF $(DEPDIR)/liblaunch_a-launchd_ktrace.Tpo -c -o liblaunch_a-launchd_ktrace.o `test -f 'launchd_ktrace.c' || echo '$(srcdir)/'`launchd_ktrace.c + at am__fastdepCC_TRUE@ mv -f $(DEPDIR)/liblaunch_a-launchd_ktrace.Tpo $(DEPDIR)/liblaunch_a-launchd_ktrace.Po + at AMDEP_TRUE@@am__fastdepCC_FALSE@ source='launchd_ktrace.c' object='liblaunch_a-launchd_ktrace.o' libtool=no @AMDEPBACKSLASH@ + at AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + at am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liblaunch_a_CFLAGS) $(CFLAGS) -c -o liblaunch_a-launchd_ktrace.o `test -f 'launchd_ktrace.c' || echo '$(srcdir)/'`launchd_ktrace.c + +liblaunch_a-launchd_ktrace.obj: launchd_ktrace.c + at am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liblaunch_a_CFLAGS) $(CFLAGS) -MT liblaunch_a-launchd_ktrace.obj -MD -MP -MF $(DEPDIR)/liblaunch_a-launchd_ktrace.Tpo -c -o liblaunch_a-launchd_ktrace.obj `if test -f 'launchd_ktrace.c'; then $(CYGPATH_W) 'launchd_ktrace.c'; else $(CYGPATH_W) '$(srcdir)/launchd_ktrace.c'; fi` + at am__fastdepCC_TRUE@ mv -f $(DEPDIR)/liblaunch_a-launchd_ktrace.Tpo $(DEPDIR)/liblaunch_a-launchd_ktrace.Po + at AMDEP_TRUE@@am__fastdepCC_FALSE@ source='launchd_ktrace.c' object='liblaunch_a-launchd_ktrace.obj' libtool=no @AMDEPBACKSLASH@ + at AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + at am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liblaunch_a_CFLAGS) $(CFLAGS) -c -o liblaunch_a-launchd_ktrace.obj `if test -f 'launchd_ktrace.c'; then $(CYGPATH_W) 'launchd_ktrace.c'; else $(CYGPATH_W) '$(srcdir)/launchd_ktrace.c'; fi` + liblaunch_a-__version.o: __version.c @am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liblaunch_a_CFLAGS) $(CFLAGS) -MT liblaunch_a-__version.o -MD -MP -MF $(DEPDIR)/liblaunch_a-__version.Tpo -c -o liblaunch_a-__version.o `test -f '__version.c' || echo '$(srcdir)/'`__version.c @am__fastdepCC_TRUE@ mv -f $(DEPDIR)/liblaunch_a-__version.Tpo $(DEPDIR)/liblaunch_a-__version.Po @@ -592,6 +613,20 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liblaunch_profile_a_CFLAGS) $(CFLAGS) -c -o liblaunch_profile_a-protocol_vprocUser.obj `if test -f 'protocol_vprocUser.c'; then $(CYGPATH_W) 'protocol_vprocUser.c'; else $(CYGPATH_W) '$(srcdir)/protocol_vprocUser.c'; fi` +liblaunch_profile_a-launchd_ktrace.o: launchd_ktrace.c + at am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liblaunch_profile_a_CFLAGS) $(CFLAGS) -MT liblaunch_profile_a-launchd_ktrace.o -MD -MP -MF $(DEPDIR)/liblaunch_profile_a-launchd_ktrace.Tpo -c -o liblaunch_profile_a-launchd_ktrace.o `test -f 'launchd_ktrace.c' || echo '$(srcdir)/'`launchd_ktrace.c + at am__fastdepCC_TRUE@ mv -f $(DEPDIR)/liblaunch_profile_a-launchd_ktrace.Tpo $(DEPDIR)/liblaunch_profile_a-launchd_ktrace.Po + at AMDEP_TRUE@@am__fastdepCC_FALSE@ source='launchd_ktrace.c' object='liblaunch_profile_a-launchd_ktrace.o' libtool=no @AMDEPBACKSLASH@ + at AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + at am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liblaunch_profile_a_CFLAGS) $(CFLAGS) -c -o liblaunch_profile_a-launchd_ktrace.o `test -f 'launchd_ktrace.c' || echo '$(srcdir)/'`launchd_ktrace.c + +liblaunch_profile_a-launchd_ktrace.obj: launchd_ktrace.c + at am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liblaunch_profile_a_CFLAGS) $(CFLAGS) -MT liblaunch_profile_a-launchd_ktrace.obj -MD -MP -MF $(DEPDIR)/liblaunch_profile_a-launchd_ktrace.Tpo -c -o liblaunch_profile_a-launchd_ktrace.obj `if test -f 'launchd_ktrace.c'; then $(CYGPATH_W) 'launchd_ktrace.c'; else $(CYGPATH_W) '$(srcdir)/launchd_ktrace.c'; fi` + at am__fastdepCC_TRUE@ mv -f $(DEPDIR)/liblaunch_profile_a-launchd_ktrace.Tpo $(DEPDIR)/liblaunch_profile_a-launchd_ktrace.Po + at AMDEP_TRUE@@am__fastdepCC_FALSE@ source='launchd_ktrace.c' object='liblaunch_profile_a-launchd_ktrace.obj' libtool=no @AMDEPBACKSLASH@ + at AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + at am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liblaunch_profile_a_CFLAGS) $(CFLAGS) -c -o liblaunch_profile_a-launchd_ktrace.obj `if test -f 'launchd_ktrace.c'; then $(CYGPATH_W) 'launchd_ktrace.c'; else $(CYGPATH_W) '$(srcdir)/launchd_ktrace.c'; fi` + liblaunch_profile_a-__version.o: __version.c @am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(liblaunch_profile_a_CFLAGS) $(CFLAGS) -MT liblaunch_profile_a-__version.o -MD -MP -MF $(DEPDIR)/liblaunch_profile_a-__version.Tpo -c -o liblaunch_profile_a-__version.o `test -f '__version.c' || echo '$(srcdir)/'`__version.c @am__fastdepCC_TRUE@ mv -f $(DEPDIR)/liblaunch_profile_a-__version.Tpo $(DEPDIR)/liblaunch_profile_a-__version.Po @@ -829,6 +864,20 @@ @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` + +launchd-launchd_ktrace.o: launchd_ktrace.c + at am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-launchd_ktrace.o -MD -MP -MF $(DEPDIR)/launchd-launchd_ktrace.Tpo -c -o launchd-launchd_ktrace.o `test -f 'launchd_ktrace.c' || echo '$(srcdir)/'`launchd_ktrace.c + at am__fastdepCC_TRUE@ mv -f $(DEPDIR)/launchd-launchd_ktrace.Tpo $(DEPDIR)/launchd-launchd_ktrace.Po + at AMDEP_TRUE@@am__fastdepCC_FALSE@ source='launchd_ktrace.c' object='launchd-launchd_ktrace.o' libtool=no @AMDEPBACKSLASH@ + at AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + at am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -c -o launchd-launchd_ktrace.o `test -f 'launchd_ktrace.c' || echo '$(srcdir)/'`launchd_ktrace.c + +launchd-launchd_ktrace.obj: launchd_ktrace.c + at am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-launchd_ktrace.obj -MD -MP -MF $(DEPDIR)/launchd-launchd_ktrace.Tpo -c -o launchd-launchd_ktrace.obj `if test -f 'launchd_ktrace.c'; then $(CYGPATH_W) 'launchd_ktrace.c'; else $(CYGPATH_W) '$(srcdir)/launchd_ktrace.c'; fi` + at am__fastdepCC_TRUE@ mv -f $(DEPDIR)/launchd-launchd_ktrace.Tpo $(DEPDIR)/launchd-launchd_ktrace.Po + at AMDEP_TRUE@@am__fastdepCC_FALSE@ source='launchd_ktrace.c' object='launchd-launchd_ktrace.obj' libtool=no @AMDEPBACKSLASH@ + at AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ + at am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -c -o launchd-launchd_ktrace.obj `if test -f 'launchd_ktrace.c'; then $(CYGPATH_W) 'launchd_ktrace.c'; else $(CYGPATH_W) '$(srcdir)/launchd_ktrace.c'; fi` install-man1: $(man1_MANS) $(man_MANS) @$(NORMAL_INSTALL) test -z "$(man1dir)" || $(MKDIR_P) "$(DESTDIR)$(man1dir)" Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/launchctl.c 2008-09-17 18:41:18 UTC (rev 23712) @@ -1390,13 +1390,20 @@ } static void +exit_at_sigterm(int sig) +{ + if( sig == SIGTERM ) { + exit(EXIT_SUCCESS); + } +} + +static void system_specific_bootstrap(bool sflag) { int hnmib[] = { CTL_KERN, KERN_HOSTNAME }; struct kevent kev; int kq; - do_sysversion_sysctl(); do_single_user_mode(sflag); @@ -1419,6 +1426,11 @@ if (path_check("/etc/rc.cdrom")) { const char *rccdrom_tool[] = { _PATH_BSHELL, "/etc/rc.cdrom", "multiuser", NULL }; + + /* The bootstrapper should always be killable during install-time (rdar://problem/6103485). + * This is a special case for /etc/rc.cdrom, which runs a process and never exits. + */ + assumes(signal(SIGTERM, exit_at_sigterm) != SIG_ERR); assumes(fwexec(rccdrom_tool, NULL) != -1); assumes(reboot(RB_HALT) != -1); _exit(EXIT_FAILURE); Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/launchd.c 2008-09-17 18:41:18 UTC (rev 23712) @@ -82,7 +82,6 @@ #define LAUNCHD_CONF ".launchd.conf" #define SECURITY_LIB "/System/Library/Frameworks/Security.framework/Versions/A/Security" - extern char **environ; INTERNAL_ABI static void pfsystem_callback(void *, struct kevent *); @@ -107,6 +106,7 @@ bool shutdown_in_progress; bool fake_shutdown_in_progress; bool network_up; +char g_username[128] = "__UnknownUserToLaunchd_DontPanic_NotImportant__"; int main(int argc, char *const *argv) @@ -157,6 +157,17 @@ pid1_magic_init(); } else { ipc_server_init(); + + runtime_log_push(); + + int64_t now = runtime_get_wall_time(); + + struct passwd *pwent = getpwuid(getuid()); + if( pwent ) { + strlcpy(g_username, pwent->pw_name, sizeof(g_username) - 1); + } + + runtime_syslog(LOG_NOTICE, "Per-user launchd for UID %u (%s) began at: %lld.%06llu", getuid(), g_username, now / USEC_PER_SEC, now % USEC_PER_SEC); } monitor_networking_state(); @@ -301,7 +312,8 @@ now = runtime_get_wall_time(); - runtime_syslog(LOG_NOTICE, "Shutdown began at: %lld.%06llu", now / USEC_PER_SEC, now % USEC_PER_SEC); + char *term_who = pid1_magic ? "System shutdown" : "Per-user launchd termination"; + runtime_syslog(LOG_NOTICE, "%s began at: %lld.%06llu", term_who, now / USEC_PER_SEC, now % USEC_PER_SEC); launchd_assert(jobmgr_shutdown(root_jobmgr) != NULL); } Modified: trunk/launchd/src/launchd.h =================================================================== --- trunk/launchd/src/launchd.h 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/launchd.h 2008-09-17 18:41:18 UTC (rev 23712) @@ -32,6 +32,7 @@ extern bool shutdown_in_progress; extern bool fake_shutdown_in_progress; extern bool network_up; +extern bool g_force_old_kill_path; INTERNAL_ABI bool init_check_pid(pid_t); Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/launchd_core_logic.c 2008-09-17 18:41:18 UTC (rev 23712) @@ -619,7 +619,7 @@ return; } - if (j->kill_via_shmem) { + if (j->kill_via_shmem && !g_force_old_kill_path) { if (j->shmem) { if (!j->sent_kill_via_shmem) { j->shmem->vp_shmem_flags |= VPROC_SHMEM_EXITING; @@ -631,6 +631,8 @@ } else { newval = -1; } + } else if( j->kill_via_shmem ) { + job_log(j, LOG_DEBUG, "Stopping transactional job the old-fashioned way."); } j->sent_signal_time = runtime_get_opaque_time(); @@ -1861,7 +1863,7 @@ case 'E': if (strcasecmp(key, LAUNCH_JOBKEY_ENVIRONMENTVARIABLES) == 0) { launch_data_dict_iterate(value, envitem_setup, j); - } + } break; case 'u': case 'U': @@ -3493,6 +3495,10 @@ setenv(ei->key, ei->value, 1); } + if( do_apple_internal_logging ) { + setenv(LAUNCHD_DO_APPLE_INTERNAL_LOGGING, "true", 1); + } + /* * We'd like to call setsid() unconditionally, but we have reason to * believe that prevents launchd from being able to send signals to @@ -4214,7 +4220,7 @@ return; } - if( strncmp(LAUNCHD_TRUSTED_FD_ENV, key, sizeof(LAUNCHD_TRUSTED_FD_ENV) - 1) ) { + if( strncmp(LAUNCHD_TRUSTED_FD_ENV, key, sizeof(LAUNCHD_TRUSTED_FD_ENV) - 1) != 0 ) { envitem_new(j, key, launch_data_get_string(obj), j->importing_global_env); } else { job_log(j, LOG_WARNING, "Ignoring reserved environmental variable: %s", key); @@ -5020,6 +5026,7 @@ snprintf(thelabel, sizeof(thelabel), "com.apple.launchctl.%s", session_type); bootstrapper = job_new(jm, thelabel, NULL, bootstrap_tool); + if (jobmgr_assumes(jm, bootstrapper != NULL) && (jm->parentmgr || getuid())) { char buf[100]; @@ -6134,7 +6141,7 @@ } else { job_log(j, LOG_DEBUG, "Now participating in transaction model."); j->kill_via_shmem = (bool)inval; - job_log(j, LOG_DEBUG, "j->kill_via_shmem = %s", j->kill_via_shmem ? "YES" : "NO"); + job_log(j, LOG_DEBUG, "j->kill_via_shmem = %s", j->kill_via_shmem ? "true" : "false"); } case 0: break; Added: trunk/launchd/src/launchd_ktrace.c =================================================================== --- trunk/launchd/src/launchd_ktrace.c (rev 0) +++ trunk/launchd/src/launchd_ktrace.c 2008-09-17 18:41:18 UTC (rev 23712) @@ -0,0 +1,34 @@ +#include "launchd_ktrace.h" + +INTERNAL_ABI void +runtime_ktrace1(runtime_ktrace_code_t code) +{ + void *ra = __builtin_extract_return_addr(__builtin_return_address(1)); + + /* This syscall returns EINVAL when the trace isn't enabled. */ + if (do_apple_internal_logging) { + syscall(180, code, 0, 0, 0, (long)ra); + } +} + +INTERNAL_ABI void +runtime_ktrace0(runtime_ktrace_code_t code) +{ + void *ra = __builtin_extract_return_addr(__builtin_return_address(0)); + + /* This syscall returns EINVAL when the trace isn't enabled. */ + if (do_apple_internal_logging) { + syscall(180, code, 0, 0, 0, (long)ra); + } +} + +INTERNAL_ABI void +runtime_ktrace(runtime_ktrace_code_t code, long a, long b, long c) +{ + void *ra = __builtin_extract_return_addr(__builtin_return_address(0)); + + /* This syscall returns EINVAL when the trace isn't enabled. */ + if (do_apple_internal_logging) { + syscall(180, code, a, b, c, (long)ra); + } +} Added: trunk/launchd/src/launchd_ktrace.h =================================================================== --- trunk/launchd/src/launchd_ktrace.h (rev 0) +++ trunk/launchd/src/launchd_ktrace.h 2008-09-17 18:41:18 UTC (rev 23712) @@ -0,0 +1,43 @@ +#ifndef __LAUNCHD_KTRACE_H__ +#define __LAUNCHD_KTRACE_H__ + +#include +#include + +extern bool do_apple_internal_logging; + +#ifdef __i386__ + #define INTERNAL_ABI __attribute__((regparm(3))) /* Enable register-passing for the first 3 arguments on i386. */ +#else + #define INTERNAL_ABI +#endif + +#ifndef DBG_LAUNCHD + #define DBG_LAUNCHD 34 +#endif + +/* Class(8) | SubClass(8) | Code(14) | Qual(2) */ +#define RTKT_CODE(c) ((DBG_LAUNCHD << 24) | (((c) & 0x3fffff) << 2)) + +typedef enum { + RTKT_LAUNCHD_STARTING = RTKT_CODE(1), + RTKT_LAUNCHD_EXITING = RTKT_CODE(2), + RTKT_LAUNCHD_FINDING_STRAY_PG = RTKT_CODE(3), + RTKT_LAUNCHD_FINDING_ALL_STRAYS = RTKT_CODE(4), + RTKT_LAUNCHD_FINDING_EXECLESS = RTKT_CODE(5), + RTKT_LAUNCHD_FINDING_WEIRD_UIDS = RTKT_CODE(6), + RTKT_LAUNCHD_DATA_PACK = RTKT_CODE(7), + RTKT_LAUNCHD_DATA_UNPACK = RTKT_CODE(8), + RTKT_LAUNCHD_BUG = RTKT_CODE(9), + RTKT_LAUNCHD_MACH_IPC = RTKT_CODE(10), + RTKT_LAUNCHD_BSD_KEVENT = RTKT_CODE(11), + RTKT_VPROC_TRANSACTION_INCREMENT = RTKT_CODE(12), + RTKT_VPROC_TRANSACTION_DECREMENT = RTKT_CODE(13), +} runtime_ktrace_code_t; + +/* All of these log the return address as "arg4" */ +INTERNAL_ABI void runtime_ktrace1(runtime_ktrace_code_t code); +INTERNAL_ABI void runtime_ktrace0(runtime_ktrace_code_t code); +INTERNAL_ABI void runtime_ktrace(runtime_ktrace_code_t code, long a, long b, long c); + +#endif /* __LAUNCHD_KTRACE_H__ */ Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/launchd_runtime.c 2008-09-17 18:41:18 UTC (rev 23712) @@ -130,8 +130,8 @@ bool pid1_magic; bool do_apple_internal_logging; bool low_level_debug; +bool g_force_old_kill_path = false; - INTERNAL_ABI mach_port_t runtime_get_kernel_port(void) { @@ -1357,39 +1357,6 @@ } INTERNAL_ABI void -runtime_ktrace1(runtime_ktrace_code_t code) -{ - void *ra = __builtin_extract_return_addr(__builtin_return_address(1)); - - /* This syscall returns EINVAL when the trace isn't enabled. */ - if (do_apple_internal_logging) { - syscall(180, code, 0, 0, 0, (long)ra); - } -} - -INTERNAL_ABI void -runtime_ktrace0(runtime_ktrace_code_t code) -{ - void *ra = __builtin_extract_return_addr(__builtin_return_address(0)); - - /* This syscall returns EINVAL when the trace isn't enabled. */ - if (do_apple_internal_logging) { - syscall(180, code, 0, 0, 0, (long)ra); - } -} - -INTERNAL_ABI void -runtime_ktrace(runtime_ktrace_code_t code, long a, long b, long c) -{ - void *ra = __builtin_extract_return_addr(__builtin_return_address(0)); - - /* This syscall returns EINVAL when the trace isn't enabled. */ - if (do_apple_internal_logging) { - syscall(180, code, a, b, c, (long)ra); - } -} - -INTERNAL_ABI void runtime_log_push(void) { static pthread_mutex_t ourlock = PTHREAD_MUTEX_INITIALIZER; @@ -1726,4 +1693,8 @@ internal_mask_pri = LOG_UPTO(LOG_DEBUG); low_level_debug = true; } + + if( stat("/var/db/.launchd_disable_sudden_termination", &sb) == 0 ) { + g_force_old_kill_path = true; + } } Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/launchd_runtime.h 2008-09-17 18:41:18 UTC (rev 23712) @@ -29,6 +29,7 @@ #include #include "launchd_runtime_kill.h" +#include "launchd_ktrace.h" #if 0 @@ -104,8 +105,8 @@ typedef INTERNAL_ABI void (*timeout_callback)(void); extern bool pid1_magic; -extern bool do_apple_internal_logging; extern bool low_level_debug; +extern char g_username[128]; INTERNAL_ABI mach_port_t runtime_get_kernel_port(void); @@ -142,33 +143,6 @@ INTERNAL_ABI kern_return_t runtime_log_forward(uid_t forward_uid, gid_t forward_gid, vm_offset_t inval, mach_msg_type_number_t invalCnt); INTERNAL_ABI kern_return_t runtime_log_drain(mach_port_t srp, vm_offset_t *outval, mach_msg_type_number_t *outvalCnt); -#ifndef DBG_LAUNCHD -#define DBG_LAUNCHD 34 -#endif - -/* Class(8) | SubClass(8) | Code(14) | Qual(2) */ -#define RTKT_CODE(c) ((DBG_LAUNCHD << 24) | (((c) & 0x3fffff) << 2)) - -typedef enum { - RTKT_LAUNCHD_STARTING = RTKT_CODE(1), - RTKT_LAUNCHD_EXITING = RTKT_CODE(2), - RTKT_LAUNCHD_FINDING_STRAY_PG = RTKT_CODE(3), - RTKT_LAUNCHD_FINDING_ALL_STRAYS = RTKT_CODE(4), - RTKT_LAUNCHD_FINDING_EXECLESS = RTKT_CODE(5), - RTKT_LAUNCHD_FINDING_WEIRD_UIDS = RTKT_CODE(6), - RTKT_LAUNCHD_DATA_PACK = RTKT_CODE(7), - RTKT_LAUNCHD_DATA_UNPACK = RTKT_CODE(8), - RTKT_LAUNCHD_BUG = RTKT_CODE(9), - RTKT_LAUNCHD_MACH_IPC = RTKT_CODE(10), - RTKT_LAUNCHD_BSD_KEVENT = RTKT_CODE(11), -} runtime_ktrace_code_t; - -/* All of these log the return address as "arg4" */ -INTERNAL_ABI void runtime_ktrace1(runtime_ktrace_code_t code); -INTERNAL_ABI void runtime_ktrace0(runtime_ktrace_code_t code); -INTERNAL_ABI void runtime_ktrace(runtime_ktrace_code_t code, long a, long b, long c); - - #define LOG_APPLEONLY 0x4141504c /* AAPL in hex */ struct runtime_syslog_attr { Modified: trunk/launchd/src/liblaunch.c =================================================================== --- trunk/launchd/src/liblaunch.c 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/liblaunch.c 2008-09-17 18:41:18 UTC (rev 23712) @@ -22,6 +22,7 @@ #include "liblaunch_public.h" #include "liblaunch_private.h" #include "liblaunch_internal.h" +#include "launchd_ktrace.h" #include #include @@ -169,6 +170,8 @@ static launch_t in_flight_msg_recv_client; static pthread_once_t _lc_once = PTHREAD_ONCE_INIT; +bool do_apple_internal_logging = false; + static struct _launch_client { pthread_mutex_t mtx; launch_t l; Modified: trunk/launchd/src/liblaunch_private.h =================================================================== --- trunk/launchd/src/liblaunch_private.h 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/liblaunch_private.h 2008-09-17 18:41:18 UTC (rev 23712) @@ -30,38 +30,39 @@ __BEGIN_DECLS -#define LAUNCH_KEY_SETUSERENVIRONMENT "SetUserEnvironment" -#define LAUNCH_KEY_UNSETUSERENVIRONMENT "UnsetUserEnvironment" -#define LAUNCH_KEY_SHUTDOWN "Shutdown" -#define LAUNCH_KEY_SINGLEUSER "SingleUser" -#define LAUNCH_KEY_GETRESOURCELIMITS "GetResourceLimits" -#define LAUNCH_KEY_SETRESOURCELIMITS "SetResourceLimits" -#define LAUNCH_KEY_GETRUSAGESELF "GetResourceUsageSelf" -#define LAUNCH_KEY_GETRUSAGECHILDREN "GetResourceUsageChildren" +#define LAUNCH_KEY_SETUSERENVIRONMENT "SetUserEnvironment" +#define LAUNCH_KEY_UNSETUSERENVIRONMENT "UnsetUserEnvironment" +#define LAUNCH_KEY_SHUTDOWN "Shutdown" +#define LAUNCH_KEY_SINGLEUSER "SingleUser" +#define LAUNCH_KEY_GETRESOURCELIMITS "GetResourceLimits" +#define LAUNCH_KEY_SETRESOURCELIMITS "SetResourceLimits" +#define LAUNCH_KEY_GETRUSAGESELF "GetResourceUsageSelf" +#define LAUNCH_KEY_GETRUSAGECHILDREN "GetResourceUsageChildren" + +#define LAUNCHD_SOCKET_ENV "LAUNCHD_SOCKET" +#define LAUNCHD_SOCK_PREFIX _PATH_VARTMP "launchd" +#define LAUNCHD_TRUSTED_FD_ENV "__LAUNCHD_FD" +#define LAUNCHD_ASYNC_MSG_KEY "_AsyncMessage" +#define LAUNCH_KEY_BATCHCONTROL "BatchControl" +#define LAUNCH_KEY_BATCHQUERY "BatchQuery" +#define LAUNCHD_DO_APPLE_INTERNAL_LOGGING "__DoAppleInternalLogging__" + +#define LAUNCH_JOBKEY_TRANSACTIONCOUNT "TransactionCount" +#define LAUNCH_JOBKEY_QUARANTINEDATA "QuarantineData" +#define LAUNCH_JOBKEY_SANDBOXPROFILE "SandboxProfile" +#define LAUNCH_JOBKEY_SANDBOXFLAGS "SandboxFlags" +#define LAUNCH_JOBKEY_SANDBOX_NAMED "Named" -#define LAUNCHD_SOCKET_ENV "LAUNCHD_SOCKET" -#define LAUNCHD_SOCK_PREFIX _PATH_VARTMP "launchd" -#define LAUNCHD_TRUSTED_FD_ENV "__LAUNCHD_FD" -#define LAUNCHD_ASYNC_MSG_KEY "_AsyncMessage" -#define LAUNCH_KEY_BATCHCONTROL "BatchControl" -#define LAUNCH_KEY_BATCHQUERY "BatchQuery" +#define LAUNCH_JOBKEY_ENTERKERNELDEBUGGERBEFOREKILL "EnterKernelDebuggerBeforeKill" +#define LAUNCH_JOBKEY_PERJOBMACHSERVICES "PerJobMachServices" +#define LAUNCH_JOBKEY_SERVICEIPC "ServiceIPC" +#define LAUNCH_JOBKEY_BINARYORDERPREFERENCE "BinaryOrderPreference" +#define LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER "MachExceptionHandler" -#define LAUNCH_JOBKEY_TRANSACTIONCOUNT "TransactionCount" -#define LAUNCH_JOBKEY_QUARANTINEDATA "QuarantineData" -#define LAUNCH_JOBKEY_SANDBOXPROFILE "SandboxProfile" -#define LAUNCH_JOBKEY_SANDBOXFLAGS "SandboxFlags" -#define LAUNCH_JOBKEY_SANDBOX_NAMED "Named" - -#define LAUNCH_JOBKEY_ENTERKERNELDEBUGGERBEFOREKILL "EnterKernelDebuggerBeforeKill" -#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" -#define LAUNCH_JOBKEY_MACH_TASKSPECIALPORT "TaskSpecialPort" -#define LAUNCH_JOBKEY_MACH_HOSTSPECIALPORT "HostSpecialPort" +#define LAUNCH_JOBKEY_MACH_KUNCSERVER "kUNCServer" +#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; Modified: trunk/launchd/src/liblaunch_public.h =================================================================== --- trunk/launchd/src/liblaunch_public.h 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/liblaunch_public.h 2008-09-17 18:41:18 UTC (rev 23712) @@ -44,109 +44,109 @@ #endif -#define LAUNCH_KEY_SUBMITJOB "SubmitJob" -#define LAUNCH_KEY_REMOVEJOB "RemoveJob" -#define LAUNCH_KEY_STARTJOB "StartJob" -#define LAUNCH_KEY_STOPJOB "StopJob" -#define LAUNCH_KEY_GETJOB "GetJob" -#define LAUNCH_KEY_GETJOBS "GetJobs" -#define LAUNCH_KEY_CHECKIN "CheckIn" +#define LAUNCH_KEY_SUBMITJOB "SubmitJob" +#define LAUNCH_KEY_REMOVEJOB "RemoveJob" +#define LAUNCH_KEY_STARTJOB "StartJob" +#define LAUNCH_KEY_STOPJOB "StopJob" +#define LAUNCH_KEY_GETJOB "GetJob" +#define LAUNCH_KEY_GETJOBS "GetJobs" +#define LAUNCH_KEY_CHECKIN "CheckIn" -#define LAUNCH_JOBKEY_LABEL "Label" -#define LAUNCH_JOBKEY_DISABLED "Disabled" -#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" +#define LAUNCH_JOBKEY_LABEL "Label" +#define LAUNCH_JOBKEY_DISABLED "Disabled" +#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" #define LAUNCH_JOBKEY_MACHSERVICELOOKUPPOLICIES "MachServiceLookupPolicies" -#define LAUNCH_JOBKEY_INETDCOMPATIBILITY "inetdCompatibility" -#define LAUNCH_JOBKEY_ENABLEGLOBBING "EnableGlobbing" -#define LAUNCH_JOBKEY_PROGRAMARGUMENTS "ProgramArguments" -#define LAUNCH_JOBKEY_PROGRAM "Program" -#define LAUNCH_JOBKEY_ONDEMAND "OnDemand" -#define LAUNCH_JOBKEY_KEEPALIVE "KeepAlive" -#define LAUNCH_JOBKEY_LIMITLOADTOHOSTS "LimitLoadToHosts" -#define LAUNCH_JOBKEY_LIMITLOADFROMHOSTS "LimitLoadFromHosts" +#define LAUNCH_JOBKEY_INETDCOMPATIBILITY "inetdCompatibility" +#define LAUNCH_JOBKEY_ENABLEGLOBBING "EnableGlobbing" +#define LAUNCH_JOBKEY_PROGRAMARGUMENTS "ProgramArguments" +#define LAUNCH_JOBKEY_PROGRAM "Program" +#define LAUNCH_JOBKEY_ONDEMAND "OnDemand" +#define LAUNCH_JOBKEY_KEEPALIVE "KeepAlive" +#define LAUNCH_JOBKEY_LIMITLOADTOHOSTS "LimitLoadToHosts" +#define LAUNCH_JOBKEY_LIMITLOADFROMHOSTS "LimitLoadFromHosts" #define LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE "LimitLoadToSessionType" -#define LAUNCH_JOBKEY_RUNATLOAD "RunAtLoad" -#define LAUNCH_JOBKEY_ROOTDIRECTORY "RootDirectory" -#define LAUNCH_JOBKEY_WORKINGDIRECTORY "WorkingDirectory" -#define LAUNCH_JOBKEY_ENVIRONMENTVARIABLES "EnvironmentVariables" +#define LAUNCH_JOBKEY_RUNATLOAD "RunAtLoad" +#define LAUNCH_JOBKEY_ROOTDIRECTORY "RootDirectory" +#define LAUNCH_JOBKEY_WORKINGDIRECTORY "WorkingDirectory" +#define LAUNCH_JOBKEY_ENVIRONMENTVARIABLES "EnvironmentVariables" #define LAUNCH_JOBKEY_USERENVIRONMENTVARIABLES "UserEnvironmentVariables" -#define LAUNCH_JOBKEY_UMASK "Umask" -#define LAUNCH_JOBKEY_NICE "Nice" -#define LAUNCH_JOBKEY_HOPEFULLYEXITSFIRST "HopefullyExitsFirst" -#define LAUNCH_JOBKEY_HOPEFULLYEXITSLAST "HopefullyExitsLast" -#define LAUNCH_JOBKEY_LOWPRIORITYIO "LowPriorityIO" -#define LAUNCH_JOBKEY_SESSIONCREATE "SessionCreate" -#define LAUNCH_JOBKEY_STARTONMOUNT "StartOnMount" -#define LAUNCH_JOBKEY_SOFTRESOURCELIMITS "SoftResourceLimits" -#define LAUNCH_JOBKEY_HARDRESOURCELIMITS "HardResourceLimits" -#define LAUNCH_JOBKEY_STANDARDINPATH "StandardInPath" -#define LAUNCH_JOBKEY_STANDARDOUTPATH "StandardOutPath" -#define LAUNCH_JOBKEY_STANDARDERRORPATH "StandardErrorPath" -#define LAUNCH_JOBKEY_DEBUG "Debug" -#define LAUNCH_JOBKEY_WAITFORDEBUGGER "WaitForDebugger" -#define LAUNCH_JOBKEY_QUEUEDIRECTORIES "QueueDirectories" -#define LAUNCH_JOBKEY_WATCHPATHS "WatchPaths" -#define LAUNCH_JOBKEY_STARTINTERVAL "StartInterval" -#define LAUNCH_JOBKEY_STARTCALENDARINTERVAL "StartCalendarInterval" -#define LAUNCH_JOBKEY_BONJOURFDS "BonjourFDs" -#define LAUNCH_JOBKEY_LASTEXITSTATUS "LastExitStatus" -#define LAUNCH_JOBKEY_PID "PID" -#define LAUNCH_JOBKEY_THROTTLEINTERVAL "ThrottleInterval" -#define LAUNCH_JOBKEY_LAUNCHONLYONCE "LaunchOnlyOnce" -#define LAUNCH_JOBKEY_ABANDONPROCESSGROUP "AbandonProcessGroup" -#define LAUNCH_JOBKEY_POLICIES "Policies" -#define LAUNCH_JOBKEY_ENABLETRANSACTIONS "EnableTransactions" +#define LAUNCH_JOBKEY_UMASK "Umask" +#define LAUNCH_JOBKEY_NICE "Nice" +#define LAUNCH_JOBKEY_HOPEFULLYEXITSFIRST "HopefullyExitsFirst" +#define LAUNCH_JOBKEY_HOPEFULLYEXITSLAST "HopefullyExitsLast" +#define LAUNCH_JOBKEY_LOWPRIORITYIO "LowPriorityIO" +#define LAUNCH_JOBKEY_SESSIONCREATE "SessionCreate" +#define LAUNCH_JOBKEY_STARTONMOUNT "StartOnMount" +#define LAUNCH_JOBKEY_SOFTRESOURCELIMITS "SoftResourceLimits" +#define LAUNCH_JOBKEY_HARDRESOURCELIMITS "HardResourceLimits" +#define LAUNCH_JOBKEY_STANDARDINPATH "StandardInPath" +#define LAUNCH_JOBKEY_STANDARDOUTPATH "StandardOutPath" +#define LAUNCH_JOBKEY_STANDARDERRORPATH "StandardErrorPath" +#define LAUNCH_JOBKEY_DEBUG "Debug" +#define LAUNCH_JOBKEY_WAITFORDEBUGGER "WaitForDebugger" +#define LAUNCH_JOBKEY_QUEUEDIRECTORIES "QueueDirectories" +#define LAUNCH_JOBKEY_WATCHPATHS "WatchPaths" +#define LAUNCH_JOBKEY_STARTINTERVAL "StartInterval" +#define LAUNCH_JOBKEY_STARTCALENDARINTERVAL "StartCalendarInterval" +#define LAUNCH_JOBKEY_BONJOURFDS "BonjourFDs" +#define LAUNCH_JOBKEY_LASTEXITSTATUS "LastExitStatus" +#define LAUNCH_JOBKEY_PID "PID" +#define LAUNCH_JOBKEY_THROTTLEINTERVAL "ThrottleInterval" +#define LAUNCH_JOBKEY_LAUNCHONLYONCE "LaunchOnlyOnce" +#define LAUNCH_JOBKEY_ABANDONPROCESSGROUP "AbandonProcessGroup" +#define LAUNCH_JOBKEY_POLICIES "Policies" +#define LAUNCH_JOBKEY_ENABLETRANSACTIONS "EnableTransactions" #define LAUNCH_JOBPOLICY_DENYCREATINGOTHERJOBS "DenyCreatingOtherJobs" -#define LAUNCH_JOBINETDCOMPATIBILITY_WAIT "Wait" +#define LAUNCH_JOBINETDCOMPATIBILITY_WAIT "Wait" -#define LAUNCH_JOBKEY_MACH_RESETATCLOSE "ResetAtClose" -#define LAUNCH_JOBKEY_MACH_HIDEUNTILCHECKIN "HideUntilCheckIn" +#define LAUNCH_JOBKEY_MACH_RESETATCLOSE "ResetAtClose" +#define LAUNCH_JOBKEY_MACH_HIDEUNTILCHECKIN "HideUntilCheckIn" #define LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT "SuccessfulExit" #define LAUNCH_JOBKEY_KEEPALIVE_NETWORKSTATE "NetworkState" -#define LAUNCH_JOBKEY_KEEPALIVE_PATHSTATE "PathState" +#define LAUNCH_JOBKEY_KEEPALIVE_PATHSTATE "PathState" #define LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBACTIVE "OtherJobActive" #define LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBENABLED "OtherJobEnabled" -#define LAUNCH_JOBKEY_CAL_MINUTE "Minute" -#define LAUNCH_JOBKEY_CAL_HOUR "Hour" -#define LAUNCH_JOBKEY_CAL_DAY "Day" -#define LAUNCH_JOBKEY_CAL_WEEKDAY "Weekday" -#define LAUNCH_JOBKEY_CAL_MONTH "Month" +#define LAUNCH_JOBKEY_CAL_MINUTE "Minute" +#define LAUNCH_JOBKEY_CAL_HOUR "Hour" +#define LAUNCH_JOBKEY_CAL_DAY "Day" +#define LAUNCH_JOBKEY_CAL_WEEKDAY "Weekday" +#define LAUNCH_JOBKEY_CAL_MONTH "Month" + +#define LAUNCH_JOBKEY_RESOURCELIMIT_CORE "Core" +#define LAUNCH_JOBKEY_RESOURCELIMIT_CPU "CPU" +#define LAUNCH_JOBKEY_RESOURCELIMIT_DATA "Data" +#define LAUNCH_JOBKEY_RESOURCELIMIT_FSIZE "FileSize" +#define LAUNCH_JOBKEY_RESOURCELIMIT_MEMLOCK "MemoryLock" +#define LAUNCH_JOBKEY_RESOURCELIMIT_NOFILE "NumberOfFiles" +#define LAUNCH_JOBKEY_RESOURCELIMIT_NPROC "NumberOfProcesses" +#define LAUNCH_JOBKEY_RESOURCELIMIT_RSS "ResidentSetSize" +#define LAUNCH_JOBKEY_RESOURCELIMIT_STACK "Stack" -#define LAUNCH_JOBKEY_RESOURCELIMIT_CORE "Core" -#define LAUNCH_JOBKEY_RESOURCELIMIT_CPU "CPU" -#define LAUNCH_JOBKEY_RESOURCELIMIT_DATA "Data" -#define LAUNCH_JOBKEY_RESOURCELIMIT_FSIZE "FileSize" -#define LAUNCH_JOBKEY_RESOURCELIMIT_MEMLOCK "MemoryLock" -#define LAUNCH_JOBKEY_RESOURCELIMIT_NOFILE "NumberOfFiles" -#define LAUNCH_JOBKEY_RESOURCELIMIT_NPROC "NumberOfProcesses" -#define LAUNCH_JOBKEY_RESOURCELIMIT_RSS "ResidentSetSize" -#define LAUNCH_JOBKEY_RESOURCELIMIT_STACK "Stack" +#define LAUNCH_JOBKEY_DISABLED_MACHINETYPE "MachineType" +#define LAUNCH_JOBKEY_DISABLED_MODELNAME "ModelName" -#define LAUNCH_JOBKEY_DISABLED_MACHINETYPE "MachineType" -#define LAUNCH_JOBKEY_DISABLED_MODELNAME "ModelName" +#define LAUNCH_JOBSOCKETKEY_TYPE "SockType" +#define LAUNCH_JOBSOCKETKEY_PASSIVE "SockPassive" +#define LAUNCH_JOBSOCKETKEY_BONJOUR "Bonjour" +#define LAUNCH_JOBSOCKETKEY_SECUREWITHKEY "SecureSocketWithKey" +#define LAUNCH_JOBSOCKETKEY_PATHNAME "SockPathName" +#define LAUNCH_JOBSOCKETKEY_PATHMODE "SockPathMode" +#define LAUNCH_JOBSOCKETKEY_NODENAME "SockNodeName" +#define LAUNCH_JOBSOCKETKEY_SERVICENAME "SockServiceName" +#define LAUNCH_JOBSOCKETKEY_FAMILY "SockFamily" +#define LAUNCH_JOBSOCKETKEY_PROTOCOL "SockProtocol" +#define LAUNCH_JOBSOCKETKEY_MULTICASTGROUP "MulticastGroup" -#define LAUNCH_JOBSOCKETKEY_TYPE "SockType" -#define LAUNCH_JOBSOCKETKEY_PASSIVE "SockPassive" -#define LAUNCH_JOBSOCKETKEY_BONJOUR "Bonjour" -#define LAUNCH_JOBSOCKETKEY_SECUREWITHKEY "SecureSocketWithKey" -#define LAUNCH_JOBSOCKETKEY_PATHNAME "SockPathName" -#define LAUNCH_JOBSOCKETKEY_PATHMODE "SockPathMode" -#define LAUNCH_JOBSOCKETKEY_NODENAME "SockNodeName" -#define LAUNCH_JOBSOCKETKEY_SERVICENAME "SockServiceName" -#define LAUNCH_JOBSOCKETKEY_FAMILY "SockFamily" -#define LAUNCH_JOBSOCKETKEY_PROTOCOL "SockProtocol" -#define LAUNCH_JOBSOCKETKEY_MULTICASTGROUP "MulticastGroup" - typedef struct _launch_data *launch_data_t; typedef enum { Modified: trunk/launchd/src/libvproc.c =================================================================== --- trunk/launchd/src/libvproc.c 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/libvproc.c 2008-09-17 18:41:18 UTC (rev 23712) @@ -41,6 +41,7 @@ #include "liblaunch_public.h" #include "liblaunch_private.h" #include "liblaunch_internal.h" +#include "launchd_ktrace.h" #include "protocol_vproc.h" @@ -83,6 +84,19 @@ vproc_shmem = (struct vproc_shmem_s *)vm_addr; } +static void +vproc_client_init(void) +{ + char *val = getenv(LAUNCHD_DO_APPLE_INTERNAL_LOGGING); + if( val ) { + if( strncmp(val, "true", sizeof("true") - 1) == 0 ) { + do_apple_internal_logging = true; + } + } + + vproc_shmem_init(); +} + vproc_transaction_t vproc_transaction_begin(vproc_t vp __attribute__((unused))) { @@ -97,7 +111,7 @@ _vproc_transaction_begin(void) { if (unlikely(vproc_shmem == NULL)) { - int po_r = pthread_once(&shmem_inited, vproc_shmem_init); + int po_r = pthread_once(&shmem_inited, vproc_client_init); if (po_r != 0 || vproc_shmem == NULL) { return; } @@ -117,6 +131,8 @@ abort(); } } while( !__sync_bool_compare_and_swap(&vproc_shmem->vp_shmem_transaction_cnt, old, old + 1) ); + + runtime_ktrace(RTKT_VPROC_TRANSACTION_INCREMENT, old + 1, 0, 0); } size_t @@ -172,6 +188,7 @@ newval = __sync_sub_and_fetch(&vproc_shmem->vp_shmem_transaction_cnt, 1); + runtime_ktrace(RTKT_VPROC_TRANSACTION_DECREMENT, newval, 0, 0); if (unlikely(newval < 0)) { if (vproc_shmem->vp_shmem_flags & VPROC_SHMEM_EXITING) { raise(SIGKILL); @@ -199,7 +216,7 @@ typeof(vproc_shmem->vp_shmem_standby_cnt) newval; if (unlikely(vproc_shmem == NULL)) { - int po_r = pthread_once(&shmem_inited, vproc_shmem_init); + int po_r = pthread_once(&shmem_inited, vproc_client_init); if (po_r != 0 || vproc_shmem == NULL) { return; } @@ -229,6 +246,11 @@ { typeof(vproc_shmem->vp_shmem_standby_cnt) newval; + if( unlikely(vproc_shmem == NULL) ) { + __crashreporter_info__ = "Process called vproc_standby_end() when not enrolled in transaction model."; + abort(); + } + newval = __sync_sub_and_fetch(&vproc_shmem->vp_shmem_standby_cnt, 1); if (unlikely(newval < 0)) { @@ -648,7 +670,7 @@ case VPROC_GSK_TRANSACTIONS_ENABLED: /* Shared memory region is required for transactions. */ if( unlikely(vproc_shmem == NULL) ) { - int po_r = pthread_once(&shmem_inited, vproc_shmem_init); + int po_r = pthread_once(&shmem_inited, vproc_client_init); if( po_r != 0 || vproc_shmem == NULL ) { if( outval ) { *outval = -1; Modified: trunk/launchd/src/libvproc_private.h =================================================================== --- trunk/launchd/src/libvproc_private.h 2008-09-03 00:07:58 UTC (rev 23711) +++ trunk/launchd/src/libvproc_private.h 2008-09-17 18:41:18 UTC (rev 23712) @@ -20,6 +20,7 @@ * @APPLE_APACHE_LICENSE_HEADER_END@ */ +#include #include #include #include @@ -27,6 +28,8 @@ #include #include +#define VPROC_HAS_TRANSACTIONS 1 + __BEGIN_DECLS #pragma GCC visibility push(default) @@ -73,24 +76,23 @@ void _vproc_logv(int pri, int err, const char *msg, va_list ap) __attribute__((format(printf, 3, 0))); #define VPROCMGR_SESSION_LOGINWINDOW "LoginWindow" -#define VPROCMGR_SESSION_BACKGROUND "Background" -#define VPROCMGR_SESSION_AQUA "Aqua" -#define VPROCMGR_SESSION_STANDARDIO "StandardIO" -#define VPROCMGR_SESSION_SYSTEM "System" +#define VPROCMGR_SESSION_BACKGROUND "Background" +#define VPROCMGR_SESSION_AQUA "Aqua" +#define VPROCMGR_SESSION_STANDARDIO "StandardIO" +#define VPROCMGR_SESSION_SYSTEM "System" vproc_err_t _vprocmgr_move_subset_to_user(uid_t target_user, const char *session_type); -void _vproc_standby_begin(void); -void _vproc_standby_end(void); -size_t _vproc_standby_count(void); -size_t _vproc_standby_timeout(void); +void _vproc_standby_begin(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA); +void _vproc_standby_end(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA); +size_t _vproc_standby_count(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA); +size_t _vproc_standby_timeout(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA); -void _vproc_transaction_try_exit(int status); -void _vproc_transaction_begin(void); -void _vproc_transaction_end(void); -size_t _vproc_transaction_count(void); +void _vproc_transaction_try_exit(int status) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA); +void _vproc_transaction_begin(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA); +void _vproc_transaction_end(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA); +size_t _vproc_transaction_count(void) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_NA); - #pragma GCC visibility pop __END_DECLS -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20080917/a57c69ca/attachment-0001.html From source_changes at macosforge.org Wed Sep 17 17:40:52 2008 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Wed, 17 Sep 2008 17:40:52 -0700 (PDT) Subject: [launchd-changes] [23713] tags/launchd-284/ Message-ID: <20080918004052.31B5837B0C8@beta.macosforge.org> Revision: 23713 http://trac.macosforge.org/projects/launchd/changeset/23713 Author: dsorresso at apple.com Date: 2008-09-17 17:40:51 -0700 (Wed, 17 Sep 2008) Log Message: ----------- "Tagging launchd-284 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-284/ Property changes on: tags/launchd-284 ___________________________________________________________________ Added: svn:mergeinfo + /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20080917/4e594c1a/attachment.html From source_changes at macosforge.org Fri Sep 19 14:55:47 2008 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Fri, 19 Sep 2008 14:55:47 -0700 (PDT) Subject: [launchd-changes] [23714] branches/SULeopard/launchd/src/launchd_core_logic.c Message-ID: <20080919215547.9259D392220@beta.macosforge.org> Revision: 23714 http://trac.macosforge.org/projects/launchd/changeset/23714 Author: dsorresso at apple.com Date: 2008-09-19 14:55:47 -0700 (Fri, 19 Sep 2008) Log Message: ----------- SULeoZip: sandbox_init: Could not set default launchd policy, err=1100 Modified Paths: -------------- branches/SULeopard/launchd/src/launchd_core_logic.c Modified: branches/SULeopard/launchd/src/launchd_core_logic.c =================================================================== --- branches/SULeopard/launchd/src/launchd_core_logic.c 2008-09-18 00:40:51 UTC (rev 23713) +++ branches/SULeopard/launchd/src/launchd_core_logic.c 2008-09-19 21:55:47 UTC (rev 23714) @@ -6668,13 +6668,31 @@ runtime_get_caller_creds(&ldc); #if TARGET_OS_EMBEDDED - if (ldc.euid) { -#else - if (ldc.euid && (ldc.euid != getuid())) { -#endif + if( ldc.euid ) { return BOOTSTRAP_NOT_PRIVILEGED; } +#else + if( ldc.euid && (ldc.euid != getuid()) ) { + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, target_pid }; + struct kinfo_proc kp; + size_t len = sizeof(kp); + job_assumes(j, sysctl(mib, 4, &kp, &len, NULL, 0) != -1); + job_assumes(j, len == sizeof(kp)); + + uid_t kp_euid = kp.kp_eproc.e_ucred.cr_uid; + uid_t kp_uid = kp.kp_eproc.e_pcred.p_ruid; + + if( ldc.euid == kp_euid ) { + job_log(j, LOG_DEBUG, "Working around rdar://problem/5982485 and allowing job to set policy for PID %u.", target_pid); + } else { + job_log(j, LOG_ERR, "Denied Mach service policy update requested by UID/EUID %u/%u against PID %u with UID/EUID %u/%u due to mismatched credentials.", ldc.uid, ldc.euid, target_pid, kp_uid, kp_euid); + + return BOOTSTRAP_NOT_PRIVILEGED; + } + } +#endif + if (!job_assumes(j, (target_j = jobmgr_find_by_pid(j->mgr, target_pid, true)) != NULL)) { return BOOTSTRAP_NO_MEMORY; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20080919/0ff310c5/attachment.html From source_changes at macosforge.org Fri Sep 19 15:50:42 2008 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Fri, 19 Sep 2008 15:50:42 -0700 (PDT) Subject: [launchd-changes] [23715] tags/launchd-258.19/ Message-ID: <20080919225043.08F7F392E69@beta.macosforge.org> Revision: 23715 http://trac.macosforge.org/projects/launchd/changeset/23715 Author: dsorresso at apple.com Date: 2008-09-19 15:50:42 -0700 (Fri, 19 Sep 2008) Log Message: ----------- "Tagging launchd-258.19 from https://svn.macosforge.org/repository/launchd/branches/SULeopard" Added Paths: ----------- tags/launchd-258.19/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20080919/510a4808/attachment.html From source_changes at macosforge.org Tue Sep 30 15:09:48 2008 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 30 Sep 2008 15:09:48 -0700 (PDT) Subject: [launchd-changes] [23716] branches/PR-6046664/ Message-ID: <20080930220948.A0A3C4490B0@beta.macosforge.org> Revision: 23716 http://trac.macosforge.org/projects/launchd/changeset/23716 Author: dsorresso at apple.com Date: 2008-09-30 15:09:48 -0700 (Tue, 30 Sep 2008) Log Message: ----------- Creating branch PR-6046664 for rdar://problem/6046664. Added Paths: ----------- branches/PR-6046664/ Property changes on: branches/PR-6046664 ___________________________________________________________________ Added: svn:mergeinfo + /branches/PR-5898404:23681-23700 /branches/PR-5978442:23651-23701 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20080930/907e1034/attachment.html From source_changes at macosforge.org Tue Sep 30 15:33:13 2008 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 30 Sep 2008 15:33:13 -0700 (PDT) Subject: [launchd-changes] [23717] branches/PR-6046664/launchd/src Message-ID: <20080930223313.6CD60449458@beta.macosforge.org> Revision: 23717 http://trac.macosforge.org/projects/launchd/changeset/23717 Author: dsorresso at apple.com Date: 2008-09-30 15:33:12 -0700 (Tue, 30 Sep 2008) Log Message: ----------- Initial set of changes for flattening of the per-user Mach namespace. Some highlights: Per-user launchd's now consult the root job manager's MachServices hash for all lookups. The root user now gets a per-user launchd, no longer uses a sub-manager of the system launchd. There is now a bstree launchctl subcommand that displays the entire Mach bootstrap tree. Added bootstrap_lookup_per_user_context() to libbootstrap (private). Changed to job_mig_lookup_per_user_context() to forward requests from root-owned processes onto the system launchd if they come through to a per-user launchd first. This will let root processes under a per-user bootstrap look up another per-user bootstrap (i.e. login(1)). This SPI is intended to replace vproc_move_subset_to_user() in the launchd PAM module. Changed job_mig_lookup_per_user_context() to return the current per-user context if the request's UID matches that of the per-user launchd it went to. Added bootstrap_lookup_children() to libbootstrap (private). Added bootstrap_root() to libbootstrap (private). Untested. Modified Paths: -------------- branches/PR-6046664/launchd/src/launchctl.c branches/PR-6046664/launchd/src/launchd.c branches/PR-6046664/launchd/src/launchd_core_logic.c branches/PR-6046664/launchd/src/launchd_runtime.c branches/PR-6046664/launchd/src/launchd_runtime.h branches/PR-6046664/launchd/src/launchproxy.c branches/PR-6046664/launchd/src/libbootstrap.c branches/PR-6046664/launchd/src/libbootstrap_private.h branches/PR-6046664/launchd/src/libbootstrap_public.h branches/PR-6046664/launchd/src/libvproc.c branches/PR-6046664/launchd/src/protocol_job.defs branches/PR-6046664/launchd/src/protocol_job_forward.defs branches/PR-6046664/launchd/src/protocol_job_reply.defs Modified: branches/PR-6046664/launchd/src/launchctl.c =================================================================== --- branches/PR-6046664/launchd/src/launchctl.c 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/launchctl.c 2008-09-30 22:33:12 UTC (rev 23717) @@ -22,6 +22,7 @@ #include "liblaunch_public.h" #include "liblaunch_private.h" +#include "libbootstrap_private.h" #include "libbootstrap_public.h" #include "libvproc_public.h" #include "libvproc_private.h" @@ -42,7 +43,12 @@ #include #include #include + +#ifndef SO_EXECPATH + #define SO_EXECPATH 0x1085 +#endif #include + #include #include #include @@ -180,7 +186,11 @@ static int getrusage_cmd(int argc, char *const argv[]); static int bsexec_cmd(int argc, char *const argv[]); static int bslist_cmd(int argc, char *const argv[]); +static int bstree_cmd(int argc, char * const argv[]); +static int _bslist_cmd(mach_port_t bsport, unsigned int depth); +static int _bstree_cmd(mach_port_t bsport, unsigned int depth); + static int exit_cmd(int argc, char *const argv[]) __attribute__((noreturn)); static int help_cmd(int argc, char *const argv[]); @@ -212,9 +222,10 @@ { "umask", umask_cmd, "Change launchd's umask" }, { "bsexec", bsexec_cmd, "Execute a process within a different Mach bootstrap subset" }, { "bslist", bslist_cmd, "List Mach bootstrap services and optional servers" }, + { "bstree", bstree_cmd, "Show the entire Mach bootstrap tree." }, { "exit", exit_cmd, "Exit the interactive invocation of launchctl" }, { "quit", exit_cmd, "Quit the interactive invocation of launchctl" }, - { "help", help_cmd, "This help output" }, + { "help", help_cmd, "This help output" } }; static bool istty; @@ -1646,7 +1657,7 @@ if (strcasecmp(session_type, VPROCMGR_SESSION_BACKGROUND) == 0) { read_launchd_conf(); -#if HAVE_SECURITY +#if 0 assumes(SessionCreate(sessionKeepCurrentBootstrap, 0) == 0); #endif } @@ -2546,6 +2557,8 @@ return 1; } } while (getrootbs && last_bport != bport); + } else if( strcmp(s, "0") == 0 ) { + bport = MACH_PORT_NULL; } else { int pid = atoi(s); @@ -2599,18 +2612,14 @@ } int -bslist_cmd(int argc, char *const argv[]) +_bslist_cmd(mach_port_t bport, unsigned int depth) { kern_return_t result; - mach_port_t bport = bootstrap_port; name_array_t service_names; mach_msg_type_number_t service_cnt, service_active_cnt; bootstrap_status_array_t service_actives; unsigned int i; - if (argc == 2) - bport = str2bsport(argv[1]); - if (bport == MACH_PORT_NULL) { fprintf(stderr, "Invalid bootstrap port\n"); return 1; @@ -2624,12 +2633,67 @@ #define bport_state(x) (((x) == BOOTSTRAP_STATUS_ACTIVE) ? "A" : ((x) == BOOTSTRAP_STATUS_ON_DEMAND) ? "D" : "I") - for (i = 0; i < service_cnt ; i++) - fprintf(stdout, "%-3s%s\n", bport_state((service_actives[i])), service_names[i]); + for (i = 0; i < service_cnt ; i++) { + fprintf(stdout, "%*s%-3s%s\n", depth, "", bport_state((service_actives[i])), service_names[i]); + } return 0; } +int +bslist_cmd(int argc, char *const argv[]) +{ + mach_port_t bport = bootstrap_port; + if( argc == 2 ) { + bport = str2bsport(argv[1]); + } + + if( bport == MACH_PORT_NULL ) { + fprintf(stderr, "Invalid bootstrap port\n"); + return 1; + } + + return _bslist_cmd(bport, 0); +} + +int +_bstree_cmd(mach_port_t bsport, unsigned int depth) +{ + if( bsport == MACH_PORT_NULL ) { + fprintf(stderr, "No root port!\n"); + return 1; + } + + mach_port_array_t child_ports = NULL; + name_array_t child_names = NULL; + unsigned int cnt = 0; + + kern_return_t kr = bootstrap_lookup_children(bsport, &child_ports, &child_names, (mach_msg_type_number_t *)&cnt); + if( kr != BOOTSTRAP_SUCCESS && kr != BOOTSTRAP_NO_CHILDREN ) { + fprintf(stderr, "%s(): bootstrap_lookup_children(): %d\n", __func__, kr); + return 1; + } + + unsigned int i = 0; + _bslist_cmd(bsport, depth); + + for( i = 0; i < cnt; i++ ) { + fprintf(stdout, "%*s%s/\n", depth, "", child_names[i]); + if( child_ports[i] != MACH_PORT_NULL ) { + _bstree_cmd(child_ports[i], depth + 4); + } + } + + return 0; +} + +int +bstree_cmd(int argc __attribute__((unused)), char * const argv[] __attribute__((unused))) +{ + fprintf(stdout, "System/\n"); + return _bstree_cmd(str2bsport("/"), 4); +} + bool is_legacy_mach_job(launch_data_t obj) { Modified: branches/PR-6046664/launchd/src/launchd.c =================================================================== --- branches/PR-6046664/launchd/src/launchd.c 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/launchd.c 2008-09-30 22:33:12 UTC (rev 23717) @@ -106,11 +106,15 @@ bool shutdown_in_progress; bool fake_shutdown_in_progress; bool network_up; -char g_username[128] = "__UnknownUserToLaunchd_DontPanic_NotImportant__"; +char *g_username = "__UninitializedUser__"; int main(int argc, char *const *argv) { + if( getpid() == 1 ) { + printf("launchd[1] is starting.\n"); + } + const char *stdouterr_path = low_level_debug ? _PATH_CONSOLE : _PATH_DEVNULL; bool sflag = false; int ch; @@ -162,12 +166,9 @@ int64_t now = runtime_get_wall_time(); - struct passwd *pwent = getpwuid(getuid()); - if( pwent ) { - strlcpy(g_username, pwent->pw_name, sizeof(g_username) - 1); - } + g_username = getenv("LOGNAME"); - runtime_syslog(LOG_NOTICE, "Per-user launchd for UID %u (%s) began at: %lld.%06llu", getuid(), g_username, now / USEC_PER_SEC, now % USEC_PER_SEC); + runtime_syslog(LOG_DEBUG, "Per-user launchd for UID %u (%s) began at: %lld.%06llu", getuid(), g_username, now / USEC_PER_SEC, now % USEC_PER_SEC); } monitor_networking_state(); @@ -313,7 +314,7 @@ now = runtime_get_wall_time(); char *term_who = pid1_magic ? "System shutdown" : "Per-user launchd termination"; - runtime_syslog(LOG_NOTICE, "%s began at: %lld.%06llu", term_who, now / USEC_PER_SEC, now % USEC_PER_SEC); + runtime_syslog(LOG_DEBUG, "%s began at: %lld.%06llu", term_who, now / USEC_PER_SEC, now % USEC_PER_SEC); launchd_assert(jobmgr_shutdown(root_jobmgr) != NULL); } @@ -336,6 +337,7 @@ launchd_SessionCreate(void) { #if HAVE_SECURITY + runtime_syslog(LOG_NOTICE, "%s(): Called.", __func__); OSStatus (*sescr)(SessionCreationFlags flags, SessionAttributeBits attributes); void *seclib; Modified: branches/PR-6046664/launchd/src/launchd_core_logic.c =================================================================== --- branches/PR-6046664/launchd/src/launchd_core_logic.c 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/launchd_core_logic.c 2008-09-30 22:33:12 UTC (rev 23717) @@ -289,9 +289,9 @@ kq_callback kqjobmgr_callback; SLIST_ENTRY(jobmgr_s) sle; SLIST_HEAD(, jobmgr_s) submgrs; + LIST_HEAD(, machservice) ms_hash[MACHSERVICE_HASH_SIZE]; LIST_HEAD(, job_s) jobs; LIST_HEAD(, job_s) active_jobs[ACTIVE_JOB_HASH_SIZE]; - LIST_HEAD(, machservice) ms_hash[MACHSERVICE_HASH_SIZE]; LIST_HEAD(, job_s) global_env_jobs; mach_port_t jm_port; mach_port_t req_port; @@ -308,7 +308,7 @@ }; #define jobmgr_assumes(jm, e) \ - (unlikely(!(e)) ? jobmgr_log_bug(jm, __LINE__), false : true) + (unlikely(!(e)) ? jobmgr_log_bug(jm, __LINE__, #e), false : true) static jobmgr_t jobmgr_new(jobmgr_t jm, mach_port_t requestorport, mach_port_t transfer_port, bool sflag, const char *name); static job_t jobmgr_import2(jobmgr_t jm, launch_data_t pload); @@ -331,7 +331,7 @@ 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, unsigned int line); +static void jobmgr_log_bug(jobmgr_t jm, unsigned int line, const char *test); #define AUTO_PICK_LEGACY_LABEL (const char *)(~0) @@ -453,7 +453,7 @@ #define job_assumes(j, e) \ - (unlikely(!(e)) ? job_log_bug(j, __LINE__), false : true) + (unlikely(!(e)) ? job_log_bug(j, __LINE__, #e), false : true) static void job_import_keys(launch_data_t obj, const char *key, void *context); static void job_import_bool(job_t j, const char *key, bool value); @@ -480,7 +480,6 @@ 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); INTERNAL_ABI 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); @@ -495,7 +494,7 @@ 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) __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, unsigned int line); +static void job_log_bug(job_t j, unsigned int line, const char *test); static void job_log_stdouterr2(job_t j, const char *msg, ...); static void job_set_exeception_port(job_t j, mach_port_t port); static kern_return_t job_handle_mpm_wait(job_t j, mach_port_t srp, int *waitstatus); @@ -526,7 +525,6 @@ /* miscellaneous file local functions */ static size_t get_kern_max_proc(void); -static void ensure_root_bkgd_setup(void); static int dir_has_files(job_t j, const char *path); static char **mach_cmd2argv(const char *string); static size_t our_strhash(const char *s) __attribute__((pure)); @@ -540,7 +538,6 @@ static mach_port_t the_exception_server; static bool did_first_per_user_launchd_BootCache_hack; #define JOB_BOOTCACHE_HACK_CHECK(j) (unlikely(j->per_user && !did_first_per_user_launchd_BootCache_hack && (j->mach_uid >= 500) && (j->mach_uid != (uid_t)-2))) -static jobmgr_t background_jobmgr; static job_t workaround_5477111; /* process wide globals */ @@ -871,7 +868,7 @@ jobmgr_t jmi; job_t ji; - jobmgr_log(jm, LOG_DEBUG, "Removed job manager"); + jobmgr_log(jm, LOG_NOTICE, "Removed job manager"); if (!jobmgr_assumes(jm, SLIST_EMPTY(&jm->submgrs))) { while ((jmi = SLIST_FIRST(&jm->submgrs))) { @@ -893,10 +890,6 @@ jobmgr_assumes(jm, launchd_mport_close_recv(jm->jm_port) == KERN_SUCCESS); } - if (jm == background_jobmgr) { - background_jobmgr = NULL; - } - if (jm->parentmgr) { runtime_del_weak_ref(); SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); @@ -1283,8 +1276,7 @@ } if (jp && !jp->anonymous && unlikely(!(kp.kp_proc.p_flag & P_EXEC))) { - job_log(jp, LOG_APPLEONLY, "Called *fork(). Please switch to posix_spawn*(), pthreads or launchd. Child PID %u", - kp.kp_proc.p_pid); + job_log(jp, LOG_APPLEONLY, "Called *fork(). Please switch to posix_spawn*(), pthreads or launchd. Child PID %u", kp.kp_proc.p_pid); } @@ -1358,6 +1350,7 @@ strlcpy(tmp_path, argv[0], sizeof(tmp_path)); bn = basename(tmp_path); /* prog for auto labels is kp.kp_kproc.p_comm */ } + snprintf(auto_label, sizeof(auto_label), "%s.%s", sizeof(void *) == 8 ? "0xdeadbeeffeedface" : "0xbabecafe", bn); label = auto_label; /* This is so we can do gross things later. See NOTE_EXEC for anonymous jobs */ @@ -1625,7 +1618,6 @@ } else if (strcasecmp(key, LAUNCH_JOBKEY_LIMITLOADFROMHOSTS) == 0) { return; } else if (strcasecmp(key, LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE) == 0) { - job_reparent_hack(j, value); return; } break; @@ -2199,7 +2191,6 @@ struct ldcred *ldc = runtime_get_caller_creds(); job_t jr; - jr = job_mig_intran2(root_jobmgr, p, ldc->pid); if (!jobmgr_assumes(root_jobmgr, jr != NULL)) { @@ -3624,7 +3615,7 @@ } void -jobmgr_log_bug(jobmgr_t jm, unsigned int line) +jobmgr_log_bug(jobmgr_t jm, unsigned int line, const char *test) { static const char *file; int saved_errno = errno; @@ -3645,14 +3636,14 @@ /* the only time 'jm' should not be set is if setting up the first bootstrap fails for some reason */ if (likely(jm)) { - jobmgr_log(jm, LOG_NOTICE, "Bug: %s:%u (%s):%u", file, line, buf, saved_errno); + jobmgr_log(jm, LOG_NOTICE, "Bug: %s:%u (%s):%u %s", file, line, buf, saved_errno, test); } else { - runtime_syslog(LOG_NOTICE, "Bug: %s:%u (%s):%u", file, line, buf, saved_errno); + runtime_syslog(LOG_NOTICE, "Bug: %s:%u (%s):%u %s", file, line, buf, saved_errno, test); } } void -job_log_bug(job_t j, unsigned int line) +job_log_bug(job_t j, unsigned int line, const char *test) { static const char *file; int saved_errno = errno; @@ -3673,9 +3664,9 @@ /* I cannot think of any reason why 'j' should ever be NULL, nor have I ever seen the case in the wild */ if (likely(j)) { - job_log(j, LOG_NOTICE, "Bug: %s:%u (%s):%u", file, line, buf, saved_errno); + job_log(j, LOG_NOTICE, "Bug: %s:%u (%s):%u %s", file, line, buf, saved_errno, test); } else { - runtime_syslog(LOG_NOTICE, "Bug: %s:%u (%s):%u", file, line, buf, saved_errno); + runtime_syslog(LOG_NOTICE, "Bug: %s:%u (%s):%u %s", file, line, buf, saved_errno, test); } } @@ -4553,10 +4544,16 @@ } SLIST_INSERT_HEAD(&j->machservices, ms, sle); - LIST_INSERT_HEAD(&j->mgr->ms_hash[hash_ms(ms->name)], ms, name_hash_sle); + + if( pid1_magic ) { + LIST_INSERT_HEAD(&j->mgr->ms_hash[hash_ms(ms->name)], ms, name_hash_sle); + } else { + LIST_INSERT_HEAD(&root_jobmgr->ms_hash[hash_ms(ms->name)], ms, name_hash_sle); + } + LIST_INSERT_HEAD(&port_hash[HASH_PORT(ms->port)], ms, port_hash_sle); - job_log(j, LOG_INFO, "Mach service added: %s", name); + jobmgr_log(j->mgr, LOG_NOTICE, "Mach service %s added.", name); return ms; out_bad2: @@ -4998,7 +4995,7 @@ } } - jobmgr_log(jmr, LOG_DEBUG, "Created job manager%s%s", jm ? " with parent: " : ".", jm ? jm->name : ""); + jobmgr_log(jmr, LOG_NOTICE, "Created job manager%s%s", jm ? " with parent: " : ".", jm ? jm->name : ""); if (bootstrapper) { jobmgr_assumes(jmr, job_dispatch(bootstrapper, true) != NULL); @@ -5020,6 +5017,8 @@ job_t jobmgr_init_session(jobmgr_t jm, const char *session_type, bool sflag) { + jobmgr_log(jm, LOG_NOTICE, "%s(): Bootstrapping %s.", __func__, session_type); + const char *bootstrap_tool[] = { "/bin/launchctl", "bootstrap", "-S", session_type, sflag ? "-s" : NULL, NULL }; char thelabel[1000]; job_t bootstrapper; @@ -5087,37 +5086,60 @@ struct machservice * jobmgr_lookup_service(jobmgr_t jm, const char *name, bool check_parent, pid_t target_pid) -{ +{ struct machservice *ms; job_t target_j; + jobmgr_log(jm, LOG_DEBUG, "%s(): Got lookup request for \"%s\"", __func__, name); + if (target_pid) { - //jobmgr_assumes(jm, !check_parent); + jobmgr_assumes(jm, !check_parent); if (unlikely((target_j = jobmgr_find_by_pid(jm, target_pid, false)) == NULL)) { + jobmgr_log(jm, LOG_DEBUG, "%s(): Couldn't find PID %u in this bootstrap.", __func__, target_pid); return NULL; } + job_log(target_j, LOG_DEBUG, "%s(): Found target job.", __func__); + SLIST_FOREACH(ms, &target_j->machservices, sle) { if (ms->per_pid && strcmp(name, ms->name) == 0) { return ms; } } + job_log(target_j, LOG_DEBUG, "%s(): Couldn't find service \"%s\" in job, giving up.", __func__, name); return NULL; } + + if( pid1_magic ) { + LIST_FOREACH(ms, &jm->ms_hash[hash_ms(name)], name_hash_sle) { + if (!ms->per_pid && strcmp(name, ms->name) == 0) { + return ms; + } + } + + if (jm->parentmgr == NULL || !check_parent) { + jobmgr_log(jm, LOG_DEBUG, "%s(): Couldn't find \"%s\" in this bootstrap, giving up.", __func__, name); + return NULL; + } - LIST_FOREACH(ms, &jm->ms_hash[hash_ms(name)], name_hash_sle) { - if (!ms->per_pid && strcmp(name, ms->name) == 0) { - return ms; + jobmgr_log(jm, LOG_DEBUG, "%s(): Couldn't find \"%s\" in this bootstrap, recursing...", __func__, name); + + return jobmgr_lookup_service(jm->parentmgr, name, true, 0); + } else { + LIST_FOREACH(ms, &root_jobmgr->ms_hash[hash_ms(name)], name_hash_sle) { + if (!ms->per_pid && strcmp(name, ms->name) == 0) { + return ms; + } } - } - - if (jm->parentmgr == NULL || !check_parent) { + + jobmgr_log(jm, LOG_DEBUG, "%s(): Couldn't find \"%s\" in this (flat) bootstrap.", __func__, name); + return NULL; } - - return jobmgr_lookup_service(jm->parentmgr, name, true, 0); + + return NULL; } mach_port_t @@ -5901,9 +5923,7 @@ } kern_return_t -job_mig_swap_complex(job_t j, vproc_gsk_t inkey, vproc_gsk_t outkey, - vm_offset_t inval, mach_msg_type_number_t invalCnt, - vm_offset_t *outval, mach_msg_type_number_t *outvalCnt) +job_mig_swap_complex(job_t j, vproc_gsk_t inkey, vproc_gsk_t outkey, vm_offset_t inval, mach_msg_type_number_t invalCnt, vm_offset_t *outval, mach_msg_type_number_t *outvalCnt) { const char *action; launch_data_t input_obj, output_obj; @@ -6272,23 +6292,8 @@ return 0; } -void -ensure_root_bkgd_setup(void) -{ - if (likely(background_jobmgr) || !pid1_magic) { - return; - } - - if (!jobmgr_assumes(root_jobmgr, (background_jobmgr = jobmgr_new(root_jobmgr, mach_task_self(), MACH_PORT_NULL, false, VPROCMGR_SESSION_BACKGROUND)) != NULL)) { - return; - } - - background_jobmgr->req_port = 0; - jobmgr_assumes(root_jobmgr, launchd_mport_make_send(background_jobmgr->jm_port) == KERN_SUCCESS); -} - kern_return_t -job_mig_lookup_per_user_context(job_t j, uid_t which_user, mach_port_t *up_cont) +job_mig_lookup_per_user_context(job_t j, mach_port_t srp, uid_t which_user, mach_port_t *up_cont) { struct ldcred *ldc = runtime_get_caller_creds(); job_t ji; @@ -6297,27 +6302,40 @@ return BOOTSTRAP_NO_MEMORY; } - job_log(j, LOG_DEBUG, "Looking up per user launchd for UID: %u", which_user); + if( j->per_user ) { + job_log(j, LOG_NOTICE, "Got per-user lookup request from per-user launchd %u.", j->mach_uid); + } if (unlikely(!pid1_magic)) { - job_log(j, LOG_ERR, "Only PID 1 supports per user launchd lookups."); + if( which_user == getuid() ) { + job_log(j, LOG_NOTICE, "Request for local per-user bootstrap (%u). Returning bootstrap port.", which_user); + + launchd_mport_make_send(root_jobmgr->jm_port); + *up_cont = root_jobmgr->jm_port; + return BOOTSTRAP_SUCCESS; + } else if( ldc->euid == 0 ) { + job_log(j, LOG_NOTICE, "Forwarding request for %u's per-user launchd to system launchd.", which_user); + /* Forward the request onto the system launchd. */ + job_assumes(j, vproc_mig_lookup_per_user_context_forward(inherited_bootstrap_port, srp, which_user) == 0); + + /* Have the client wait for the system launchd to get back to it. */ + return MIG_NO_REPLY; + } else { + job_log(j, LOG_ERR, "Only PID 1 supports non-local per user launchd lookups."); + } + return BOOTSTRAP_NOT_PRIVILEGED; } - if (ldc->euid || ldc->uid) { + /* If the request came from a per-user launchd, it was forwarded on behalf of a root-owned client. */ + if( !j->per_user && (ldc->euid || ldc->uid) ) { which_user = ldc->euid ?: ldc->uid; } + job_log(j, LOG_NOTICE, "Looking up per user launchd for UID: %u", which_user); + *up_cont = MACH_PORT_NULL; - if (which_user == 0) { - ensure_root_bkgd_setup(); - - *up_cont = background_jobmgr->jm_port; - - return 0; - } - LIST_FOREACH(ji, &root_jobmgr->jobs, sle) { if (!ji->per_user) { continue; @@ -6366,6 +6384,7 @@ } if (job_assumes(j, ji != NULL)) { + launchd_mport_copy_send(machservice_port(SLIST_FIRST(&ji->machservices))); *up_cont = machservice_port(SLIST_FIRST(&ji->machservices)); } @@ -6384,12 +6403,15 @@ return BOOTSTRAP_NO_MEMORY; } + job_log(j, LOG_NOTICE, "%s(): Checking in service \"%s\"%s.", __func__, servicename, per_pid_service ? " as a per-PID service" : ""); ms = jobmgr_lookup_service(j->mgr, servicename, false, per_pid_service ? ldc->pid : 0); if (ms == NULL) { + job_log(j, LOG_NOTICE, "%s(): Service \"%s\" not found.", __func__, servicename); *serviceportp = MACH_PORT_NULL; if (unlikely((ms = machservice_new(j, servicename, serviceportp, per_pid_service)) == NULL)) { + job_log(j, LOG_NOTICE, "%s(): Creating service \"%s\" failed.", __func__, servicename); return BOOTSTRAP_NO_MEMORY; } @@ -6438,7 +6460,7 @@ 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); + job_log(j, LOG_NOTICE, "%sMach service registration attempt: %s", flags & BOOTSTRAP_PER_PID_SERVICE ? "Per PID " : "", servicename); /* 5641783 for the embedded hack */ #if !TARGET_OS_EMBEDDED @@ -6583,54 +6605,52 @@ } kern_return_t -job_mig_info(job_t j, name_array_t *servicenamesp, unsigned int *servicenames_cnt, - bootstrap_status_array_t *serviceactivesp, unsigned int *serviceactives_cnt) +job_mig_info(job_t j, name_array_t *servicenamesp, unsigned int *servicenames_cnt, bootstrap_status_array_t *serviceactivesp, unsigned int *serviceactives_cnt) { - name_array_t service_names = NULL; - bootstrap_status_array_t service_actives = NULL; - unsigned int cnt = 0, cnt2 = 0; - struct machservice *ms; - jobmgr_t jm; - job_t ji; - - if (!launchd_assumes(j != NULL)) { + if( !launchd_assumes(j != NULL) ) { return BOOTSTRAP_NO_MEMORY; } - jm = j->mgr; - - LIST_FOREACH(ji, &jm->jobs, sle) { - SLIST_FOREACH(ms, &ji->machservices, sle) { - if (!ms->per_pid) { + jobmgr_t jm = j->mgr; + struct machservice *msi = NULL; + unsigned int cnt = 0; + + unsigned int i = 0; + for( i = 0; i < MACHSERVICE_HASH_SIZE; i++ ) { + LIST_FOREACH( msi, &jm->ms_hash[i], name_hash_sle ) { + if( !msi->per_pid ) { cnt++; } } } - if (cnt == 0) { + if( cnt == 0 ) { goto out; } + name_array_t service_names = NULL; mig_allocate((vm_address_t *)&service_names, cnt * sizeof(service_names[0])); - if (!job_assumes(j, service_names != NULL)) { + if( !job_assumes(j, service_names != NULL) ) { goto out_bad; } + bootstrap_status_array_t service_actives = NULL; mig_allocate((vm_address_t *)&service_actives, cnt * sizeof(service_actives[0])); - if (!job_assumes(j, service_actives != NULL)) { + if( !job_assumes(j, service_actives != NULL) ) { goto out_bad; } - LIST_FOREACH(ji, &jm->jobs, sle) { - SLIST_FOREACH(ms, &ji->machservices, sle) { - if (!ms->per_pid) { - strlcpy(service_names[cnt2], machservice_name(ms), sizeof(service_names[0])); - service_actives[cnt2] = machservice_status(ms); + unsigned int cnt2 = 0; + for( i = 0; i < MACHSERVICE_HASH_SIZE; i++ ) { + LIST_FOREACH( msi, &jm->ms_hash[i], name_hash_sle ) { + if( !msi->per_pid ) { + strlcpy(service_names[cnt2], machservice_name(msi), sizeof(service_names[0])); + service_actives[cnt2] = machservice_status(msi); cnt2++; } } } - + job_assumes(j, cnt == cnt2); out: @@ -6651,59 +6671,6 @@ return BOOTSTRAP_NO_MEMORY; } -void -job_reparent_hack(job_t j, const char *where) -{ - jobmgr_t jmi, jmi2; - - ensure_root_bkgd_setup(); - - /* NULL is only passed for our custom API for LaunchServices. If that is the case, we do magic. */ - if (where == NULL) { - if (strcasecmp(j->mgr->name, VPROCMGR_SESSION_LOGINWINDOW) == 0) { - where = VPROCMGR_SESSION_LOGINWINDOW; - } else { - where = VPROCMGR_SESSION_AQUA; - } - } - - if (strcasecmp(j->mgr->name, where) == 0) { - return; - } - - SLIST_FOREACH(jmi, &root_jobmgr->submgrs, sle) { - if (unlikely(jmi->shutting_down)) { - continue; - } else if (strcasecmp(jmi->name, where) == 0) { - goto jm_found; - } else if (strcasecmp(jmi->name, VPROCMGR_SESSION_BACKGROUND) == 0 && pid1_magic) { - SLIST_FOREACH(jmi2, &jmi->submgrs, sle) { - if (strcasecmp(jmi2->name, where) == 0) { - jmi = jmi2; - goto jm_found; - } - } - } - } - -jm_found: - if (job_assumes(j, jmi != NULL)) { - struct machservice *msi; - - SLIST_FOREACH(msi, &j->machservices, sle) { - LIST_REMOVE(msi, name_hash_sle); - } - - LIST_REMOVE(j, sle); - LIST_INSERT_HEAD(&jmi->jobs, j, sle); - j->mgr = jmi; - - SLIST_FOREACH(msi, &j->machservices, sle) { - LIST_INSERT_HEAD(&j->mgr->ms_hash[hash_ms(msi->name)], msi, name_hash_sle); - } - } -} - kern_return_t job_mig_move_subset(job_t j, mach_port_t target_subset, name_t session_type) { @@ -6723,50 +6690,9 @@ job_t j2; if (j->mgr->session_initialized) { - if (ldc->uid == 0 && pid1_magic) { - if (strcmp(j->mgr->name, VPROCMGR_SESSION_LOGINWINDOW) == 0) { - job_t ji, jn; - - LIST_FOREACH_SAFE(ji, &j->mgr->jobs, sle, jn) { - if (!ji->anonymous) { - job_remove(ji); - } - } - - ensure_root_bkgd_setup(); - - SLIST_REMOVE(&j->mgr->parentmgr->submgrs, j->mgr, jobmgr_s, sle); - j->mgr->parentmgr = background_jobmgr; - SLIST_INSERT_HEAD(&j->mgr->parentmgr->submgrs, j->mgr, sle); - - /* - * We really should wait for all the jobs to die before proceeding. See 5351245 for more info. - * - * We have hacked around this in job_find() by ignoring jobs that are pending removal. - */ - - } else if (strcmp(j->mgr->name, VPROCMGR_SESSION_AQUA) == 0) { - job_log(j, LOG_DEBUG, "Tried to move the Aqua session."); - return 0; - } else if (strcmp(j->mgr->name, VPROCMGR_SESSION_BACKGROUND) == 0) { - job_log(j, LOG_DEBUG, "Tried to move the background session."); - return 0; - } else { - job_log(j, LOG_ERR, "Tried to initialize an already setup session!"); - kr = BOOTSTRAP_NOT_PRIVILEGED; - goto out; - } - } else { - job_log(j, LOG_ERR, "Tried to initialize an already setup session!"); - kr = BOOTSTRAP_NOT_PRIVILEGED; - goto out; - } - } else if (ldc->uid == 0 && pid1_magic && strcmp(session_type, VPROCMGR_SESSION_STANDARDIO) == 0) { - ensure_root_bkgd_setup(); - - SLIST_REMOVE(&j->mgr->parentmgr->submgrs, j->mgr, jobmgr_s, sle); - j->mgr->parentmgr = background_jobmgr; - SLIST_INSERT_HEAD(&j->mgr->parentmgr->submgrs, j->mgr, sle); + job_log(j, LOG_ERR, "Tried to initialize an already setup session!"); + kr = BOOTSTRAP_NOT_PRIVILEGED; + goto out; } else if (strcmp(session_type, VPROCMGR_SESSION_LOGINWINDOW) == 0) { jobmgr_t jmi; @@ -6794,7 +6720,7 @@ } } - jobmgr_log(j->mgr, LOG_DEBUG, "Renaming to: %s", session_type); + jobmgr_log(j->mgr, LOG_NOTICE, "Renaming to: %s", session_type); strcpy(j->mgr->name_init, session_type); if (job_assumes(j, (j2 = jobmgr_init_session(j->mgr, session_type, false)))) { @@ -6810,7 +6736,7 @@ goto out; } - job_log(j, LOG_DEBUG, "Move subset attempt: 0x%x", target_subset); + job_log(j, LOG_NOTICE, "Move subset attempt: 0x%x", target_subset); kr = _vproc_grab_subset(target_subset, &reqport, &rcvright, &out_obj_array, &l2l_ports, &l2l_port_cnt); @@ -6877,9 +6803,7 @@ } kern_return_t -job_mig_take_subset(job_t j, mach_port_t *reqport, mach_port_t *rcvright, - vm_offset_t *outdata, mach_msg_type_number_t *outdataCnt, - mach_port_array_t *portsp, unsigned int *ports_cnt) +job_mig_take_subset(job_t j, mach_port_t *reqport, mach_port_t *rcvright, vm_offset_t *outdata, mach_msg_type_number_t *outdataCnt, mach_port_array_t *portsp, unsigned int *ports_cnt) { launch_data_t tmp_obj, tmp_dict, outdata_obj_array = NULL; mach_port_array_t ports = NULL; @@ -6889,7 +6813,10 @@ jobmgr_t jm; job_t ji; + jobmgr_log(j->mgr, LOG_NOTICE, "%s(): Called from %s.", __func__, j->label); + if (!launchd_assumes(j != NULL)) { + runtime_syslog(LOG_NOTICE, "%s(): Called with NULL job.", __func__); return BOOTSTRAP_NO_MEMORY; } @@ -6912,7 +6839,7 @@ return BOOTSTRAP_NOT_PRIVILEGED; } - job_log(j, LOG_DEBUG, "Transferring sub-bootstrap to the per session launchd."); + job_log(j, LOG_NOTICE, "Transferring sub-bootstrap to the per session launchd."); outdata_obj_array = launch_data_alloc(LAUNCH_DATA_ARRAY); if (!job_assumes(j, outdata_obj_array)) { @@ -6944,6 +6871,8 @@ continue; } + jobmgr_log(j->mgr, LOG_NOTICE, "%s(%s, ...): Packing up %s for transfer...", __func__, j->label, ji->label); + SLIST_FOREACH(ms, &ji->machservices, sle) { if (job_assumes(j, (tmp_dict = launch_data_alloc(LAUNCH_DATA_DICTIONARY)))) { job_assumes(j, launch_data_array_set_index(outdata_obj_array, tmp_dict, cnt2)); @@ -7013,6 +6942,7 @@ mig_deallocate((vm_address_t)ports, cnt * sizeof(ports[0])); } + return BOOTSTRAP_NO_MEMORY; } @@ -7160,7 +7090,7 @@ uid_t kp_uid = kp.kp_eproc.e_pcred.p_ruid; if( ldc->euid == kp_euid ) { - job_log(j, LOG_WARNING, "Working around rdar://problem/5982485 and allowing job to set policy for PID %u. We should discuss having %s run under a per-user launchd.", target_pid, target_j->label); + job_log(j, LOG_DEBUG, "Working around rdar://problem/5982485 and allowing job to set policy for PID %u.", target_pid); } else { job_log(j, LOG_ERR, "Denied Mach service policy update requested by UID/EUID %u/%u against PID %u with UID/EUID %u/%u due to mismatched credentials.", ldc->uid, ldc->euid, target_pid, kp_uid, kp_euid); @@ -7236,8 +7166,6 @@ } } - job_reparent_hack(jr, NULL); - if (pid1_magic) { jr->mach_uid = ldc->uid; } @@ -7352,6 +7280,102 @@ return true; } +kern_return_t +job_mig_lookup_children(job_t j, mach_port_array_t *child_ports, unsigned int *child_ports_cnt, name_array_t *child_names, unsigned int *child_names_cnt) +{ + kern_return_t kr = BOOTSTRAP_NO_MEMORY; + if( !launchd_assumes(j != NULL) ) { + return BOOTSTRAP_NO_MEMORY; + } + + unsigned int cnt = 0; + + jobmgr_t jmr = j->mgr; + jobmgr_t jmi = NULL; + SLIST_FOREACH( jmi, &jmr->submgrs, sle ) { + cnt++; + } + + job_t ji = NULL; + LIST_FOREACH( ji, &jmr->jobs, sle ) { + if( ji->per_user ) { + cnt++; + } + } + + if( cnt == 0 ) { + return BOOTSTRAP_NO_CHILDREN; + } + + mach_port_array_t _child_ports = NULL; + mig_allocate((vm_address_t *)&_child_ports, cnt * sizeof(_child_ports[0])); + if( !job_assumes(j, _child_ports != NULL) ) { + kr = BOOTSTRAP_NO_MEMORY; + goto out_bad; + } + + name_array_t _child_names = NULL; + mig_allocate((vm_address_t *)&_child_names, cnt * sizeof(_child_names[0])); + if( !job_assumes(j, _child_ports != NULL) ) { + kr = BOOTSTRAP_NO_MEMORY; + goto out_bad; + } + + unsigned int cnt2 = 0; + SLIST_FOREACH( jmi, &jmr->submgrs, sle ) { + if( jobmgr_assumes(jmi, launchd_mport_make_send(jmi->jm_port)) == KERN_SUCCESS ) { + _child_ports[cnt2] = jmi->jm_port; + } else { + _child_ports[cnt2] = MACH_PORT_NULL; + } + + strlcpy(_child_names[cnt2], jmi->name, sizeof(_child_names[0])); + cnt2++; + } + + LIST_FOREACH( ji, &jmr->jobs, sle ) { + if( ji->per_user ) { + if( job_assumes(ji, SLIST_FIRST(&ji->machservices)->per_user_hack == true) ) { + mach_port_t port = machservice_port(SLIST_FIRST(&ji->machservices)); + + if( job_assumes(ji, launchd_mport_copy_send(port)) == KERN_SUCCESS ) { + _child_ports[cnt2] = port; + } else { + _child_ports[cnt2] = MACH_PORT_NULL; + } + } else { + _child_ports[cnt2] = MACH_PORT_NULL; + } + + strlcpy(_child_names[cnt2], ji->label, sizeof(_child_names[0])); + cnt2++; + } + } + + *child_names_cnt = cnt; + *child_ports_cnt = cnt; + + *child_names = _child_names; + *child_ports = _child_ports; + + unsigned int i = 0; + for( i = 0; i < cnt; i++ ) { + job_log(j, LOG_DEBUG, "child_names[%u] = %s", i, (char *)_child_names[i]); + } + + return BOOTSTRAP_SUCCESS; +out_bad: + if( _child_ports ) { + mig_deallocate((vm_address_t)_child_ports, cnt * sizeof(_child_ports[0])); + } + + if( _child_names ) { + mig_deallocate((vm_address_t)_child_names, cnt * sizeof(_child_ports[0])); + } + + return kr; +} + void mspolicy_setup(launch_data_t obj, const char *key, void *context) { Modified: branches/PR-6046664/launchd/src/launchd_runtime.c =================================================================== --- branches/PR-6046664/launchd/src/launchd_runtime.c 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/launchd_runtime.c 2008-09-30 22:33:12 UTC (rev 23717) @@ -816,6 +816,12 @@ } INTERNAL_ABI kern_return_t +launchd_mport_copy_send(mach_port_t name) +{ + return errno = mach_port_insert_right(mach_task_self(), name, name, MACH_MSG_TYPE_COPY_SEND); +} + +INTERNAL_ABI kern_return_t launchd_mport_close_recv(mach_port_t name) { return errno = mach_port_mod_refs(mach_task_self(), name, MACH_PORT_RIGHT_RECEIVE, -1); Modified: branches/PR-6046664/launchd/src/launchd_runtime.h =================================================================== --- branches/PR-6046664/launchd/src/launchd_runtime.h 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/launchd_runtime.h 2008-09-30 22:33:12 UTC (rev 23717) @@ -106,7 +106,7 @@ extern bool pid1_magic; extern bool low_level_debug; -extern char g_username[128]; +extern char *g_username; INTERNAL_ABI mach_port_t runtime_get_kernel_port(void); @@ -174,6 +174,7 @@ INTERNAL_ABI kern_return_t launchd_mport_create_recv(mach_port_t *name); INTERNAL_ABI kern_return_t launchd_mport_deallocate(mach_port_t name); INTERNAL_ABI kern_return_t launchd_mport_make_send(mach_port_t name); +INTERNAL_ABI kern_return_t launchd_mport_copy_send(mach_port_t name); INTERNAL_ABI kern_return_t launchd_mport_close_recv(mach_port_t name); #endif Modified: branches/PR-6046664/launchd/src/launchproxy.c =================================================================== --- branches/PR-6046664/launchd/src/launchproxy.c 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/launchproxy.c 2008-09-30 22:33:12 UTC (rev 23717) @@ -191,7 +191,7 @@ setpgid(0, 0); -#if HAVE_SECURITY +#if 0 if ((tmp = launch_data_dict_lookup(resp, LAUNCH_JOBKEY_SESSIONCREATE)) && launch_data_get_bool(tmp)) { if (SessionCreate) { OSStatus scr = SessionCreate(0, 0); Modified: branches/PR-6046664/launchd/src/libbootstrap.c =================================================================== --- branches/PR-6046664/launchd/src/libbootstrap.c 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/libbootstrap.c 2008-09-30 22:33:12 UTC (rev 23717) @@ -18,6 +18,7 @@ * @APPLE_APACHE_LICENSE_HEADER_END@ */ +#include #include "config.h" #include "libbootstrap_public.h" #include "libbootstrap_private.h" @@ -56,6 +57,7 @@ kern_return_t bootstrap_subset(mach_port_t bp, mach_port_t requestor_port, mach_port_t *subset_port) { + _vproc_log(LOG_NOTICE, "%s(): Called by %s.", __func__, getprogname()); return vproc_mig_subset(bp, requestor_port, subset_port); } @@ -88,6 +90,56 @@ } kern_return_t +bootstrap_lookup_children(mach_port_t bp, mach_port_array_t *children, name_array_t *names, mach_msg_type_number_t *n_children) +{ + mach_msg_type_number_t junk = 0; + return vproc_mig_lookup_children(bp, children, &junk, names, n_children); +} + +kern_return_t +bootstrap_lookup_per_user_context(mach_port_t bp, uid_t uid, char *session_type __attribute__((unused)), mach_port_t *puc) +{ + return vproc_mig_lookup_per_user_context(bp, uid, puc); +} + +kern_return_t bootstrap_lookup_local_per_user_context(mach_port_t bp, mach_port_t *puc) +{ + return vproc_mig_lookup_local_per_user_context(bp, puc); +} + +kern_return_t +bootstrap_root(mach_port_t *rbsp) +{ + mach_port_t last_bsport = MACH_PORT_NULL; + mach_port_t _rbsp = bootstrap_port; + kern_return_t result = KERN_FAILURE; + + do { + last_bsport = _rbsp; + result = bootstrap_parent(last_bsport, &_rbsp); + + if( result == BOOTSTRAP_NOT_PRIVILEGED ) { + syslog(LOG_ERR, "bootstrap_parent(): Permission denied.\n"); + _rbsp = MACH_PORT_NULL; + } else if( result != BOOTSTRAP_SUCCESS ) { + syslog(LOG_ERR, "bootstrap_parent() %d\n", result); + _rbsp = MACH_PORT_NULL; + } + + /* Even though last_bport being equal to _rbsp is the stopping point, we'll + * still get back another send right, and thus our reference count will be + * incremented by one, and we'll be responsible for releasing the additional + * reference. + */ + mach_port_mod_refs(mach_task_self(), last_bsport, MACH_PORT_RIGHT_SEND, -1); + } while( _rbsp != MACH_PORT_NULL && last_bsport != _rbsp ); + + *rbsp = _rbsp; + + return result; +} + +kern_return_t bootstrap_register(mach_port_t bp, name_t service_name, mach_port_t sp) { return bootstrap_register2(bp, service_name, sp, 0); @@ -237,7 +289,6 @@ mach_port_deallocate(mach_task_self(), *sp); kr = BOOTSTRAP_NOT_PRIVILEGED; } - } return kr; @@ -265,12 +316,9 @@ } kern_return_t -bootstrap_info(mach_port_t bp, - name_array_t *service_names, mach_msg_type_number_t *service_namesCnt, - bootstrap_status_array_t *service_active, mach_msg_type_number_t *service_activeCnt) +bootstrap_info(mach_port_t bp, name_array_t *service_names, mach_msg_type_number_t *service_namesCnt, bootstrap_status_array_t *service_active, mach_msg_type_number_t *service_activeCnt) { - return vproc_mig_info(bp, service_names, service_namesCnt, - service_active, service_activeCnt); + return vproc_mig_info(bp, service_names, service_namesCnt, service_active, service_activeCnt); } const char * Modified: branches/PR-6046664/launchd/src/libbootstrap_private.h =================================================================== --- branches/PR-6046664/launchd/src/libbootstrap_private.h 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/libbootstrap_private.h 2008-09-30 22:33:12 UTC (rev 23717) @@ -42,6 +42,14 @@ kern_return_t bootstrap_set_policy(mach_port_t bp, pid_t target_pid, uint64_t flags, const char *target_service); +kern_return_t bootstrap_lookup_children(mach_port_t bp, mach_port_array_t *children, name_array_t *names, mach_msg_type_number_t *n_children); + +kern_return_t bootstrap_lookup_per_user_context(mach_port_t bp, uid_t uid, char *session_type __attribute__((unused)), mach_port_t *puc); + +kern_return_t bootstrap_lookup_local_per_user_context(mach_port_t bp, mach_port_t *puc); + +kern_return_t bootstrap_root(mach_port_t *rbsp); + #pragma GCC visibility pop __END_DECLS Modified: branches/PR-6046664/launchd/src/libbootstrap_public.h =================================================================== --- branches/PR-6046664/launchd/src/libbootstrap_public.h 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/libbootstrap_public.h 2008-09-30 22:33:12 UTC (rev 23717) @@ -102,12 +102,13 @@ #define BOOTSTRAP_MAX_LOOKUP_COUNT 20 #define BOOTSTRAP_SUCCESS 0 -#define BOOTSTRAP_NOT_PRIVILEGED 1100 -#define BOOTSTRAP_NAME_IN_USE 1101 -#define BOOTSTRAP_UNKNOWN_SERVICE 1102 -#define BOOTSTRAP_SERVICE_ACTIVE 1103 +#define BOOTSTRAP_NOT_PRIVILEGED 1100 +#define BOOTSTRAP_NAME_IN_USE 1101 +#define BOOTSTRAP_UNKNOWN_SERVICE 1102 +#define BOOTSTRAP_SERVICE_ACTIVE 1103 #define BOOTSTRAP_BAD_COUNT 1104 #define BOOTSTRAP_NO_MEMORY 1105 +#define BOOTSTRAP_NO_CHILDREN 1106 #define BOOTSTRAP_STATUS_INACTIVE 0 #define BOOTSTRAP_STATUS_ACTIVE 1 Modified: branches/PR-6046664/launchd/src/libvproc.c =================================================================== --- branches/PR-6046664/launchd/src/libvproc.c 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/libvproc.c 2008-09-30 22:33:12 UTC (rev 23717) @@ -260,8 +260,7 @@ } kern_return_t -_vproc_grab_subset(mach_port_t bp, mach_port_t *reqport, mach_port_t *rcvright, launch_data_t *outval, - mach_port_array_t *ports, mach_msg_type_number_t *portCnt) +_vproc_grab_subset(mach_port_t bp, mach_port_t *reqport, mach_port_t *rcvright, launch_data_t *outval, mach_port_array_t *ports, mach_msg_type_number_t *portCnt) { mach_msg_type_number_t outdata_cnt; vm_offset_t outdata = 0; @@ -325,6 +324,10 @@ return (vproc_err_t)_vprocmgr_move_subset_to_user; } + _vproc_log(LOG_NOTICE, "%s(%u, %s): %s, uid = %u", __func__, target_user, session_type, getprogname(), getuid()); + + _vproc_log(LOG_NOTICE, "%s(%u, %s): %s", __func__, target_user, session_type, getprogname()); + if (!is_bkgd && ldpid != 1) { if (lduid == getuid()) { return NULL; @@ -336,25 +339,42 @@ return (vproc_err_t)_vprocmgr_move_subset_to_user; } - if (is_bkgd || target_user) { - mach_port_t puc = 0, rootbs = get_root_bootstrap_port(); +#if 0 + mach_port_t puc = 0, rootbs = get_root_bootstrap_port(); - if (vproc_mig_lookup_per_user_context(rootbs, target_user, &puc) != 0) { - return (vproc_err_t)_vprocmgr_move_subset_to_user; - } + if (vproc_mig_lookup_per_user_context(rootbs, target_user, &puc) != 0) { + return (vproc_err_t)_vprocmgr_move_subset_to_user; + } - if (is_bkgd) { - task_set_bootstrap_port(mach_task_self(), puc); - mach_port_deallocate(mach_task_self(), bootstrap_port); - bootstrap_port = puc; - } else { - kr = vproc_mig_move_subset(puc, bootstrap_port, (char *)session_type); - mach_port_deallocate(mach_task_self(), puc); - } + if( ldpid == 1 ) { + _vproc_log(LOG_NOTICE, "%s(): %s: ldpid = %llu, lduid = %llu, moving subset to per-user bootstrap.", __func__, getprogname(), ldpid, lduid); + kr = vproc_mig_move_subset(puc, bootstrap_port, VPROCMGR_SESSION_BACKGROUND); + mach_port_deallocate(mach_task_self(), puc); } else { - kr = _vprocmgr_init(session_type) ? 1 : 0; + _vproc_log(LOG_NOTICE, "%s(): %s: ldpid = %llu, lduid = %llu, swapping bootstrap_port and puc.", __func__, getprogname(), ldpid, lduid); + task_set_bootstrap_port(mach_task_self(), puc); + mach_port_deallocate(mach_task_self(), bootstrap_port); + bootstrap_port = puc; } +#else + mach_port_t puc = 0, rootbs = get_root_bootstrap_port(); + _vproc_log(LOG_NOTICE, "%s(%u, %s): Looking up per-user context...", __func__, target_user, session_type); + if (vproc_mig_lookup_per_user_context(rootbs, target_user, &puc) != 0) { + return (vproc_err_t)_vprocmgr_move_subset_to_user; + } + + if (is_bkgd) { + _vproc_log(LOG_NOTICE, "%s(%u, %s): Background session, swapping bootstrap_port with puc.", __func__, target_user, session_type); + task_set_bootstrap_port(mach_task_self(), puc); + mach_port_deallocate(mach_task_self(), bootstrap_port); + bootstrap_port = puc; + } else { + _vproc_log(LOG_NOTICE, "%s(%u, %s): Moving subset...", __func__, target_user, session_type); + kr = vproc_mig_move_subset(puc, bootstrap_port, (char *)session_type); + mach_port_deallocate(mach_task_self(), puc); + } +#endif cached_pid = -1; if (kr) { Modified: branches/PR-6046664/launchd/src/protocol_job.defs =================================================================== --- branches/PR-6046664/launchd/src/protocol_job.defs 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/protocol_job.defs 2008-09-30 22:33:12 UTC (rev 23717) @@ -35,148 +35,157 @@ type mach_port_move_send_array_t = array[] of mach_port_move_send_t ctype: mach_port_array_t; +type mach_port_make_send_array_t = array[] of mach_port_make_send_t + ctype: mach_port_array_t; userprefix vproc_mig_; serverprefix job_mig_; routine create_server( - __bs_port : job_t; - __server_cmd : cmd_t; - __server_uid : uid_t; - __on_demand : boolean_t; - out __server_port : mach_port_make_send_t); + __bs_port : job_t; + __server_cmd : cmd_t; + __server_uid : uid_t; + __on_demand : boolean_t; +out __server_port : mach_port_make_send_t); routine reboot2( - __bs_port : job_t; - __flags : uint64_t); + __bs_port : job_t; + __flags : uint64_t); routine check_in2( - __bs_port : job_t; - __service_name : name_t; - out __service_port : mach_port_move_receive_t; - __flags : uint64_t); + __bs_port : job_t; + __service_name : name_t; +out __service_port : mach_port_move_receive_t; + __flags : uint64_t); routine register2( - __bs_port : job_t; - __service_name : name_t; - __service_port : mach_port_t; - __flags : uint64_t); + __bs_port : job_t; + __service_name : name_t; + __service_port : mach_port_t; + __flags : uint64_t); routine look_up2( - __bs_port : job_t; - sreplyport __rport : mach_port_make_send_once_t; - __service_name : name_t; - out __service_port : mach_port_t; - UserAuditToken __server_cred: audit_token_t; - __target_pid : pid_t; - __flags : uint64_t); + __bs_port : job_t; +sreplyport __rport : mach_port_make_send_once_t; + __service_name : name_t; +out __service_port : mach_port_t; +UserAuditToken __server_cred : audit_token_t; + __target_pid : pid_t; + __flags : uint64_t); routine send_signal( - __bs_port : job_t; - sreplyport __rport : mach_port_make_send_once_t; - __label : name_t; - __signal : integer_t); + __bs_port : job_t; +sreplyport __rport : mach_port_make_send_once_t; + __label : name_t; + __signal : integer_t); routine parent( - __bs_port : job_t; - sreplyport __rport : mach_port_make_send_once_t; - out __parent_port : mach_port_make_send_t); + __bs_port : job_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; - __task_port : task_t); + __bs_port : job_t; + __task_port : task_t); routine info( - __bs_port : job_t; - out __service_names : name_array_t, dealloc; - out __service_active : bootstrap_status_array_t, dealloc); + __bs_port : job_t; +out __service_names : name_array_t, dealloc; +out __service_active : bootstrap_status_array_t, dealloc); routine subset( - __bs_port : job_t; - __requestor_port: mach_port_t; - out __subset_port : mach_port_make_send_t); + __bs_port : job_t; + __requestor_port : mach_port_t; +out __subset_port : mach_port_make_send_t); routine setup_shmem( - __bs_port : job_t; - out __shmem_port : mach_port_move_send_t); + __bs_port : job_t; +out __shmem_port : mach_port_move_send_t); routine take_subset( - __bs_port : job_t; - out __bs_reqport : mach_port_move_send_t; - out __bs_rcvright : mach_port_move_receive_t; - out __outdata : pointer_t, dealloc; - out __service_ports : mach_port_move_send_array_t, dealloc); + __bs_port : job_t; +out __bs_reqport : mach_port_move_send_t; +out __bs_rcvright : mach_port_move_receive_t; +out __outdata : pointer_t, dealloc; +out __service_ports : mach_port_move_send_array_t, dealloc); routine getsocket( - __bs_port : job_t; - out __sockpath : name_t); + __bs_port : job_t; +out __sockpath : name_t); routine spawn( - __bs_port : job_t; - __indata : pointer_t; - out __pid : pid_t; - out __obsvr_port : mach_port_make_send_t); + __bs_port : job_t; + __indata : pointer_t; +out __pid : pid_t; +out __obsvr_port : mach_port_make_send_t); routine wait( - __bs_port : job_t; - sreplyport __rport : mach_port_make_send_once_t; - out __waitval : integer_t); + __bs_port : job_t; +sreplyport __rport : mach_port_make_send_once_t; +out __waitval : integer_t); routine uncork_fork( - __bs_port : job_t); + __bs_port : job_t); routine swap_integer( - __bs_port : job_t; - __inkey : vproc_gsk_t; - __outkey : vproc_gsk_t; - __inval : int64_t; - out __outval : int64_t); + __bs_port : job_t; + __inkey : vproc_gsk_t; + __outkey : vproc_gsk_t; + __inval : int64_t; +out __outval : int64_t); routine set_service_policy( - __bs_port : job_t; - __target_pid : pid_t; - __flags : uint64_t; - __service : name_t); + __bs_port : job_t; + __target_pid : pid_t; + __flags : uint64_t; + __service : name_t); routine log( - __bs_port : job_t; - __pri : integer_t; - __err : integer_t; - __msg : logmsg_t); + __bs_port : job_t; + __pri : integer_t; + __err : integer_t; + __msg : logmsg_t); routine lookup_per_user_context( - __bs_port : job_t; - __wu : uid_t; - out __u_cont : mach_port_t); + __bs_port : job_t; +sreplyport __rport : mach_port_make_send_once_t; + __wu : uid_t; +out __u_cont : mach_port_move_send_t); routine move_subset( - __bs_port : job_t; - __target_port : mach_port_t; - __sessiontype : name_t); + __bs_port : job_t; + __target_port : mach_port_t; + __sessiontype : name_t); routine swap_complex( - __bs_port : job_t; - __inkey : vproc_gsk_t; - __outkey : vproc_gsk_t; - __inval : pointer_t; - out __outval : pointer_t, dealloc); + __bs_port : job_t; + __inkey : vproc_gsk_t; + __outkey : vproc_gsk_t; + __inval : pointer_t; +out __outval : pointer_t, dealloc); routine log_drain( - __bs_port : job_t; - sreplyport __rport : mach_port_make_send_once_t; - out __outval : pointer_t, dealloc); + __bs_port : job_t; +sreplyport __rport : mach_port_make_send_once_t; +out __outval : pointer_t, dealloc); routine log_forward( - __bs_port : job_t; - __inval : pointer_t); + __bs_port : job_t; + __inval : pointer_t); routine embedded_kickstart( - __bs_port : job_t; - __label : name_t; - out __pid : pid_t; - out __name_port : mach_port_t); + __bs_port : job_t; + __label : name_t; +out __pid : pid_t; +out __name_port : mach_port_t); routine embedded_wait( - __bs_port : job_t; - __label : name_t; - out __waitval : integer_t); + __bs_port : job_t; + __label : name_t; +out __waitval : integer_t); + +routine lookup_children( + __bs_port : job_t; +out __child_ports : mach_port_move_send_array_t, dealloc; +out __child_names : name_array_t, dealloc); + Modified: branches/PR-6046664/launchd/src/protocol_job_forward.defs =================================================================== --- branches/PR-6046664/launchd/src/protocol_job_forward.defs 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/protocol_job_forward.defs 2008-09-30 22:33:12 UTC (rev 23717) @@ -39,15 +39,43 @@ 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); + __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); + __bs_port : job_t; +replyport __rport : mach_port_move_send_once_t); +skip; /* post_fork_ping */ + +skip; /* info */ + +skip; /* subset */ + +skip; /* setup_shmem */ + +skip; /* take_subset */ + +skip; /* getsocket */ + +skip; /* spawn */ + +skip; /* wait */ + +skip; /* uncork_fork */ + +skip; /* swap_integer */ + +skip; /* set_service_policy */ + +skip; /* log */ + +simpleroutine lookup_per_user_context_forward( + __bs_port : job_t; +replyport __rport : mach_port_move_send_once_t; + __wu : uid_t); Modified: branches/PR-6046664/launchd/src/protocol_job_reply.defs =================================================================== --- branches/PR-6046664/launchd/src/protocol_job_reply.defs 2008-09-30 22:09:48 UTC (rev 23716) +++ branches/PR-6046664/launchd/src/protocol_job_reply.defs 2008-09-30 22:33:12 UTC (rev 23717) @@ -70,7 +70,7 @@ skip; /* log */ -skip; /* lookup_per_user_context */ +skip; /* lookup_per_user_context_reply */ skip; /* move_subset */ @@ -79,4 +79,4 @@ simpleroutine job_mig_log_drain_reply( __r_port : mach_port_move_send_once_t; __result : kern_return_t, RetCode; - __outval : pointer_t); + __outval : pointer_t); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20080930/b74c0145/attachment-0001.html From source_changes at macosforge.org Tue Sep 30 16:13:37 2008 From: source_changes at macosforge.org (source_changes at macosforge.org) Date: Tue, 30 Sep 2008 16:13:37 -0700 (PDT) Subject: [launchd-changes] [23718] branches/PR-6046664/launchd/src/libbootstrap.c Message-ID: <20080930231337.CFF4A4497FC@beta.macosforge.org> Revision: 23718 http://trac.macosforge.org/projects/launchd/changeset/23718 Author: dsorresso at apple.com Date: 2008-09-30 16:13:37 -0700 (Tue, 30 Sep 2008) Log Message: ----------- Removed a dangling function in libbootstrap. Modified Paths: -------------- branches/PR-6046664/launchd/src/libbootstrap.c Modified: branches/PR-6046664/launchd/src/libbootstrap.c =================================================================== --- branches/PR-6046664/launchd/src/libbootstrap.c 2008-09-30 22:33:12 UTC (rev 23717) +++ branches/PR-6046664/launchd/src/libbootstrap.c 2008-09-30 23:13:37 UTC (rev 23718) @@ -102,11 +102,6 @@ return vproc_mig_lookup_per_user_context(bp, uid, puc); } -kern_return_t bootstrap_lookup_local_per_user_context(mach_port_t bp, mach_port_t *puc) -{ - return vproc_mig_lookup_local_per_user_context(bp, puc); -} - kern_return_t bootstrap_root(mach_port_t *rbsp) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20080930/039a1a8f/attachment.html