From source_changes at macosforge.org Thu Dec 6 13:11:04 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Thu Dec 6 13:12:43 2007 Subject: [launchd-changes] [23454] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071206211104.B1E072B5EA7@beta.macosforge.org> Revision: 23454 http://trac.macosforge.org/projects/launchd/changeset/23454 Author: zarzycki@apple.com Date: 2007-12-06 13:10:26 -0800 (Thu, 06 Dec 2007) Log Message: ----------- Better logging. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-04 21:58:16 UTC (rev 23453) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-06 21:10:26 UTC (rev 23454) @@ -5759,8 +5759,7 @@ } if (machservice_job(ms) != j) { if (last_warned_pid != ldc.pid) { - job_log(j, LOG_NOTICE, "Check-in of Mach service failed. PID %d is not privileged: %s", - ldc.pid, servicename); + job_log(j, LOG_NOTICE, "Check-in of Mach service failed. The service \"%s\" is owned by: %s", servicename, j->label); last_warned_pid = ldc.pid; } return BOOTSTRAP_NOT_PRIVILEGED; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071206/19f91944/attachment.html From source_changes at macosforge.org Fri Dec 7 12:58:10 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Fri Dec 7 12:59:43 2007 Subject: [launchd-changes] [23455] branches/SULeopard/launchd/src/launchproxy.c Message-ID: <20071207205810.619742CDF1C@beta.macosforge.org> Revision: 23455 http://trac.macosforge.org/projects/launchd/changeset/23455 Author: zarzycki@apple.com Date: 2007-12-07 12:58:01 -0800 (Fri, 07 Dec 2007) Log Message: ----------- SULeoCeto: rsh jobs wait for backgrounded processes Modified Paths: -------------- branches/SULeopard/launchd/src/launchproxy.c Modified: branches/SULeopard/launchd/src/launchproxy.c =================================================================== --- branches/SULeopard/launchd/src/launchproxy.c 2007-12-06 21:10:26 UTC (rev 23454) +++ branches/SULeopard/launchd/src/launchproxy.c 2007-12-07 20:58:01 UTC (rev 23455) @@ -194,6 +194,7 @@ } } fcntl(r, F_SETFL, 0); + fcntl(r, F_SETFD, 1); dup2(r, STDIN_FILENO); if (dupstdout) dup2(r, STDOUT_FILENO); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071207/db6c9814/attachment-0001.html From source_changes at macosforge.org Fri Dec 7 12:59:15 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Fri Dec 7 13:00:46 2007 Subject: [launchd-changes] [23456] branches/SULeopard/launchd/src/launchd_runtime.c Message-ID: <20071207205915.6C21E2CDFAD@beta.macosforge.org> Revision: 23456 http://trac.macosforge.org/projects/launchd/changeset/23456 Author: zarzycki@apple.com Date: 2007-12-07 12:59:06 -0800 (Fri, 07 Dec 2007) Log Message: ----------- SWB: launchd needs changes to build using gcc 4.2 with -Werror Modified Paths: -------------- branches/SULeopard/launchd/src/launchd_runtime.c Modified: branches/SULeopard/launchd/src/launchd_runtime.c =================================================================== --- branches/SULeopard/launchd/src/launchd_runtime.c 2007-12-07 20:58:01 UTC (rev 23455) +++ branches/SULeopard/launchd/src/launchd_runtime.c 2007-12-07 20:59:06 UTC (rev 23456) @@ -251,7 +251,11 @@ static char flags_buf[sizeof(MAX_RB_STR)]; char *flags_off = NULL; - if (flags) while (flags) { + if (flags == 0) { + return "RB_AUTOBOOT"; + } + + while (flags) { if (flags_off) { *flags_off = '|'; flags_off++; @@ -275,10 +279,9 @@ flags_off += sprintf(flags_off, "0x%x", flags); flags = 0; } - return flags_buf; - } else { - return "RB_AUTOBOOT"; } + + return flags_buf; } const char * -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071207/f56f10c3/attachment.html From source_changes at macosforge.org Fri Dec 7 13:00:10 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Fri Dec 7 13:01:13 2007 Subject: [launchd-changes] [23457] branches/SULeopard/launchd/src/launchctl.c Message-ID: <20071207210010.39A2E2CDFFE@beta.macosforge.org> Revision: 23457 http://trac.macosforge.org/projects/launchd/changeset/23457 Author: zarzycki@apple.com Date: 2007-12-07 12:59:53 -0800 (Fri, 07 Dec 2007) Log Message: ----------- SULeoCeto: Detect and fix bogus permissions on /sbin/launchd Modified Paths: -------------- branches/SULeopard/launchd/src/launchctl.c Modified: branches/SULeopard/launchd/src/launchctl.c =================================================================== --- branches/SULeopard/launchd/src/launchctl.c 2007-12-07 20:59:06 UTC (rev 23456) +++ branches/SULeopard/launchd/src/launchctl.c 2007-12-07 20:59:53 UTC (rev 23457) @@ -148,6 +148,7 @@ static bool do_single_user_mode2(void); static void read_launchd_conf(void); static bool job_disabled_logic(launch_data_t obj); +static void fix_bogus_file_metadata(void); typedef enum { BOOTCACHE_START = 1, @@ -2782,8 +2783,66 @@ */ assumes(fwexec(remount_tool, true) != -1); + + fix_bogus_file_metadata(); } +void +fix_bogus_file_metadata(void) +{ + static const struct { + const char *path; + const uid_t owner; + const gid_t group; + const mode_t needed_bits; + const mode_t bad_bits; + } f[] = { + { "/sbin/launchd", 0, 0, S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, S_ISUID|S_ISGID|S_ISVTX|S_IWOTH }, + { _PATH_TMP, 0, 0, S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO, S_ISUID|S_ISGID }, + { _PATH_VARTMP, 0, 0, S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO, S_ISUID|S_ISGID }, + }; + struct stat sb; + size_t i; + + for (i = 0; i < (sizeof(f) / sizeof(f[0])); i++) { + mode_t i_needed_bits; + mode_t i_bad_bits; + bool fix_mode = false; + bool fix_id = false; + + if (!assumes(stat(f[i].path, &sb) != -1)) { + continue; + } + + i_needed_bits = ~sb.st_mode & f[i].needed_bits; + i_bad_bits = sb.st_mode & f[i].bad_bits; + + if (i_bad_bits) { + fprintf(stderr, "Crucial filesystem check: Removing bogus mode bits 0%o on path: %s\n", i_bad_bits, f[i].path); + fix_mode = true; + } + if (i_needed_bits) { + fprintf(stderr, "Crucial filesystem check: Adding missing mode bits 0%o on path: %s\n", i_needed_bits, f[i].path); + fix_mode = true; + } + if (sb.st_uid != f[i].owner) { + fprintf(stderr, "Crucial filesystem check: Fixing bogus UID %u on path: %s\n", sb.st_uid, f[i].path); + fix_id = true; + } + if (sb.st_gid != f[i].group) { + fprintf(stderr, "Crucial filesystem check: Fixing bogus GID %u on path: %s\n", sb.st_gid, f[i].path); + fix_id = true; + } + + if (fix_mode) { + assumes(chmod(f[i].path, (sb.st_mode & ~i_bad_bits) | i_needed_bits) != -1); + } + if (fix_id) { + assumes(chown(f[i].path, f[i].owner, f[i].group) != -1); + } + } +} + bool path_check(const char *path) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071207/e3b12cb3/attachment.html From source_changes at macosforge.org Fri Dec 7 13:06:28 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Fri Dec 7 13:08:00 2007 Subject: [launchd-changes] [23458] trunk/launchd/src/launchctl.c Message-ID: <20071207210628.1A26C2CE1AA@beta.macosforge.org> Revision: 23458 http://trac.macosforge.org/projects/launchd/changeset/23458 Author: zarzycki@apple.com Date: 2007-12-07 13:06:19 -0800 (Fri, 07 Dec 2007) Log Message: ----------- SULeoCeto: Detect and fix bogus permissions on /sbin/launchd Modified Paths: -------------- trunk/launchd/src/launchctl.c Modified: trunk/launchd/src/launchctl.c =================================================================== --- trunk/launchd/src/launchctl.c 2007-12-07 20:59:53 UTC (rev 23457) +++ trunk/launchd/src/launchctl.c 2007-12-07 21:06:19 UTC (rev 23458) @@ -151,6 +151,7 @@ static bool do_single_user_mode2(void); static void read_launchd_conf(void); static bool job_disabled_logic(launch_data_t obj); +static void fix_bogus_file_metadata(void); typedef enum { BOOTCACHE_START = 1, @@ -2781,8 +2782,67 @@ */ assumes(fwexec(remount_tool, NULL) != -1); + + fix_bogus_file_metadata(); } +void +fix_bogus_file_metadata(void) +{ + static const struct { + const char *path; + const uid_t owner; + const gid_t group; + const mode_t needed_bits; + const mode_t bad_bits; + } f[] = { + { "/sbin/launchd", 0, 0, S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, S_ISUID|S_ISGID|S_ISVTX|S_IWOTH }, + { _PATH_TMP, 0, 0, S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO, S_ISUID|S_ISGID }, + { _PATH_VARTMP, 0, 0, S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO, S_ISUID|S_ISGID }, + }; + struct stat sb; + size_t i; + + for (i = 0; i < (sizeof(f) / sizeof(f[0])); i++) { + mode_t i_needed_bits; + mode_t i_bad_bits; + bool fix_mode = false; + bool fix_id = false; + + if (!assumes(stat(f[i].path, &sb) != -1)) { + continue; + } + + i_needed_bits = ~sb.st_mode & f[i].needed_bits; + i_bad_bits = sb.st_mode & f[i].bad_bits; + + if (i_bad_bits) { + fprintf(stderr, "Crucial filesystem check: Removing bogus mode bits 0%o on path: %s\n", i_bad_bits, f[i].path); + fix_mode = true; + } + if (i_needed_bits) { + fprintf(stderr, "Crucial filesystem check: Adding missing mode bits 0%o on path: %s\n", i_needed_bits, f[i].path); + fix_mode = true; + } + if (sb.st_uid != f[i].owner) { + fprintf(stderr, "Crucial filesystem check: Fixing bogus UID %u on path: %s\n", sb.st_uid, f[i].path); + fix_id = true; + } + if (sb.st_gid != f[i].group) { + fprintf(stderr, "Crucial filesystem check: Fixing bogus GID %u on path: %s\n", sb.st_gid, f[i].path); + fix_id = true; + } + + if (fix_mode) { + assumes(chmod(f[i].path, (sb.st_mode & ~i_bad_bits) | i_needed_bits) != -1); + } + if (fix_id) { + assumes(chown(f[i].path, f[i].owner, f[i].group) != -1); + } + } +} + + bool path_check(const char *path) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071207/60550076/attachment-0001.html From source_changes at macosforge.org Fri Dec 7 13:15:45 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Fri Dec 7 13:17:18 2007 Subject: [launchd-changes] [23459] branches/SULeopard/launchd/src Message-ID: <20071207211545.861372CE47E@beta.macosforge.org> Revision: 23459 http://trac.macosforge.org/projects/launchd/changeset/23459 Author: zarzycki@apple.com Date: 2007-12-07 13:15:23 -0800 (Fri, 07 Dec 2007) Log Message: ----------- SULeoCeto: ReportCrash can deadlock against itself if it crashes prior to main() Modified Paths: -------------- branches/SULeopard/launchd/src/Makefile.am branches/SULeopard/launchd/src/Makefile.in branches/SULeopard/launchd/src/launchd_core_logic.c branches/SULeopard/launchd/src/launchd_runtime.c branches/SULeopard/launchd/src/launchd_runtime.h branches/SULeopard/launchd/src/liblaunch_private.h Modified: branches/SULeopard/launchd/src/Makefile.am =================================================================== --- branches/SULeopard/launchd/src/Makefile.am 2007-12-07 21:06:19 UTC (rev 23458) +++ branches/SULeopard/launchd/src/Makefile.am 2007-12-07 21:15:23 UTC (rev 23459) @@ -2,7 +2,7 @@ CLEANFILES = protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h \ launchd_internal.h launchd_internalServer.h launchd_internalServer.c launchd_internalUser.c \ - notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c + notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c mach_excServer.c mach_excServer.h protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h: $(srcdir)/protocol_job.defs mig $(MIGFLAGS) -sheader protocol_vprocServer.h $(srcdir)/protocol_job.defs @@ -48,9 +48,9 @@ launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -Wno-unused-parameter launchd_LDFLAGS = -lbsm -launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.c +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 mach_excServer.c -launchd_runtime.c:: notifyServer.h launchd_internal.h +launchd_runtime.c:: notifyServer.h launchd_internal.h mach_excServer.h launchd_core_logic.c:: protocol_vproc.h job_reply.h protocol_vprocServer.h launchproxy_LDFLAGS = -weak_framework Security @@ -58,6 +58,9 @@ notifyServer.c notifyServer.h: /usr/include/mach/notify.defs mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader notifyServer.h /usr/include/mach/notify.defs +mach_excServer.c mach_excServer.h: /usr/include/mach/mach_exc.defs + mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader mach_excServer.h /usr/include/mach/mach_exc.defs + job_replyUser.c job_reply.h: $(srcdir)/protocol_job_reply.defs mig $(MIGFLAGS) -sheader /dev/null -server /dev/null $(srcdir)/protocol_job_reply.defs Modified: branches/SULeopard/launchd/src/Makefile.in =================================================================== --- branches/SULeopard/launchd/src/Makefile.in 2007-12-07 21:06:19 UTC (rev 23458) +++ branches/SULeopard/launchd/src/Makefile.in 2007-12-07 21:15:23 UTC (rev 23459) @@ -96,7 +96,8 @@ am__launchd_SOURCES_DIST = launchd.c launchd_core_logic.c \ launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c \ launchd_internalUser.c launchd_internalServer.c \ - job_replyUser.c launchd_runtime.c launchd_runtime_kill.c + job_replyUser.c launchd_runtime.c launchd_runtime_kill.c \ + mach_excServer.c @LIBS_ONLY_FALSE@am_launchd_OBJECTS = launchd-launchd.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-launchd_core_logic.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-launchd_unix_ipc.$(OBJEXT) \ @@ -106,7 +107,8 @@ @LIBS_ONLY_FALSE@ launchd-launchd_internalServer.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-job_replyUser.$(OBJEXT) \ @LIBS_ONLY_FALSE@ launchd-launchd_runtime.$(OBJEXT) \ -@LIBS_ONLY_FALSE@ launchd-launchd_runtime_kill.$(OBJEXT) +@LIBS_ONLY_FALSE@ launchd-launchd_runtime_kill.$(OBJEXT) \ +@LIBS_ONLY_FALSE@ launchd-mach_excServer.$(OBJEXT) launchd_OBJECTS = $(am_launchd_OBJECTS) launchd_LDADD = $(LDADD) launchd_LINK = $(CCLD) $(launchd_CFLAGS) $(CFLAGS) $(launchd_LDFLAGS) \ @@ -238,7 +240,7 @@ AM_CFLAGS = -no-cpp-precomp -F/System/Library/PrivateFrameworks -Wall -Wextra -Waggregate-return -Wshadow -Wmissing-prototypes -Wmissing-declarations -Werror -D__MigTypeCheck=1 -fvisibility=hidden -Dmig_external=__private_extern__ CLEANFILES = protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h \ launchd_internal.h launchd_internalServer.h launchd_internalServer.c launchd_internalUser.c \ - notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c + notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c mach_excServer.c mach_excServer.h @LIBS_ONLY_TRUE@noinst_LIBRARIES = liblaunch.a liblaunch_profile.a @LIBS_ONLY_TRUE@liblaunch_a_CFLAGS = -D__DARWIN_NON_CANCELABLE=1 $(AM_CFLAGS) @@ -253,7 +255,7 @@ @LIBS_ONLY_FALSE@SystemStarter_SOURCES = StartupItems.c IPC.c SystemStarter.c @LIBS_ONLY_FALSE@launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -Wno-unused-parameter @LIBS_ONLY_FALSE@launchd_LDFLAGS = -lbsm -@LIBS_ONLY_FALSE@launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.c +@LIBS_ONLY_FALSE@launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.c mach_excServer.c @LIBS_ONLY_FALSE@launchproxy_LDFLAGS = -weak_framework Security @LIBS_ONLY_FALSE@man1_MANS = wait4path.1 launchctl.1 @LIBS_ONLY_FALSE@man5_MANS = launchd.plist.5 launchd.conf.5 @@ -423,6 +425,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-launchd_runtime.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-launchd_runtime_kill.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-launchd_unix_ipc.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-mach_excServer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-notifyServer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchd-protocol_vprocServer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/launchproxy.Po@am__quote@ @@ -787,6 +790,20 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='launchd_runtime_kill.c' object='launchd-launchd_runtime_kill.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -c -o launchd-launchd_runtime_kill.obj `if test -f 'launchd_runtime_kill.c'; then $(CYGPATH_W) 'launchd_runtime_kill.c'; else $(CYGPATH_W) '$(srcdir)/launchd_runtime_kill.c'; fi` + +launchd-mach_excServer.o: mach_excServer.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-mach_excServer.o -MD -MP -MF $(DEPDIR)/launchd-mach_excServer.Tpo -c -o launchd-mach_excServer.o `test -f 'mach_excServer.c' || echo '$(srcdir)/'`mach_excServer.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/launchd-mach_excServer.Tpo $(DEPDIR)/launchd-mach_excServer.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='mach_excServer.c' object='launchd-mach_excServer.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -c -o launchd-mach_excServer.o `test -f 'mach_excServer.c' || echo '$(srcdir)/'`mach_excServer.c + +launchd-mach_excServer.obj: mach_excServer.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -MT launchd-mach_excServer.obj -MD -MP -MF $(DEPDIR)/launchd-mach_excServer.Tpo -c -o launchd-mach_excServer.obj `if test -f 'mach_excServer.c'; then $(CYGPATH_W) 'mach_excServer.c'; else $(CYGPATH_W) '$(srcdir)/mach_excServer.c'; fi` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/launchd-mach_excServer.Tpo $(DEPDIR)/launchd-mach_excServer.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='mach_excServer.c' object='launchd-mach_excServer.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(launchd_CFLAGS) $(CFLAGS) -c -o launchd-mach_excServer.obj `if test -f 'mach_excServer.c'; then $(CYGPATH_W) 'mach_excServer.c'; else $(CYGPATH_W) '$(srcdir)/mach_excServer.c'; fi` install-man1: $(man1_MANS) $(man_MANS) @$(NORMAL_INSTALL) test -z "$(man1dir)" || $(MKDIR_P) "$(DESTDIR)$(man1dir)" @@ -1148,12 +1165,15 @@ @LIBS_ONLY_TRUE@ cp liblaunch.a $(DESTDIR)/usr/local/lib/system/liblaunch_debug.a @LIBS_ONLY_TRUE@ cp liblaunch_profile.a $(DESTDIR)/usr/local/lib/system/liblaunch_profile.a -@LIBS_ONLY_FALSE@launchd_runtime.c:: notifyServer.h launchd_internal.h +@LIBS_ONLY_FALSE@launchd_runtime.c:: notifyServer.h launchd_internal.h mach_excServer.h @LIBS_ONLY_FALSE@launchd_core_logic.c:: protocol_vproc.h job_reply.h protocol_vprocServer.h @LIBS_ONLY_FALSE@notifyServer.c notifyServer.h: /usr/include/mach/notify.defs @LIBS_ONLY_FALSE@ mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader notifyServer.h /usr/include/mach/notify.defs +@LIBS_ONLY_FALSE@mach_excServer.c mach_excServer.h: /usr/include/mach/mach_exc.defs +@LIBS_ONLY_FALSE@ mig $(MIGFLAGS) -header /dev/null -user /dev/null -sheader mach_excServer.h /usr/include/mach/mach_exc.defs + @LIBS_ONLY_FALSE@job_replyUser.c job_reply.h: $(srcdir)/protocol_job_reply.defs @LIBS_ONLY_FALSE@ mig $(MIGFLAGS) -sheader /dev/null -server /dev/null $(srcdir)/protocol_job_reply.defs Modified: branches/SULeopard/launchd/src/launchd_core_logic.c =================================================================== --- branches/SULeopard/launchd/src/launchd_core_logic.c 2007-12-07 21:06:19 UTC (rev 23458) +++ branches/SULeopard/launchd/src/launchd_core_logic.c 2007-12-07 21:15:23 UTC (rev 23459) @@ -333,6 +333,7 @@ char *groupname; char *stdoutpath; char *stderrpath; + char *alt_exc_handler; struct machservice *lastlookup; unsigned int lastlookup_gennum; char *seatbelt_profile; @@ -360,7 +361,7 @@ currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1, hopefully_exits_last:1, removal_pending:1, wait4pipe_eof:1, sent_sigkill:1, debug_before_kill:1, weird_bootstrap:1, start_on_mount:1, per_user:1, hopefully_exits_first:1, deny_unknown_mslookups:1, unload_at_mig_return:1, abandon_pg:1, - poll_for_vfs_changes:1; + poll_for_vfs_changes:1, internal_exc_handler:1; const char label[0]; }; @@ -861,6 +862,9 @@ if (j->stderrpath) { free(j->stderrpath); } + if (j->alt_exc_handler) { + free(j->alt_exc_handler); + } if (j->seatbelt_profile) { free(j->seatbelt_profile); } @@ -1323,6 +1327,13 @@ found_key = true; } break; + case 'm': + case 'M': + if (strcasecmp(key, LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER) == 0) { + j->internal_exc_handler = value; + found_key = true; + } + break; case 'i': case 'I': if (strcasecmp(key, LAUNCH_JOBKEY_INITGROUPS) == 0) { @@ -1376,6 +1387,12 @@ char **where2put = NULL; switch (key[0]) { + case 'm': + case 'M': + if (strcasecmp(key, LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER) == 0) { + where2put = &j->alt_exc_handler; + } + break; case 'p': case 'P': if (strcasecmp(key, LAUNCH_JOBKEY_PROGRAM) == 0) { @@ -4002,9 +4019,20 @@ void job_setup_exception_port(job_t j, task_t target_task) { + struct machservice *ms; thread_state_flavor_t f = 0; + mach_port_t exc_port = the_exception_server; - if (!the_exception_server) { + if (j->alt_exc_handler) { + ms = jobmgr_lookup_service(j->mgr, j->alt_exc_handler, true, 0); + if (ms) { + exc_port = machservice_port(ms); + } else { + job_log(j, LOG_WARNING, "Falling back to default Mach exception handler. Could not find: %s", j->alt_exc_handler); + } + } else if (j->internal_exc_handler) { + exc_port = runtime_get_kernel_port(); + } else if (!exc_port) { return; } @@ -4015,9 +4043,9 @@ #endif if (target_task) { - job_assumes(j, task_set_exception_ports(target_task, EXC_MASK_CRASH, the_exception_server, + job_assumes(j, task_set_exception_ports(target_task, EXC_MASK_CRASH, exc_port, EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); - } else if (getpid() == 1) { + } else if (getpid() == 1 && the_exception_server) { mach_port_t mhp = mach_host_self(); job_assumes(j, host_set_exception_ports(mhp, EXC_MASK_CRASH, the_exception_server, EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, f) == KERN_SUCCESS); Modified: branches/SULeopard/launchd/src/launchd_runtime.c =================================================================== --- branches/SULeopard/launchd/src/launchd_runtime.c 2007-12-07 21:06:19 UTC (rev 23458) +++ branches/SULeopard/launchd/src/launchd_runtime.c 2007-12-07 21:15:23 UTC (rev 23459) @@ -61,6 +61,7 @@ #include "launchd_internalServer.h" #include "launchd_internal.h" #include "notifyServer.h" +#include "mach_excServer.h" /* We shouldn't be including these */ #include "launch.h" @@ -86,6 +87,7 @@ static void *kqueue_demand_loop(void *arg); static void log_kevent_struct(int level, struct kevent *kev, int indx); +static boolean_t launchd_internal_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply); static void record_caller_creds(mach_msg_header_t *mh); static void launchd_runtime2(mach_msg_size_t msg_size, mig_reply_error_t *bufRequest, mig_reply_error_t *bufReply); static mach_msg_size_t max_msg_size; @@ -115,6 +117,12 @@ }; static sigset_t sigign_set; +mach_port_t +runtime_get_kernel_port(void) +{ + return launchd_internal_port; +} + void launchd_runtime_init(void) { @@ -846,9 +854,11 @@ { if (launchd_internal_server_routine(Request)) { return launchd_internal_server(Request, Reply); + } else if (notify_server_routine(Request)) { + return notify_server(Request, Reply); + } else { + return mach_exc_server(Request, Reply); } - - return notify_server(Request, Reply); } kern_return_t @@ -1450,3 +1460,49 @@ { runtime_busy_cnt--; } + +kern_return_t +catch_mach_exception_raise(mach_port_t exception_port, mach_port_t thread, mach_port_t task, + exception_type_t exception, mach_exception_data_t code, mach_msg_type_number_t codeCnt) +{ + runtime_syslog(LOG_NOTICE, "%s(): thread: 0x%x task: 0x%x type: 0x%x code: %p codeCnt: 0x%x", + __func__, thread, task, exception, code, codeCnt); + + launchd_assumes(launchd_mport_deallocate(thread) == KERN_SUCCESS); + launchd_assumes(launchd_mport_deallocate(task) == KERN_SUCCESS); + + return 0; +} + +kern_return_t +catch_mach_exception_raise_state(mach_port_t exception_port, + exception_type_t exception, const mach_exception_data_t code, mach_msg_type_number_t codeCnt, + int *flavor, const thread_state_t old_state, mach_msg_type_number_t old_stateCnt, + thread_state_t new_state, mach_msg_type_number_t *new_stateCnt) +{ + runtime_syslog(LOG_NOTICE, "%s(): type: 0x%x code: %p codeCnt: 0x%x flavor: %p old_state: %p old_stateCnt: 0x%x new_state: %p new_stateCnt: %p", + __func__, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); + + memcpy(new_state, old_state, old_stateCnt * sizeof(old_state[0])); + *new_stateCnt = old_stateCnt; + + return 0; +} + +kern_return_t +catch_mach_exception_raise_state_identity(mach_port_t exception_port, mach_port_t thread, mach_port_t task, + exception_type_t exception, mach_exception_data_t code, mach_msg_type_number_t codeCnt, + int *flavor, thread_state_t old_state, mach_msg_type_number_t old_stateCnt, + thread_state_t new_state, mach_msg_type_number_t *new_stateCnt) +{ + runtime_syslog(LOG_NOTICE, "%s(): thread: 0x%x task: 0x%x type: 0x%x code: %p codeCnt: 0x%x flavor: %p old_state: %p old_stateCnt: 0x%x new_state: %p new_stateCnt: %p", + __func__, thread, task, exception, code, codeCnt, flavor, old_state, old_stateCnt, new_state, new_stateCnt); + + memcpy(new_state, old_state, old_stateCnt * sizeof(old_state[0])); + *new_stateCnt = old_stateCnt; + + launchd_assumes(launchd_mport_deallocate(thread) == KERN_SUCCESS); + launchd_assumes(launchd_mport_deallocate(task) == KERN_SUCCESS); + + return 0; +} Modified: branches/SULeopard/launchd/src/launchd_runtime.h =================================================================== --- branches/SULeopard/launchd/src/launchd_runtime.h 2007-12-07 21:06:19 UTC (rev 23458) +++ branches/SULeopard/launchd/src/launchd_runtime.h 2007-12-07 21:15:23 UTC (rev 23459) @@ -56,7 +56,7 @@ typedef boolean_t (*mig_callback)(mach_msg_header_t *, mach_msg_header_t *); typedef void (*timeout_callback)(void); -boolean_t launchd_internal_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply); +mach_port_t runtime_get_kernel_port(void); void runtime_add_ref(void); void runtime_del_ref(void); Modified: branches/SULeopard/launchd/src/liblaunch_private.h =================================================================== --- branches/SULeopard/launchd/src/liblaunch_private.h 2007-12-07 21:06:19 UTC (rev 23458) +++ branches/SULeopard/launchd/src/liblaunch_private.h 2007-12-07 21:15:23 UTC (rev 23459) @@ -55,6 +55,7 @@ #define LAUNCH_JOBKEY_PERJOBMACHSERVICES "PerJobMachServices" #define LAUNCH_JOBKEY_SERVICEIPC "ServiceIPC" #define LAUNCH_JOBKEY_BINARYORDERPREFERENCE "BinaryOrderPreference" +#define LAUNCH_JOBKEY_MACHEXCEPTIONHANDLER "MachExceptionHandler" #define LAUNCH_JOBKEY_MACH_KUNCSERVER "kUNCServer" #define LAUNCH_JOBKEY_MACH_EXCEPTIONSERVER "ExceptionServer" -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071207/10a98a60/attachment-0001.html From source_changes at macosforge.org Fri Dec 7 13:20:57 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Fri Dec 7 13:22:27 2007 Subject: [launchd-changes] [23460] tags/launchd-258.1/ Message-ID: <20071207212057.8C6092CE5BB@beta.macosforge.org> Revision: 23460 http://trac.macosforge.org/projects/launchd/changeset/23460 Author: zarzycki@apple.com Date: 2007-12-07 13:20:54 -0800 (Fri, 07 Dec 2007) Log Message: ----------- "Tagging launchd-258.1 from https://svn.macosforge.org/repository/launchd/branches/SULeopard" Added Paths: ----------- tags/launchd-258.1/ Copied: tags/launchd-258.1 (from rev 23459, branches/SULeopard) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071207/b0e4648b/attachment.html From source_changes at macosforge.org Fri Dec 7 13:24:47 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Fri Dec 7 13:26:18 2007 Subject: [launchd-changes] [23461] tags/launchd-259/ Message-ID: <20071207212447.0AC3C2CE679@beta.macosforge.org> Revision: 23461 http://trac.macosforge.org/projects/launchd/changeset/23461 Author: zarzycki@apple.com Date: 2007-12-07 13:24:39 -0800 (Fri, 07 Dec 2007) Log Message: ----------- "Tagging launchd-259 from https://svn.macosforge.org/repository/launchd/trunk" Added Paths: ----------- tags/launchd-259/ Copied: tags/launchd-259 (from rev 23460, trunk) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071207/b9befd0f/attachment.html From source_changes at macosforge.org Fri Dec 7 16:02:42 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Fri Dec 7 16:04:14 2007 Subject: [launchd-changes] [23462] trunk/launchd/src Message-ID: <20071208000242.383612D12FF@beta.macosforge.org> Revision: 23462 http://trac.macosforge.org/projects/launchd/changeset/23462 Author: zarzycki@apple.com Date: 2007-12-07 16:02:39 -0800 (Fri, 07 Dec 2007) Log Message: ----------- Turn -Wpadded back on. Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/liblaunch.c Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-12-07 21:24:39 UTC (rev 23461) +++ trunk/launchd/src/Makefile.am 2007-12-08 00:02:39 UTC (rev 23462) @@ -1,4 +1,4 @@ -AM_CFLAGS = -F/System/Library/PrivateFrameworks -Wall -Wextra -Waggregate-return -Wshadow -Wmissing-prototypes -Wmissing-declarations -Werror -D__MigTypeCheck=1 -fvisibility=hidden -freorder-blocks -Dmig_external=__private_extern__ +AM_CFLAGS = -F/System/Library/PrivateFrameworks -Wall -Wextra -Waggregate-return -Wshadow -Wpadded -Wmissing-prototypes -Wmissing-declarations -Werror -D__MigTypeCheck=1 -fvisibility=hidden -freorder-blocks -Dmig_external=__private_extern__ CLEANFILES = protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h \ launchd_internal.h launchd_internalServer.h launchd_internalServer.c launchd_internalUser.c \ @@ -39,7 +39,7 @@ sysconf_DATA = hostconfig rc.common rc.netboot -launchctl_CFLAGS = $(AM_CFLAGS) -I/System/Library/Frameworks/System.framework/PrivateHeaders +launchctl_CFLAGS = $(AM_CFLAGS) -isystem /System/Library/Frameworks/System.framework/PrivateHeaders launchctl_LDFLAGS = -framework CoreFoundation -framework IOKit -framework Security -weak_library /usr/lib/libedit.dylib SystemStarter_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-12-07 21:24:39 UTC (rev 23461) +++ trunk/launchd/src/Makefile.in 2007-12-08 00:02:39 UTC (rev 23462) @@ -238,7 +238,7 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -AM_CFLAGS = -F/System/Library/PrivateFrameworks -Wall -Wextra -Waggregate-return -Wshadow -Wmissing-prototypes -Wmissing-declarations -Werror -D__MigTypeCheck=1 -fvisibility=hidden -freorder-blocks -Dmig_external=__private_extern__ +AM_CFLAGS = -F/System/Library/PrivateFrameworks -Wall -Wextra -Waggregate-return -Wshadow -Wpadded -Wmissing-prototypes -Wmissing-declarations -Werror -D__MigTypeCheck=1 -fvisibility=hidden -freorder-blocks -Dmig_external=__private_extern__ CLEANFILES = protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h \ launchd_internal.h launchd_internalServer.h launchd_internalServer.c launchd_internalUser.c \ notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c mach_excServer.c mach_excServer.h @@ -249,7 +249,7 @@ @LIBS_ONLY_TRUE@liblaunch_profile_a_CFLAGS = -pg -D__DARWIN_NON_CANCELABLE=1 $(AM_CFLAGS) @LIBS_ONLY_TRUE@liblaunch_profile_a_SOURCES = liblaunch.c libvproc.c libbootstrap.c protocol_vprocUser.c __version.c @LIBS_ONLY_FALSE@sysconf_DATA = hostconfig rc.common rc.netboot -@LIBS_ONLY_FALSE@launchctl_CFLAGS = $(AM_CFLAGS) -I/System/Library/Frameworks/System.framework/PrivateHeaders +@LIBS_ONLY_FALSE@launchctl_CFLAGS = $(AM_CFLAGS) -isystem /System/Library/Frameworks/System.framework/PrivateHeaders @LIBS_ONLY_FALSE@launchctl_LDFLAGS = -framework CoreFoundation -framework IOKit -framework Security -weak_library /usr/lib/libedit.dylib @LIBS_ONLY_FALSE@SystemStarter_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) @LIBS_ONLY_FALSE@SystemStarter_LDFLAGS = -framework CoreFoundation -framework IOKit Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-07 21:24:39 UTC (rev 23461) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-08 00:02:39 UTC (rev 23462) @@ -116,7 +116,7 @@ struct mspolicy { SLIST_ENTRY(mspolicy) sle; - unsigned int allow:1, per_pid:1; + unsigned int allow:1, per_pid:1, __junk:30; const char name[0]; }; @@ -134,7 +134,8 @@ job_t job; unsigned int gen_num; mach_port_name_t port; - unsigned int isActive:1, reset:1, recv:1, hide:1, kUNCServer:1, per_user_hack:1, debug_on_close:1, per_pid:1, special_port_num:10; + unsigned int isActive:1, reset:1, recv:1, hide:1, kUNCServer:1, + per_user_hack:1, debug_on_close:1, per_pid:1, special_port_num:24; const char name[0]; }; @@ -270,7 +271,7 @@ unsigned int global_on_demand_cnt; unsigned int hopefully_first_cnt; unsigned int normal_active_cnt; - unsigned int sent_stop_to_normal_jobs:1, sent_stop_to_hopefully_last_jobs:1, shutting_down:1, session_initialized:1; + unsigned int sent_stop_to_normal_jobs:1, sent_stop_to_hopefully_last_jobs:1, shutting_down:1, session_initialized:1, __junk:28; char name[0]; }; @@ -353,15 +354,15 @@ uint64_t start_time; uint32_t min_run_time; uint32_t start_interval; - unsigned int checkedin:1, anonymous:1, debug:1, inetcompat:1, inetcompat_wait:1, + unsigned short checkedin:1, anonymous:1, debug:1, inetcompat:1, inetcompat_wait:1, ondemand:1, session_create:1, low_pri_io:1, no_init_groups:1, priv_port_has_senders:1, - importing_global_env:1, importing_hard_limits:1, setmask:1, legacy_mach_job:1, start_pending:1; - mode_t mask; - unsigned int globargv:1, wait4debugger:1, internal_exc_handler:1, stall_before_exec:1, only_once:1, + importing_global_env:1, importing_hard_limits:1, setmask:1, legacy_mach_job:1, start_pending:1, + globargv:1, wait4debugger:1, internal_exc_handler:1, stall_before_exec:1, only_once:1, currently_ignored:1, forced_peers_to_demand_mode:1, setnice:1, hopefully_exits_last:1, removal_pending:1, legacy_LS_job:1, sent_sigkill:1, debug_before_kill:1, weird_bootstrap:1, start_on_mount:1, per_user:1, hopefully_exits_first:1, deny_unknown_mslookups:1, unload_at_mig_return:1, abandon_pg:1, - poll_for_vfs_changes:1; + poll_for_vfs_changes:1, __junk:12; + mode_t mask; const char label[0]; }; Modified: trunk/launchd/src/liblaunch.c =================================================================== --- trunk/launchd/src/liblaunch.c 2007-12-07 21:24:39 UTC (rev 23461) +++ trunk/launchd/src/liblaunch.c 2007-12-08 00:02:39 UTC (rev 23462) @@ -138,6 +138,9 @@ size_t recvlen; size_t recvfdcnt; int fd; +#if __LP64__ + int __pad; +#endif }; static launch_data_t launch_data_array_pop_first(launch_data_t where); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071207/67347f3e/attachment-0001.html From source_changes at macosforge.org Wed Dec 12 12:32:55 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Wed Dec 12 12:34:05 2007 Subject: [launchd-changes] [23463] trunk/launchd/src Message-ID: <20071212203255.AF39833714F@beta.macosforge.org> Revision: 23463 http://trac.macosforge.org/projects/launchd/changeset/23463 Author: zarzycki@apple.com Date: 2007-12-12 12:32:53 -0800 (Wed, 12 Dec 2007) Log Message: ----------- Misc updates. Modified Paths: -------------- trunk/launchd/src/Makefile.am trunk/launchd/src/Makefile.in trunk/launchd/src/launchd.c trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c trunk/launchd/src/launchd_runtime.h Modified: trunk/launchd/src/Makefile.am =================================================================== --- trunk/launchd/src/Makefile.am 2007-12-08 00:02:39 UTC (rev 23462) +++ trunk/launchd/src/Makefile.am 2007-12-12 20:32:53 UTC (rev 23463) @@ -1,4 +1,4 @@ -AM_CFLAGS = -F/System/Library/PrivateFrameworks -Wall -Wextra -Waggregate-return -Wshadow -Wpadded -Wmissing-prototypes -Wmissing-declarations -Werror -D__MigTypeCheck=1 -fvisibility=hidden -freorder-blocks -Dmig_external=__private_extern__ +AM_CFLAGS = -F/System/Library/PrivateFrameworks -Wall -Wextra -Waggregate-return -Wfloat-equal -Wshadow -Wpacked -Wpadded -Wstrict-overflow=4 -Wmissing-prototypes -Wmissing-declarations -Werror -D__MigTypeCheck=1 -fvisibility=hidden -freorder-blocks -Dmig_external=__private_extern__ CLEANFILES = protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h \ launchd_internal.h launchd_internalServer.h launchd_internalServer.c launchd_internalUser.c \ @@ -46,7 +46,7 @@ SystemStarter_LDFLAGS = -framework CoreFoundation -framework IOKit SystemStarter_SOURCES = StartupItems.c IPC.c SystemStarter.c -launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -Wno-unused-parameter +launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) # -Wconversion # -Wstrict-aliasing=2 -fstrict-aliasing launchd_LDFLAGS = -lbsm launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.c job_forwardUser.c mach_excServer.c Modified: trunk/launchd/src/Makefile.in =================================================================== --- trunk/launchd/src/Makefile.in 2007-12-08 00:02:39 UTC (rev 23462) +++ trunk/launchd/src/Makefile.in 2007-12-12 20:32:53 UTC (rev 23463) @@ -238,7 +238,7 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -AM_CFLAGS = -F/System/Library/PrivateFrameworks -Wall -Wextra -Waggregate-return -Wshadow -Wpadded -Wmissing-prototypes -Wmissing-declarations -Werror -D__MigTypeCheck=1 -fvisibility=hidden -freorder-blocks -Dmig_external=__private_extern__ +AM_CFLAGS = -F/System/Library/PrivateFrameworks -Wall -Wextra -Waggregate-return -Wfloat-equal -Wshadow -Wpacked -Wpadded -Wstrict-overflow=4 -Wmissing-prototypes -Wmissing-declarations -Werror -D__MigTypeCheck=1 -fvisibility=hidden -freorder-blocks -Dmig_external=__private_extern__ CLEANFILES = protocol_vproc.h protocol_vprocServer.c protocol_vprocUser.c protocol_vprocServer.h \ launchd_internal.h launchd_internalServer.h launchd_internalServer.c launchd_internalUser.c \ notifyServer.c notifyServer.h job_replyUser.c job_reply.h __version.c mach_excServer.c mach_excServer.h @@ -254,7 +254,7 @@ @LIBS_ONLY_FALSE@SystemStarter_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) @LIBS_ONLY_FALSE@SystemStarter_LDFLAGS = -framework CoreFoundation -framework IOKit @LIBS_ONLY_FALSE@SystemStarter_SOURCES = StartupItems.c IPC.c SystemStarter.c -@LIBS_ONLY_FALSE@launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) -Wno-unused-parameter +@LIBS_ONLY_FALSE@launchd_CFLAGS = -mdynamic-no-pic $(AM_CFLAGS) # -Wconversion # -Wstrict-aliasing=2 -fstrict-aliasing @LIBS_ONLY_FALSE@launchd_LDFLAGS = -lbsm @LIBS_ONLY_FALSE@launchd_SOURCES = launchd.c launchd_core_logic.c launchd_unix_ipc.c protocol_vprocServer.c notifyServer.c launchd_internalUser.c launchd_internalServer.c job_replyUser.c launchd_runtime.c launchd_runtime_kill.c job_forwardUser.c mach_excServer.c @LIBS_ONLY_FALSE@launchproxy_LDFLAGS = -weak_framework Security Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-12-08 00:02:39 UTC (rev 23462) +++ trunk/launchd/src/launchd.c 2007-12-12 20:32:53 UTC (rev 23463) @@ -176,7 +176,7 @@ static __attribute__((unused)) typeof(reboot) *__junk_dyld_trick3 = reboot; void -fatal_signal_handler(int sig, siginfo_t *si, void *uap) +fatal_signal_handler(int sig, siginfo_t *si, void *uap __attribute__((unused))) { const char *doom_why = "at instruction"; char *sample_args[] = { "/usr/bin/sample", "1", "1", "-file", PID1_CRASH_LOGFILE, NULL }; @@ -245,6 +245,7 @@ void launchd_shutdown(void) { + struct timeval tvnow; struct stat sb; if (shutdown_in_progress) { @@ -263,6 +264,12 @@ debug_shutdown_hangs = true; } + if (launchd_assumes(gettimeofday(&tvnow, NULL) != -1)) { + runtime_syslog(LOG_NOTICE, "Shutdown began at: %lu.%06u", tvnow.tv_sec, tvnow.tv_usec); + } + + launchd_log_vm_stats(); + launchd_assert(jobmgr_shutdown(root_jobmgr) != NULL); } @@ -372,7 +379,7 @@ } void -pfsystem_callback(void *obj, struct kevent *kev) +pfsystem_callback(void *obj __attribute__((unused)), struct kevent *kev) { bool new_networking_state; char buf[1024]; Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-08 00:02:39 UTC (rev 23462) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-12 20:32:53 UTC (rev 23463) @@ -401,7 +401,7 @@ static void job_setup_exception_port(job_t j, task_t target_task); static void job_reparent_hack(job_t j, const char *where); static void job_callback(void *obj, struct kevent *kev); -static void job_callback_proc(job_t j, int flags, int fflags); +static void job_callback_proc(job_t j, int fflags); static void job_callback_timer(job_t j, void *ident); static void job_callback_read(job_t j, int ident); static void job_log_stray_pg(job_t j); @@ -752,6 +752,9 @@ runtime_del_ref(); SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); } else if (getpid() == 1) { + jobmgr_log(jm, LOG_DEBUG, "About to call: sync()"); + sync(); /* We're are going to rely on log timestamps to benchmark this call */ + launchd_log_vm_stats(); jobmgr_log(jm, LOG_DEBUG, "About to call: reboot(%s)", reboot_flags_to_C_names(jm->reboot_flags)); runtime_closelog(); jobmgr_assumes(jm, reboot(jm->reboot_flags) != -1); @@ -1109,7 +1112,7 @@ } if (jobmgr_assumes(jm, (jr = job_new(jm, AUTO_PICK_LEGACY_LABEL, kp.kp_proc.p_comm, NULL)) != NULL)) { - u_int proc_fflags = NOTE_EXEC|NOTE_FORK|NOTE_EXIT /* |NOTE_REAP */; + u_int proc_fflags = NOTE_EXEC|NOTE_FORK|NOTE_EXIT|NOTE_REAP; total_anon_children++; jr->anonymous = true; @@ -2348,7 +2351,7 @@ } void -job_callback_proc(job_t j, int flags, int fflags) +job_callback_proc(job_t j, int fflags) { bool program_changed = false; @@ -2394,15 +2397,9 @@ } } - /* NOTE_REAP sanity checking is disabled for now while we try and diagnose 5289559 */ -#if 0 if (j && (fflags & NOTE_REAP)) { - job_assumes(j, flags & EV_ONESHOT); - job_assumes(j, flags & EV_EOF); - job_assumes(j, j->p == 0); } -#endif } void @@ -2510,7 +2507,7 @@ switch (kev->filter) { case EVFILT_PROC: - return job_callback_proc(j, kev->flags, kev->fflags); + return job_callback_proc(j, kev->fflags); case EVFILT_TIMER: return job_callback_timer(j, (void *)kev->ident); case EVFILT_VNODE: @@ -2534,7 +2531,7 @@ char nbuf[64]; pid_t c; bool sipc = false; - u_int proc_fflags = NOTE_EXIT|NOTE_FORK|NOTE_EXEC /* NOTE_REAP */; + u_int proc_fflags = NOTE_EXIT|NOTE_FORK|NOTE_EXEC|NOTE_REAP; if (!job_assumes(j, j->mgr != NULL)) { return; @@ -2687,11 +2684,11 @@ void job_start_child(job_t j) { + typeof(posix_spawn) *psf; const char *file2exec = "/usr/libexec/launchproxy"; const char **argv; posix_spawnattr_t spattr; int gflags = GLOB_NOSORT|GLOB_NOCHECK|GLOB_TILDE|GLOB_DOOFFS; - pid_t junk_pid; glob_t g; short spflags = POSIX_SPAWN_SETEXEC; size_t binpref_out_cnt = 0; @@ -2769,14 +2766,15 @@ } } - if (j->prog) { - errno = posix_spawn(&junk_pid, j->inetcompat ? file2exec : j->prog, NULL, &spattr, (char *const*)argv, environ); - job_log_error(j, LOG_ERR, "posix_spawn(\"%s\", ...)", j->prog); - } else { - errno = posix_spawnp(&junk_pid, j->inetcompat ? file2exec : argv[0], NULL, &spattr, (char *const*)argv, environ); - job_log_error(j, LOG_ERR, "posix_spawnp(\"%s\", ...)", argv[0]); + psf = j->prog ? posix_spawn : posix_spawnp; + + if (!j->inetcompat) { + file2exec = j->prog ? j->prog : argv[0]; } + errno = psf(NULL, file2exec, NULL, &spattr, (char *const*)argv, environ); + job_log_error(j, LOG_ERR, "posix_spawn(\"%s\", ...)", j->prog); + out_bad: _exit(EXIT_FAILURE); } @@ -4234,20 +4232,6 @@ jobmgr_log(jm, LOG_DEBUG, "Garbage collecting."); - /* - * Normally, we wait for all resources of a job (Unix PIDs/FDs and Mach ports) - * to reset before we conider the job truly dead and ready to be spawned again. - * - * In order to work around 5487724 and 3456090, we're going to call reboot() - * when the last PID dies and not wait for the associated resources to reset. - */ - if (getpid() == 1 && jm->parentmgr == NULL && total_children == 0) { - jobmgr_log_stray_children(jm); - jobmgr_log(jm, LOG_DEBUG, "About to force a call to: reboot(%s)", reboot_flags_to_C_names(jm->reboot_flags)); - runtime_closelog(); - jobmgr_assumes(jm, reboot(jm->reboot_flags) != -1); - } - if (jm->hopefully_first_cnt) { return jm; } Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-12-08 00:02:39 UTC (rev 23462) +++ trunk/launchd/src/launchd_runtime.c 2007-12-12 20:32:53 UTC (rev 23463) @@ -869,7 +869,7 @@ } kern_return_t -do_mach_notify_port_destroyed(mach_port_t notify, mach_port_t rights) +do_mach_notify_port_destroyed(mach_port_t notify __attribute__((unused)), mach_port_t rights) { /* This message is sent to us when a receive right is returned to us. */ @@ -881,7 +881,7 @@ } kern_return_t -do_mach_notify_port_deleted(mach_port_t notify, mach_port_name_t name) +do_mach_notify_port_deleted(mach_port_t notify __attribute__((unused)), mach_port_name_t name __attribute__((unused))) { /* If we deallocate/destroy/mod_ref away a port with a pending * notification, the original notification message is replaced with @@ -892,7 +892,7 @@ } kern_return_t -do_mach_notify_no_senders(mach_port_t notify, mach_port_mscount_t mscount) +do_mach_notify_no_senders(mach_port_t notify, mach_port_mscount_t mscount __attribute__((unused))) { job_t j = job_mig_intran(notify); @@ -910,7 +910,7 @@ } kern_return_t -do_mach_notify_send_once(mach_port_t notify) +do_mach_notify_send_once(mach_port_t notify __attribute__((unused))) { /* This message is sent to us every time we close a port that we have * outstanding Mach notification requests on. We can safely ignore this @@ -921,7 +921,7 @@ } kern_return_t -do_mach_notify_dead_name(mach_port_t notify, mach_port_name_t name) +do_mach_notify_dead_name(mach_port_t notify __attribute__((unused)), mach_port_name_t name) { /* This message is sent to us when one of our send rights no longer has * a receiver somewhere else on the system. @@ -1467,7 +1467,7 @@ } kern_return_t -catch_mach_exception_raise(mach_port_t exception_port, mach_port_t thread, mach_port_t task, +catch_mach_exception_raise(mach_port_t exception_port __attribute__((unused)), mach_port_t thread, mach_port_t task, exception_type_t exception, mach_exception_data_t code, mach_msg_type_number_t codeCnt) { pid_t p4t = -1; @@ -1484,7 +1484,7 @@ } kern_return_t -catch_mach_exception_raise_state(mach_port_t exception_port, +catch_mach_exception_raise_state(mach_port_t exception_port __attribute__((unused)), exception_type_t exception, const mach_exception_data_t code, mach_msg_type_number_t codeCnt, int *flavor, const thread_state_t old_state, mach_msg_type_number_t old_stateCnt, thread_state_t new_state, mach_msg_type_number_t *new_stateCnt) @@ -1499,7 +1499,7 @@ } kern_return_t -catch_mach_exception_raise_state_identity(mach_port_t exception_port, mach_port_t thread, mach_port_t task, +catch_mach_exception_raise_state_identity(mach_port_t exception_port __attribute__((unused)), mach_port_t thread, mach_port_t task, exception_type_t exception, mach_exception_data_t code, mach_msg_type_number_t codeCnt, int *flavor, thread_state_t old_state, mach_msg_type_number_t old_stateCnt, thread_state_t new_state, mach_msg_type_number_t *new_stateCnt) @@ -1519,3 +1519,51 @@ return 0; } + +void +launchd_log_vm_stats(void) +{ + static struct vm_statistics orig_stats; + static bool did_first_pass; + unsigned int count = HOST_VM_INFO_COUNT; + struct vm_statistics stats, *statsp; + mach_port_t mhs = mach_host_self(); + + statsp = did_first_pass ? &stats : &orig_stats; + + if (!launchd_assumes(host_statistics(mhs, HOST_VM_INFO, (host_info_t)statsp, &count) == KERN_SUCCESS)) { + return; + } + + launchd_assumes(count == HOST_VM_INFO_COUNT); + + if (did_first_pass) { + runtime_syslog(LOG_DEBUG, "VM statistics (now - orig): Free: %d Active: %d Inactive: %d Reactivations: %d PageIns: %d PageOuts: %d Faults: %d COW-Faults: %d Purgeable: %d Purges: %d", + stats.free_count - orig_stats.free_count, + stats.active_count - orig_stats.active_count, + stats.inactive_count - orig_stats.inactive_count, + stats.reactivations - orig_stats.reactivations, + stats.pageins - orig_stats.pageins, + stats.pageouts - orig_stats.pageouts, + stats.faults - orig_stats.faults, + stats.cow_faults - orig_stats.cow_faults, + stats.purgeable_count - orig_stats.purgeable_count, + stats.purges - orig_stats.purges); + } else { + runtime_syslog(LOG_DEBUG, "VM statistics (now): Free: %d Active: %d Inactive: %d Reactivations: %d PageIns: %d PageOuts: %d Faults: %d COW-Faults: %d Purgeable: %d Purges: %d", + orig_stats.free_count, + orig_stats.active_count, + orig_stats.inactive_count, + orig_stats.reactivations, + orig_stats.pageins, + orig_stats.pageouts, + orig_stats.faults, + orig_stats.cow_faults, + orig_stats.purgeable_count, + orig_stats.purges); + + did_first_pass = true; + } + + launchd_mport_deallocate(mhs); +} Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2007-12-08 00:02:39 UTC (rev 23462) +++ trunk/launchd/src/launchd_runtime.h 2007-12-12 20:32:53 UTC (rev 23463) @@ -107,6 +107,8 @@ void launchd_runtime_init2(void); void launchd_runtime(void) __attribute__((noreturn)); +void launchd_log_vm_stats(void); + int runtime_close(int fd); int runtime_fsync(int fd); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071212/af7bd911/attachment-0001.html From source_changes at macosforge.org Wed Dec 12 13:12:29 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Wed Dec 12 13:13:37 2007 Subject: [launchd-changes] [23464] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071212211229.CE6C8337FBE@beta.macosforge.org> Revision: 23464 http://trac.macosforge.org/projects/launchd/changeset/23464 Author: zarzycki@apple.com Date: 2007-12-12 13:12:28 -0800 (Wed, 12 Dec 2007) Log Message: ----------- Let's do some more stuff in user-land so that we can benchmark it. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-12 20:32:53 UTC (rev 23463) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-12 21:12:28 UTC (rev 23464) @@ -453,6 +453,7 @@ static void extract_rcsid_substr(const char *i, char *o, size_t osz); static void do_first_per_user_launchd_hack(void); static void do_file_init(void) __attribute__((constructor)); +static void do_unmounts(void); /* file local globals */ static size_t total_children; @@ -754,6 +755,8 @@ } else if (getpid() == 1) { jobmgr_log(jm, LOG_DEBUG, "About to call: sync()"); sync(); /* We're are going to rely on log timestamps to benchmark this call */ + jobmgr_log(jm, LOG_DEBUG, "Unmounting all filesystems except / and /dev"); + do_unmounts(); launchd_log_vm_stats(); jobmgr_log(jm, LOG_DEBUG, "About to call: reboot(%s)", reboot_flags_to_C_names(jm->reboot_flags)); runtime_closelog(); @@ -6694,3 +6697,32 @@ launchd_assert(mach_timebase_info(&tbi) == 0); } + +void +do_unmounts(void) +{ + struct statfs buf[100]; + int i, found, returned; + + do { + returned = getfsstat(buf, sizeof(buf), MNT_NOWAIT); + found = 0; + + if (!launchd_assumes(returned != -1)) { + return; + } + + for (i = 0; i < returned; i++) { + if (strcmp(buf[i].f_mntonname, "/") == 0) { + continue; + } else if (strncmp(buf[i].f_mntonname, "/dev", strlen("/dev")) == 0) { + continue; + } + + runtime_syslog(LOG_DEBUG, "About to unmount: %s", buf[i].f_mntonname); + if (launchd_assumes(unmount(buf[i].f_mntonname, 0) != -1)) { + found++; + } + } + } while ((returned == (sizeof(buf) / sizeof(buf[0]))) && (found > 0)); +} -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071212/f6638592/attachment.html From source_changes at macosforge.org Wed Dec 12 13:54:34 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Wed Dec 12 13:55:12 2007 Subject: [launchd-changes] [23465] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071212215434.BF7FB338A73@beta.macosforge.org> Revision: 23465 http://trac.macosforge.org/projects/launchd/changeset/23465 Author: zarzycki@apple.com Date: 2007-12-12 13:54:32 -0800 (Wed, 12 Dec 2007) Log Message: ----------- We should walk the mount table list backwards. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-12 21:12:28 UTC (rev 23464) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-12 21:54:32 UTC (rev 23465) @@ -6701,7 +6701,7 @@ void do_unmounts(void) { - struct statfs buf[100]; + struct statfs buf[250]; int i, found, returned; do { @@ -6712,7 +6712,8 @@ return; } - for (i = 0; i < returned; i++) { + /* Work backwards due to mounts on top of mounts */ + for (i = returned - 1; i >= 0; i--) { if (strcmp(buf[i].f_mntonname, "/") == 0) { continue; } else if (strncmp(buf[i].f_mntonname, "/dev", strlen("/dev")) == 0) { -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071212/4253d8da/attachment.html From source_changes at macosforge.org Wed Dec 12 16:16:29 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Wed Dec 12 16:17:37 2007 Subject: [launchd-changes] [23466] trunk/launchd/src Message-ID: <20071213001629.AA78333B78C@beta.macosforge.org> Revision: 23466 http://trac.macosforge.org/projects/launchd/changeset/23466 Author: zarzycki@apple.com Date: 2007-12-12 16:16:27 -0800 (Wed, 12 Dec 2007) Log Message: ----------- Misc logging updates. Modified Paths: -------------- 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 Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-12-12 21:54:32 UTC (rev 23465) +++ trunk/launchd/src/launchd.c 2007-12-13 00:16:27 UTC (rev 23466) @@ -99,8 +99,7 @@ static void *crash_addr; static pid_t crash_pid; -static bool shutdown_in_progress = false; -bool debug_shutdown_hangs = false; +bool shutdown_in_progress = false; bool network_up = false; int @@ -246,7 +245,6 @@ launchd_shutdown(void) { struct timeval tvnow; - struct stat sb; if (shutdown_in_progress) { return; @@ -254,14 +252,13 @@ shutdown_in_progress = true; - if (getpid() == 1 && stat("/var/db/debugShutdownHangs", &sb) != -1) { + if (getpid() == 1) { /* * When this changes to a more sustainable API, update this: * http://howto.apple.com/db.cgi?Debugging_Apps_Non-Responsive_At_Shutdown */ runtime_setlogmask(LOG_UPTO(LOG_DEBUG)); prep_shutdown_log_dir(); - debug_shutdown_hangs = true; } if (launchd_assumes(gettimeofday(&tvnow, NULL) != -1)) { Modified: trunk/launchd/src/launchd.h =================================================================== --- trunk/launchd/src/launchd.h 2007-12-12 21:54:32 UTC (rev 23465) +++ trunk/launchd/src/launchd.h 2007-12-13 00:16:27 UTC (rev 23466) @@ -31,7 +31,7 @@ struct kevent; struct conncb; -extern bool debug_shutdown_hangs; +extern bool shutdown_in_progress; extern bool network_up; bool init_check_pid(pid_t); Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-12 21:54:32 UTC (rev 23465) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-13 00:16:27 UTC (rev 23466) @@ -710,7 +710,7 @@ } } - if (debug_shutdown_hangs && jm->parentmgr == NULL && getpid() == 1) { + if (do_apple_internal_logging() && jm->parentmgr == NULL && getpid() == 1) { runtime_set_timeout(still_alive_with_check, 5); } @@ -4294,7 +4294,7 @@ jobmgr_log_stray_children(jobmgr_t jm) { int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL }; - size_t i, kp_cnt, len = 10*1024*1024; + size_t i, kp_cnt = 0, kp_skipped = 0, len = 10*1024*1024; struct kinfo_proc *kp; if (jm->parentmgr || getpid() != 1) { @@ -4318,6 +4318,7 @@ const char *n = kp[i].kp_proc.p_comm; if (p_i == 0 || p_i == 1) { + kp_skipped++; continue; } @@ -4330,6 +4331,10 @@ } out: + if (kp_cnt == kp_skipped) { + jobmgr_log(jm, LOG_DEBUG, "No stray processes at shutdown"); + } + free(kp); } @@ -4766,7 +4771,7 @@ int wstatus; pid_t sp; - if (!debug_shutdown_hangs) { + if (!do_apple_internal_logging()) { return; } @@ -6702,7 +6707,7 @@ do_unmounts(void) { struct statfs buf[250]; - int i, found, returned; + int r, i, found, returned; do { returned = getfsstat(buf, sizeof(buf), MNT_NOWAIT); @@ -6720,8 +6725,11 @@ continue; } - runtime_syslog(LOG_DEBUG, "About to unmount: %s", buf[i].f_mntonname); - if (launchd_assumes(unmount(buf[i].f_mntonname, 0) != -1)) { + r = unmount(buf[i].f_mntonname, 0); + + runtime_syslog(LOG_DEBUG, "unmount(\"%s\", 0): %s", buf[i].f_mntonname, r == -1 ? strerror(errno) : "Success"); + + if (r != -1) { found++; } } Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-12-12 21:54:32 UTC (rev 23465) +++ trunk/launchd/src/launchd_runtime.c 2007-12-13 00:16:27 UTC (rev 23466) @@ -1131,7 +1131,7 @@ int runtime_fsync(int fd) { - if (debug_shutdown_hangs) { + if (do_apple_internal_logging()) { return fcntl(fd, F_FULLFSYNC, NULL); } else { return fsync(fd); @@ -1169,19 +1169,13 @@ static pthread_mutex_t ourlock = PTHREAD_MUTEX_INITIALIZER; static struct timeval shutdown_start; static struct timeval prev_msg; - static int apple_internal_logging = 1; struct timeval tvnow, tvd_total, tvd_msg_delta = { 0, 0 }; - struct stat sb; int saved_errno = errno; char newmsg[10000]; size_t i, j; - if (apple_internal_logging == 1) { - apple_internal_logging = stat("/AppleInternal", &sb); - } - if (attr->priority == LOG_APPLEONLY) { - if (apple_internal_logging == 0) { + if (do_apple_internal_logging()) { attr->priority = LOG_NOTICE; } else { return; @@ -1192,7 +1186,7 @@ goto out; } - if (!(debug_shutdown_hangs && getpid() == 1)) { + if (getpid() != 1 || !shutdown_in_progress) { vsnprintf(newmsg, sizeof(newmsg), message, args); logmsg_add(attr, saved_errno, newmsg); goto out; @@ -1567,3 +1561,16 @@ launchd_mport_deallocate(mhs); } + +bool +do_apple_internal_logging(void) +{ + static int apple_internal_logging = 1; + struct stat sb; + + if (apple_internal_logging == 1) { + apple_internal_logging = stat("/AppleInternal", &sb); + } + + return (apple_internal_logging == 0); +} Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2007-12-12 21:54:32 UTC (rev 23465) +++ trunk/launchd/src/launchd_runtime.h 2007-12-13 00:16:27 UTC (rev 23466) @@ -123,6 +123,7 @@ const char *reboot_flags_to_C_names(unsigned int flags); const char *proc_flags_to_C_names(unsigned int flags); +bool do_apple_internal_logging(void); int kevent_bulk_mod(struct kevent *kev, size_t kev_cnt); int kevent_mod(uintptr_t ident, short filter, u_short flags, u_int fflags, intptr_t data, void *udata); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071212/e49f8183/attachment-0001.html From source_changes at macosforge.org Thu Dec 13 12:35:50 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Thu Dec 13 12:36:22 2007 Subject: [launchd-changes] [23467] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071213203550.4530F34DB6D@beta.macosforge.org> Revision: 23467 http://trac.macosforge.org/projects/launchd/changeset/23467 Author: zarzycki@apple.com Date: 2007-12-13 12:35:48 -0800 (Thu, 13 Dec 2007) Log Message: ----------- Fix a think-o. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-13 00:16:27 UTC (rev 23466) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-13 20:35:48 UTC (rev 23467) @@ -5737,6 +5737,7 @@ static pid_t last_warned_pid = 0; struct machservice *ms; struct ldcred ldc; + job_t jo; if (!launchd_assumes(j != NULL)) { return BOOTSTRAP_NO_MEMORY; @@ -5750,9 +5751,10 @@ job_log(j, LOG_DEBUG, "Check-in of Mach service failed. Unknown: %s", servicename); return BOOTSTRAP_UNKNOWN_SERVICE; } - if (machservice_job(ms) != j) { + + if ((jo = machservice_job(ms)) != j) { if (last_warned_pid != ldc.pid) { - job_log(j, LOG_NOTICE, "Check-in of Mach service failed. The service \"%s\" is owned by: %s", servicename, j->label); + job_log(j, LOG_NOTICE, "Check-in of Mach service failed. The service \"%s\" is owned by: %s", servicename, jo->label); last_warned_pid = ldc.pid; } return BOOTSTRAP_NOT_PRIVILEGED; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071213/5fe0f408/attachment.html From source_changes at macosforge.org Wed Dec 19 09:33:13 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Wed Dec 19 09:33:51 2007 Subject: [launchd-changes] [23468] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071219173313.6444740E7A6@beta.macosforge.org> Revision: 23468 http://trac.macosforge.org/projects/launchd/changeset/23468 Author: zarzycki@apple.com Date: 2007-12-19 09:33:08 -0800 (Wed, 19 Dec 2007) Log Message: ----------- More missing bits. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-13 20:35:48 UTC (rev 23467) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-19 17:33:08 UTC (rev 23468) @@ -798,6 +798,17 @@ ipc_close_all_with_job(j); +#if DO_RUSAGE_SUMMATION + job_log(j, LOG_INFO, "Total rusage: utime %ld.%06u stime %ld.%06u maxrss %lu ixrss %lu idrss %lu isrss %lu minflt %lu majflt %lu nswap %lu inblock %lu oublock %lu msgsnd %lu msgrcv %lu nsignals %lu nvcsw %lu nivcsw %lu", + j->ru.ru_utime.tv_sec, j->ru.ru_utime.tv_usec, + j->ru.ru_stime.tv_sec, j->ru.ru_stime.tv_usec, + j->ru.ru_maxrss, j->ru.ru_ixrss, j->ru.ru_idrss, j->ru.ru_isrss, + j->ru.ru_minflt, j->ru.ru_majflt, + j->ru.ru_nswap, j->ru.ru_inblock, j->ru.ru_oublock, + j->ru.ru_msgsnd, j->ru.ru_msgrcv, + j->ru.ru_nsignals, j->ru.ru_nvcsw, j->ru.ru_nivcsw); +#endif + if (j->forced_peers_to_demand_mode) { job_set_global_on_demand(j, false); } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071219/16f0167b/attachment.html From source_changes at macosforge.org Wed Dec 19 09:40:59 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Wed Dec 19 09:40:37 2007 Subject: [launchd-changes] [23469] trunk/launchd/src Message-ID: <20071219174059.5A14C40EC06@beta.macosforge.org> Revision: 23469 http://trac.macosforge.org/projects/launchd/changeset/23469 Author: zarzycki@apple.com Date: 2007-12-19 09:40:56 -0800 (Wed, 19 Dec 2007) Log Message: ----------- printf output not appearing in console or appearing after app quits Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-19 17:33:08 UTC (rev 23468) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-19 17:40:56 UTC (rev 23469) @@ -2084,8 +2084,12 @@ } if (j->log_redirect_fd && !j->legacy_LS_job) { - job_assumes(j, runtime_close(j->log_redirect_fd) != -1); - j->log_redirect_fd = 0; + job_log_stdouterr(j); /* one last chance */ + + if (j->log_redirect_fd) { + job_assumes(j, runtime_close(j->log_redirect_fd) != -1); + j->log_redirect_fd = 0; + } } if (j->forkfd) { Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-12-19 17:33:08 UTC (rev 23468) +++ trunk/launchd/src/launchd_runtime.c 2007-12-19 17:40:56 UTC (rev 23469) @@ -1183,13 +1183,13 @@ } if (!(LOG_MASK(attr->priority) & internal_mask_pri)) { - goto out; + return; } if (getpid() != 1 || !shutdown_in_progress) { vsnprintf(newmsg, sizeof(newmsg), message, args); logmsg_add(attr, saved_errno, newmsg); - goto out; + return; } if (shutdown_start.tv_sec == 0) { @@ -1211,11 +1211,11 @@ pthread_mutex_unlock(&ourlock); if (ourlogfile == NULL) { - goto out; + return; } if (message == NULL) { - goto out; + return; } timersub(&tvnow, &shutdown_start, &tvd_total); @@ -1248,9 +1248,6 @@ strcpy(newmsg + j, "\n"); vfprintf(ourlogfile, newmsg, args); - -out: - runtime_log_uncork_pending_drain(); } bool @@ -1375,6 +1372,7 @@ launchd_assumes(STAILQ_EMPTY(&logmsg_queue)); return; } else if (getpid() == 1) { + runtime_log_uncork_pending_drain(); return; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071219/4a67597e/attachment.html From source_changes at macosforge.org Wed Dec 19 10:13:22 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Wed Dec 19 10:14:01 2007 Subject: [launchd-changes] [23470] trunk/launchd/src Message-ID: <20071219181322.9BB8640FE15@beta.macosforge.org> Revision: 23470 http://trac.macosforge.org/projects/launchd/changeset/23470 Author: zarzycki@apple.com Date: 2007-12-19 10:13:19 -0800 (Wed, 19 Dec 2007) Log Message: ----------- Better shutdown logging. Modified Paths: -------------- 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 Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-12-19 17:40:56 UTC (rev 23469) +++ trunk/launchd/src/launchd.c 2007-12-19 18:13:19 UTC (rev 23470) @@ -95,12 +95,13 @@ static void handle_pid1_crashes_separately(void); static void prep_shutdown_log_dir(void); -static bool re_exec_in_single_user_mode = false; +static bool re_exec_in_single_user_mode; static void *crash_addr; static pid_t crash_pid; -bool shutdown_in_progress = false; -bool network_up = false; +bool shutdown_in_progress; +bool fake_shutdown_in_progress; +bool network_up; int main(int argc, char *const *argv) @@ -261,12 +262,12 @@ prep_shutdown_log_dir(); } + runtime_log_push(); + if (launchd_assumes(gettimeofday(&tvnow, NULL) != -1)) { runtime_syslog(LOG_NOTICE, "Shutdown began at: %lu.%06u", tvnow.tv_sec, tvnow.tv_usec); } - launchd_log_vm_stats(); - launchd_assert(jobmgr_shutdown(root_jobmgr) != NULL); } Modified: trunk/launchd/src/launchd.h =================================================================== --- trunk/launchd/src/launchd.h 2007-12-19 17:40:56 UTC (rev 23469) +++ trunk/launchd/src/launchd.h 2007-12-19 18:13:19 UTC (rev 23470) @@ -32,6 +32,7 @@ struct conncb; extern bool shutdown_in_progress; +extern bool fake_shutdown_in_progress; extern bool network_up; bool init_check_pid(pid_t); Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-19 17:40:56 UTC (rev 23469) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-19 18:13:19 UTC (rev 23470) @@ -2481,7 +2481,9 @@ void jobmgr_callback(void *obj, struct kevent *kev) { + struct timeval tvnow; jobmgr_t jm = obj; + job_t ji; switch (kev->filter) { case EVFILT_PROC: @@ -2496,6 +2498,24 @@ return launchd_shutdown(); case SIGUSR1: return calendarinterval_callback(); + case SIGUSR2: + fake_shutdown_in_progress = true; + runtime_setlogmask(LOG_UPTO(LOG_DEBUG)); + + runtime_closelog(); /* HACK -- force 'start' time to be set */ + + if (getpid() == 1 && jobmgr_assumes(jm, gettimeofday(&tvnow, NULL) != -1)) { + jobmgr_log(jm, LOG_NOTICE, "Anticipatory shutdown began at: %lu.%06u", tvnow.tv_sec, tvnow.tv_usec); + LIST_FOREACH(ji, &root_jobmgr->jobs, sle) { + if (ji->per_user && ji->p) { + job_assumes(ji, runtime_kill(ji->p, SIGUSR2) != -1); + } + } + } else { + jobmgr_log(jm, LOG_NOTICE, "Anticipatory per-user launchd shutdown"); + } + + return; default: return (void)jobmgr_assumes(jm, false); } @@ -4453,6 +4473,7 @@ if (!jm) { jobmgr_assumes(jmr, kevent_mod(SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, jmr) != -1); jobmgr_assumes(jmr, kevent_mod(SIGUSR1, EVFILT_SIGNAL, EV_ADD, 0, 0, jmr) != -1); + jobmgr_assumes(jmr, kevent_mod(SIGUSR2, EVFILT_SIGNAL, EV_ADD, 0, 0, jmr) != -1); jobmgr_assumes(jmr, kevent_mod(0, EVFILT_FS, EV_ADD, VQ_MOUNT|VQ_UNMOUNT|VQ_UPDATE, 0, jmr) != -1); } @@ -5749,7 +5770,6 @@ kern_return_t job_mig_check_in(job_t j, name_t servicename, mach_port_t *serviceportp) { - static pid_t last_warned_pid = 0; struct machservice *ms; struct ldcred ldc; job_t jo; @@ -5768,11 +5788,14 @@ } if ((jo = machservice_job(ms)) != j) { + static pid_t last_warned_pid; + if (last_warned_pid != ldc.pid) { job_log(j, LOG_NOTICE, "Check-in of Mach service failed. The service \"%s\" is owned by: %s", servicename, jo->label); last_warned_pid = ldc.pid; } - return BOOTSTRAP_NOT_PRIVILEGED; + + return BOOTSTRAP_NOT_PRIVILEGED; } if (machservice_active(ms)) { job_log(j, LOG_WARNING, "Check-in of Mach service failed. Already active: %s", servicename); Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-12-19 17:40:56 UTC (rev 23469) +++ trunk/launchd/src/launchd_runtime.c 2007-12-19 18:13:19 UTC (rev 23470) @@ -105,7 +105,6 @@ static mach_port_t drain_reply_port; static void runtime_log_uncork_pending_drain(void); static kern_return_t runtime_log_pack(vm_offset_t *outval, mach_msg_type_number_t *outvalCnt); -static void runtime_log_push(void); static bool logmsg_add(struct runtime_syslog_attr *attr, int err_num, const char *msg); static void logmsg_remove(struct logmsg_s *lm); @@ -116,7 +115,9 @@ SIGXFSZ, SIGVTALRM, SIGPROF, SIGWINCH, SIGINFO, SIGUSR1, SIGUSR2 }; static sigset_t sigign_set; +static FILE *ourlogfile; + mach_port_t runtime_get_kernel_port(void) { @@ -1117,11 +1118,11 @@ return close(fd); } -static FILE *ourlogfile; - void runtime_closelog(void) { + runtime_log_push(); + if (ourlogfile) { launchd_assumes(fflush(ourlogfile) == 0); launchd_assumes(runtime_fsync(fileno(ourlogfile)) != -1); @@ -1131,11 +1132,15 @@ int runtime_fsync(int fd) { +#if 0 if (do_apple_internal_logging()) { return fcntl(fd, F_FULLFSYNC, NULL); } else { return fsync(fd); } +#else + return fsync(fd); +#endif } int @@ -1166,13 +1171,8 @@ void runtime_vsyslog(struct runtime_syslog_attr *attr, const char *message, va_list args) { - static pthread_mutex_t ourlock = PTHREAD_MUTEX_INITIALIZER; - static struct timeval shutdown_start; - static struct timeval prev_msg; - struct timeval tvnow, tvd_total, tvd_msg_delta = { 0, 0 }; int saved_errno = errno; char newmsg[10000]; - size_t i, j; if (attr->priority == LOG_APPLEONLY) { if (do_apple_internal_logging()) { @@ -1186,70 +1186,11 @@ return; } - if (getpid() != 1 || !shutdown_in_progress) { - vsnprintf(newmsg, sizeof(newmsg), message, args); - logmsg_add(attr, saved_errno, newmsg); - return; - } - - if (shutdown_start.tv_sec == 0) { - gettimeofday(&shutdown_start, NULL); - } - - if (gettimeofday(&tvnow, NULL) == -1) { - tvnow.tv_sec = 0; - tvnow.tv_usec = 0; - } - - pthread_mutex_lock(&ourlock); - - if (ourlogfile == NULL) { - rename("/var/log/launchd-shutdown.log", "/var/log/launchd-shutdown.log.1"); - ourlogfile = fopen("/var/log/launchd-shutdown.log", "a"); - } - - pthread_mutex_unlock(&ourlock); - - if (ourlogfile == NULL) { - return; - } - - if (message == NULL) { - return; - } - - timersub(&tvnow, &shutdown_start, &tvd_total); - - if (prev_msg.tv_sec != 0) { - timersub(&tvnow, &prev_msg, &tvd_msg_delta); - } - - prev_msg = tvnow; - - snprintf(newmsg, sizeof(newmsg), "%3ld.%06d%4ld.%06d%6u %-40s%6u %-40s ", - tvd_total.tv_sec, tvd_total.tv_usec, - tvd_msg_delta.tv_sec, tvd_msg_delta.tv_usec, - attr->from_pid, attr->from_name, - attr->about_pid, attr->about_name); - - for (i = 0, j = strlen(newmsg); message[i];) { - if (message[i] == '%' && message[i + 1] == 'm') { - char *errs = strerror(saved_errno); - strcpy(newmsg + j, errs ? errs : "unknown error"); - j += strlen(newmsg + j); - i += 2; - } else { - newmsg[j] = message[i]; - j++; - i++; - } - } - - strcpy(newmsg + j, "\n"); - - vfprintf(ourlogfile, newmsg, args); + vsnprintf(newmsg, sizeof(newmsg), message, args); + logmsg_add(attr, saved_errno, newmsg); } + bool logmsg_add(struct runtime_syslog_attr *attr, int err_num, const char *msg) { @@ -1365,24 +1306,62 @@ void runtime_log_push(void) { + static pthread_mutex_t ourlock = PTHREAD_MUTEX_INITIALIZER; + static struct timeval shutdown_start; + struct timeval tvd; mach_msg_type_number_t outvalCnt; + struct logmsg_s *lm; vm_offset_t outval; if (logmsg_queue_cnt == 0) { launchd_assumes(STAILQ_EMPTY(&logmsg_queue)); return; - } else if (getpid() == 1) { + } else if (getpid() != 1) { + if (runtime_log_pack(&outval, &outvalCnt) == 0) { + launchd_assumes(_vprocmgr_log_forward(inherited_bootstrap_port, (void *)outval, outvalCnt) == NULL); + mig_deallocate(outval, outvalCnt); + } + return; + } + + if (!shutdown_in_progress && !fake_shutdown_in_progress) { runtime_log_uncork_pending_drain(); return; } - if (runtime_log_pack(&outval, &outvalCnt) != 0) { + if (shutdown_start.tv_sec == 0) { + gettimeofday(&shutdown_start, NULL); + launchd_log_vm_stats(); + } + + + pthread_mutex_lock(&ourlock); + + if (ourlogfile == NULL) { + rename("/var/log/launchd-shutdown.log", "/var/log/launchd-shutdown.log.1"); + ourlogfile = fopen("/var/log/launchd-shutdown.log", "a"); + } + + pthread_mutex_unlock(&ourlock); + + if (!ourlogfile) { return; } - launchd_assumes(_vprocmgr_log_forward(inherited_bootstrap_port, (void *)outval, outvalCnt) == NULL); + while ((lm = STAILQ_FIRST(&logmsg_queue))) { + timersub(&lm->when, &shutdown_start, &tvd); - mig_deallocate(outval, outvalCnt); + /* don't ask */ + if (tvd.tv_sec < 0) { + tvd.tv_sec = 0; + tvd.tv_usec = 0; + } + + fprintf(ourlogfile, "%3ld.%06d%6u %-40s%6u %-40s %s\n", tvd.tv_sec, tvd.tv_usec, + lm->from_pid, lm->from_name, lm->about_pid, lm->about_name, lm->msg); + + logmsg_remove(lm); + } } kern_return_t @@ -1424,10 +1403,9 @@ kern_return_t runtime_log_drain(mach_port_t srp, vm_offset_t *outval, mach_msg_type_number_t *outvalCnt) { - if (logmsg_queue_cnt == 0) { - launchd_assumes(STAILQ_EMPTY(&logmsg_queue)); - launchd_assumes(drain_reply_port == 0); + launchd_assumes(drain_reply_port == 0); + if ((logmsg_queue_cnt == 0) || shutdown_in_progress || fake_shutdown_in_progress) { drain_reply_port = srp; launchd_assumes(launchd_mport_notify_req(drain_reply_port, MACH_NOTIFY_DEAD_NAME) == KERN_SUCCESS); Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2007-12-19 17:40:56 UTC (rev 23469) +++ trunk/launchd/src/launchd_runtime.h 2007-12-19 18:13:19 UTC (rev 23470) @@ -149,6 +149,7 @@ void runtime_closelog(void); void runtime_syslog(int pri, const char *message, ...) __attribute__((format(printf, 2, 3))); void runtime_vsyslog(struct runtime_syslog_attr *attr, const char *message, va_list args) __attribute__((format(printf, 2, 0))); +void runtime_log_push(void); kern_return_t launchd_set_bport(mach_port_t name); -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071219/f832de8c/attachment-0001.html From source_changes at macosforge.org Wed Dec 19 11:49:00 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Wed Dec 19 11:49:39 2007 Subject: [launchd-changes] [23471] trunk/launchd/src Message-ID: <20071219194900.00E9E413F4B@beta.macosforge.org> Revision: 23471 http://trac.macosforge.org/projects/launchd/changeset/23471 Author: zarzycki@apple.com Date: 2007-12-19 11:48:57 -0800 (Wed, 19 Dec 2007) Log Message: ----------- Both Mach and Unix time concepts are weird. We now use an 'int64_t' instead of 'struct timeval' for wall clock code. We now wrap the 'timebase info' logic required by Mach absolute time. Modified Paths: -------------- trunk/launchd/src/launchd.c trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_runtime.c trunk/launchd/src/launchd_runtime.h trunk/launchd/src/libvproc_internal.h Modified: trunk/launchd/src/launchd.c =================================================================== --- trunk/launchd/src/launchd.c 2007-12-19 18:13:19 UTC (rev 23470) +++ trunk/launchd/src/launchd.c 2007-12-19 19:48:57 UTC (rev 23471) @@ -245,7 +245,7 @@ void launchd_shutdown(void) { - struct timeval tvnow; + int64_t now; if (shutdown_in_progress) { return; @@ -264,10 +264,10 @@ runtime_log_push(); - if (launchd_assumes(gettimeofday(&tvnow, NULL) != -1)) { - runtime_syslog(LOG_NOTICE, "Shutdown began at: %lu.%06u", tvnow.tv_sec, tvnow.tv_usec); - } + now = runtime_get_wall_time(); + runtime_syslog(LOG_NOTICE, "Shutdown began at: %lld.%06llu", now / USEC_PER_SEC, now % USEC_PER_SEC); + launchd_assert(jobmgr_shutdown(root_jobmgr) != NULL); } Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-19 18:13:19 UTC (rev 23470) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-19 19:48:57 UTC (rev 23471) @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -452,7 +451,6 @@ static size_t our_strhash(const char *s) __attribute__((pure)); static void extract_rcsid_substr(const char *i, char *o, size_t osz); static void do_first_per_user_launchd_hack(void); -static void do_file_init(void) __attribute__((constructor)); static void do_unmounts(void); /* file local globals */ @@ -463,7 +461,6 @@ #define JOB_BOOTCACHE_HACK_CHECK(j) (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; -static mach_timebase_info_data_t tbi; /* process wide globals */ mach_port_t inherited_bootstrap_port; @@ -539,7 +536,7 @@ } job_assumes(j, runtime_kill(j->p, SIGTERM) != -1); - j->sent_sigterm_time = mach_absolute_time(); + j->sent_sigterm_time = runtime_get_opaque_time(); if (j->exit_timeout) { job_assumes(j, kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, @@ -2150,7 +2147,7 @@ } if (j->sent_sigterm_time) { - uint64_t td_sec, td_usec, td = (mach_absolute_time() - j->sent_sigterm_time) * tbi.numer / tbi.denom; + uint64_t td_sec, td_usec, td = runtime_opaque_time_to_nano(runtime_get_opaque_time() - j->sent_sigterm_time); td_sec = td / NSEC_PER_SEC; td_usec = (td % NSEC_PER_SEC) / NSEC_PER_USEC; @@ -2432,7 +2429,7 @@ job_dispatch(j, false); } else if (&j->exit_timeout == ident) { if (j->sent_sigkill) { - uint64_t td = (mach_absolute_time() - j->sent_sigterm_time) * tbi.numer / tbi.denom; + uint64_t td = runtime_opaque_time_to_nano(runtime_get_opaque_time() - j->sent_sigterm_time); td /= NSEC_PER_SEC; td -= j->exit_timeout; @@ -2481,7 +2478,6 @@ void jobmgr_callback(void *obj, struct kevent *kev) { - struct timeval tvnow; jobmgr_t jm = obj; job_t ji; @@ -2504,8 +2500,11 @@ runtime_closelog(); /* HACK -- force 'start' time to be set */ - if (getpid() == 1 && jobmgr_assumes(jm, gettimeofday(&tvnow, NULL) != -1)) { - jobmgr_log(jm, LOG_NOTICE, "Anticipatory shutdown began at: %lu.%06u", tvnow.tv_sec, tvnow.tv_usec); + if (getpid() == 1) { + int64_t now = runtime_get_wall_time(); + + jobmgr_log(jm, LOG_NOTICE, "Anticipatory shutdown began at: %lld.%06llu", now / USEC_PER_SEC, now % USEC_PER_SEC); + LIST_FOREACH(ji, &root_jobmgr->jobs, sle) { if (ji->per_user && ji->p) { job_assumes(ji, runtime_kill(ji->p, SIGUSR2) != -1); @@ -2562,7 +2561,7 @@ void job_start(job_t j) { - uint64_t td, tnow = mach_absolute_time(); + uint64_t td, tnow = runtime_get_opaque_time(); int spair[2]; int execspair[2]; int oepair[2]; @@ -2584,10 +2583,10 @@ /* * Some users adjust the wall-clock and then expect software to not notice. - * Therefore, launchd must use an absolute clock instead of gettimeofday() - * or time() wherever possible. + * Therefore, launchd must use an absolute clock instead of the wall clock + * wherever possible. */ - td = (tnow - j->start_time) * tbi.numer / tbi.denom; + td = runtime_opaque_time_to_nano(tnow - j->start_time); td /= NSEC_PER_SEC; if (j->start_time && (td < j->min_run_time) && !j->legacy_mach_job && !j->inetcompat) { @@ -6737,13 +6736,6 @@ } void -do_file_init(void) -{ - launchd_assert(mach_timebase_info(&tbi) == 0); - -} - -void do_unmounts(void) { struct statfs buf[250]; Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-12-19 18:13:19 UTC (rev 23470) +++ trunk/launchd/src/launchd_runtime.c 2007-12-19 19:48:57 UTC (rev 23471) @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -109,6 +110,8 @@ static bool logmsg_add(struct runtime_syslog_attr *attr, int err_num, const char *msg); static void logmsg_remove(struct logmsg_s *lm); +static void do_file_init(void) __attribute__((constructor)); +static mach_timebase_info_data_t tbi; static const int sigigns[] = { SIGHUP, SIGINT, SIGPIPE, SIGALRM, SIGTERM, SIGURG, SIGTSTP, SIGTSTP, SIGCONT, SIGTTIN, SIGTTOU, SIGIO, SIGXCPU, @@ -1209,7 +1212,7 @@ data_off = lm->data; - launchd_assumes(gettimeofday(&lm->when, NULL) != -1); + lm->when = runtime_get_wall_time(); lm->from_pid = attr->from_pid; lm->about_pid = attr->about_pid; lm->err_num = err_num; @@ -1307,8 +1310,7 @@ runtime_log_push(void) { static pthread_mutex_t ourlock = PTHREAD_MUTEX_INITIALIZER; - static struct timeval shutdown_start; - struct timeval tvd; + static int64_t shutdown_start, log_delta; mach_msg_type_number_t outvalCnt; struct logmsg_s *lm; vm_offset_t outval; @@ -1329,8 +1331,8 @@ return; } - if (shutdown_start.tv_sec == 0) { - gettimeofday(&shutdown_start, NULL); + if (shutdown_start == 0) { + shutdown_start = runtime_get_wall_time(); launchd_log_vm_stats(); } @@ -1349,15 +1351,9 @@ } while ((lm = STAILQ_FIRST(&logmsg_queue))) { - timersub(&lm->when, &shutdown_start, &tvd); + log_delta = lm->when - shutdown_start; - /* don't ask */ - if (tvd.tv_sec < 0) { - tvd.tv_sec = 0; - tvd.tv_usec = 0; - } - - fprintf(ourlogfile, "%3ld.%06d%6u %-40s%6u %-40s %s\n", tvd.tv_sec, tvd.tv_usec, + fprintf(ourlogfile, "%8lld%6u %-40s%6u %-40s %s\n", log_delta, lm->from_pid, lm->from_name, lm->about_pid, lm->about_name, lm->msg); logmsg_remove(lm); @@ -1550,3 +1546,55 @@ return (apple_internal_logging == 0); } + +int64_t +runtime_get_wall_time(void) +{ + struct timeval tv; + int64_t r; + + launchd_assumes(gettimeofday(&tv, NULL) != -1); + + r = tv.tv_sec; + r *= USEC_PER_SEC; + r += tv.tv_usec; + + return r; +} + +uint64_t +runtime_get_opaque_time(void) +{ + return mach_absolute_time(); +} + +uint64_t +runtime_opaque_time_to_nano(uint64_t o) +{ +#if defined(__i386__) + if (unlikely(tbi.numer != tbi.denom)) { +#elif defined(__ppc__) + if (likely(tbi.numer != tbi.denom)) { +#else + if (tbi.numer != tbi.denom) { +#endif + if (o < INT32_MAX) { + o *= tbi.numer; + o /= tbi.denom; + } else { + double d = o; + d *= tbi.numer; + d /= tbi.denom; + o = d; + } + } + + return o; +} + +void +do_file_init(void) +{ + launchd_assert(mach_timebase_info(&tbi) == 0); +} + Modified: trunk/launchd/src/launchd_runtime.h =================================================================== --- trunk/launchd/src/launchd_runtime.h 2007-12-19 18:13:19 UTC (rev 23470) +++ trunk/launchd/src/launchd_runtime.h 2007-12-19 19:48:57 UTC (rev 23471) @@ -70,6 +70,8 @@ #endif +#define likely(x) __builtin_expect((bool)(x), true) +#define unlikely(x) __builtin_expect((bool)(x), false) struct ldcred { uid_t euid; @@ -151,7 +153,11 @@ void runtime_vsyslog(struct runtime_syslog_attr *attr, const char *message, va_list args) __attribute__((format(printf, 2, 0))); void runtime_log_push(void); +int64_t runtime_get_wall_time(void); +uint64_t runtime_get_opaque_time(void); +uint64_t runtime_opaque_time_to_nano(uint64_t o); + kern_return_t launchd_set_bport(mach_port_t name); kern_return_t launchd_get_bport(mach_port_t *name); kern_return_t launchd_mport_notify_req(mach_port_t name, mach_msg_id_t which); Modified: trunk/launchd/src/libvproc_internal.h =================================================================== --- trunk/launchd/src/libvproc_internal.h 2007-12-19 18:13:19 UTC (rev 23470) +++ trunk/launchd/src/libvproc_internal.h 2007-12-19 19:48:57 UTC (rev 23471) @@ -59,7 +59,7 @@ struct logmsg_s { STAILQ_ENTRY(logmsg_s) sqe; - struct timeval when; + int64_t when; pid_t from_pid; pid_t about_pid; uid_t sender_uid; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071219/50066de9/attachment.html From source_changes at macosforge.org Wed Dec 19 14:29:17 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Wed Dec 19 14:29:54 2007 Subject: [launchd-changes] [23472] trunk/launchd/src/launchd_runtime.c Message-ID: <20071219222917.0851441A399@beta.macosforge.org> Revision: 23472 http://trac.macosforge.org/projects/launchd/changeset/23472 Author: zarzycki@apple.com Date: 2007-12-19 14:29:16 -0800 (Wed, 19 Dec 2007) Log Message: ----------- Small optimization. Modified Paths: -------------- trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-12-19 19:48:57 UTC (rev 23471) +++ trunk/launchd/src/launchd_runtime.c 2007-12-19 22:29:16 UTC (rev 23472) @@ -112,6 +112,7 @@ static void do_file_init(void) __attribute__((constructor)); static mach_timebase_info_data_t tbi; +static double tbi_float_val; static const int sigigns[] = { SIGHUP, SIGINT, SIGPIPE, SIGALRM, SIGTERM, SIGURG, SIGTSTP, SIGTSTP, SIGCONT, SIGTTIN, SIGTTOU, SIGIO, SIGXCPU, @@ -1583,8 +1584,7 @@ o /= tbi.denom; } else { double d = o; - d *= tbi.numer; - d /= tbi.denom; + d *= tbi_float_val; o = d; } } @@ -1596,5 +1596,7 @@ do_file_init(void) { launchd_assert(mach_timebase_info(&tbi) == 0); + tbi_float_val = tbi.numer; + tbi_float_val /= tbi.denom; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071219/58222910/attachment-0001.html From source_changes at macosforge.org Wed Dec 19 16:43:47 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Wed Dec 19 16:44:23 2007 Subject: [launchd-changes] [23473] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071220004347.283D941E8F7@beta.macosforge.org> Revision: 23473 http://trac.macosforge.org/projects/launchd/changeset/23473 Author: zarzycki@apple.com Date: 2007-12-19 16:43:45 -0800 (Wed, 19 Dec 2007) Log Message: ----------- Misc. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-19 22:29:16 UTC (rev 23472) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-20 00:43:45 UTC (rev 23473) @@ -1069,6 +1069,7 @@ if (len != sizeof(kp)) { jobmgr_log(jm, LOG_DEBUG, "Tried to create an anonymous job for nonexistent PID: %u", anonpid); + errno = ESRCH; return NULL; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071219/7ad8bfb9/attachment.html From source_changes at macosforge.org Fri Dec 21 13:06:38 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Fri Dec 21 13:07:06 2007 Subject: [launchd-changes] [23474] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071221210638.AE480464A69@beta.macosforge.org> Revision: 23474 http://trac.macosforge.org/projects/launchd/changeset/23474 Author: zarzycki@apple.com Date: 2007-12-21 13:06:36 -0800 (Fri, 21 Dec 2007) Log Message: ----------- Bug: launchd_core_logic.c:6375 (23433):0: (target_j = jobmgr_find_by_pid(j->mgr, target_pid, true)) != NULL Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-20 00:43:45 UTC (rev 23473) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-21 21:06:36 UTC (rev 23474) @@ -405,9 +405,9 @@ static void job_callback_read(job_t j, int ident); static void job_log_stray_pg(job_t j); static void job_log_chidren_without_exec(job_t j); -static job_t job_new_anonymous(jobmgr_t jm, pid_t anonpid); -static job_t job_new(jobmgr_t jm, const char *label, const char *prog, const char *const *argv); -static job_t job_new_via_mach_init(job_t j, const char *cmd, uid_t uid, bool ond); +static job_t job_new_anonymous(jobmgr_t jm, pid_t anonpid) __attribute__((malloc, nonnull, warn_unused_result)); +static job_t job_new(jobmgr_t jm, const char *label, const char *prog, const char *const *argv) __attribute__((malloc, nonnull(1,2), warn_unused_result)); +static job_t job_new_via_mach_init(job_t j, const char *cmd, uid_t uid, bool ond) __attribute__((malloc, nonnull, warn_unused_result)); static const char *job_prog(job_t j); static jobmgr_t job_get_bs(job_t j); static void job_kill(job_t j); @@ -1055,11 +1055,13 @@ gid_t kp_egid, kp_gid, kp_svgid; if (!jobmgr_assumes(jm, anonpid != 0)) { + errno = EINVAL; return NULL; } if (!jobmgr_assumes(jm, anonpid < 100000)) { /* The kernel current defines PID_MAX to be 99999, but that define isn't exported */ + errno = EINVAL; return NULL; } @@ -1074,6 +1076,7 @@ } if (!jobmgr_assumes(jm, kp.kp_proc.p_comm[0] != '\0')) { + errno = EINVAL; return NULL; } @@ -6502,6 +6505,15 @@ return BOOTSTRAP_NO_MEMORY; } + 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); + } + return BOOTSTRAP_NO_MEMORY; + } + 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/20071221/263075ab/attachment.html From source_changes at macosforge.org Fri Dec 21 13:37:18 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Fri Dec 21 13:37:47 2007 Subject: [launchd-changes] [23475] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071221213718.1740F465B5F@beta.macosforge.org> Revision: 23475 http://trac.macosforge.org/projects/launchd/changeset/23475 Author: zarzycki@apple.com Date: 2007-12-21 13:37:17 -0800 (Fri, 21 Dec 2007) Log Message: ----------- Added likely() / unlikely() usage. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-21 21:06:36 UTC (rev 23474) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-21 21:37:17 UTC (rev 23475) @@ -582,7 +582,7 @@ if (j->stderrpath && (tmp = launch_data_new_string(j->stderrpath))) { launch_data_dict_insert(r, tmp, LAUNCH_JOBKEY_STANDARDERRORPATH); } - if (j->argv && (tmp = launch_data_alloc(LAUNCH_DATA_ARRAY))) { + if (likely(j->argv) && (tmp = launch_data_alloc(LAUNCH_DATA_ARRAY))) { int i; for (i = 0; i < j->argc; i++) { @@ -857,7 +857,7 @@ if (j->prog) { free(j->prog); } - if (j->argv) { + if (likely(j->argv)) { free(j->argv); } if (j->rootdir) { @@ -1080,7 +1080,7 @@ return NULL; } - if (kp.kp_proc.p_stat == SZOMB) { + if (unlikely(kp.kp_proc.p_stat == SZOMB)) { jobmgr_log(jm, LOG_DEBUG, "Tried to create an anonymous job for zombie PID %u: %s", anonpid, kp.kp_proc.p_comm); } @@ -1136,7 +1136,7 @@ /* anonymous process reaping is messy */ LIST_INSERT_HEAD(&jm->active_jobs[ACTIVE_JOB_HASH(jr->p)], jr, pid_hash_sle); - if (kevent_mod(jr->p, EVFILT_PROC, EV_ADD, proc_fflags, 0, root_jobmgr) == -1 && job_assumes(jr, errno == ESRCH)) { + if (unlikely(kevent_mod(jr->p, EVFILT_PROC, EV_ADD, proc_fflags, 0, root_jobmgr) == -1) && job_assumes(jr, errno == ESRCH)) { /* zombies are weird */ job_log(jr, LOG_ERR, "Failed to add kevent for PID %u. Will unload at MIG return", jr->p); jr->unload_at_mig_return = true; @@ -1173,12 +1173,12 @@ launchd_assert(offsetof(struct job_s, kqjob_callback) == 0); - if (jm->shutting_down) { + if (unlikely(jm->shutting_down)) { errno = EINVAL; return NULL; } - if (prog == NULL && argv == NULL) { + if (unlikely(prog == NULL && argv == NULL)) { errno = EINVAL; return NULL; } @@ -1220,9 +1220,10 @@ } } - if (argv) { - while (*argv_tmp++) + if (likely(argv)) { + while (*argv_tmp++) { j->argc++; + } for (i = 0; i < j->argc; i++) { cc += strlen(argv[i]) + 1; @@ -1522,9 +1523,9 @@ case 'e': case 'E': if (strcasecmp(key, LAUNCH_JOBKEY_EXITTIMEOUT) == 0) { - if (value < 0) { + if (unlikely(value < 0)) { job_log(j, LOG_WARNING, "%s less than zero. Ignoring.", LAUNCH_JOBKEY_EXITTIMEOUT); - } else if (value > UINT32_MAX) { + } else if (unlikely(value > UINT32_MAX)) { job_log(j, LOG_WARNING, "%s is too large. Ignoring.", LAUNCH_JOBKEY_EXITTIMEOUT); } else { j->exit_timeout = value; @@ -1541,9 +1542,9 @@ case 't': case 'T': if (strcasecmp(key, LAUNCH_JOBKEY_TIMEOUT) == 0) { - if (value < 0) { + if (unlikely(value < 0)) { job_log(j, LOG_WARNING, "%s less than zero. Ignoring.", LAUNCH_JOBKEY_TIMEOUT); - } else if (value > UINT32_MAX) { + } else if (unlikely(value > UINT32_MAX)) { job_log(j, LOG_WARNING, "%s is too large. Ignoring.", LAUNCH_JOBKEY_TIMEOUT); } else { j->timeout = value; @@ -1568,9 +1569,9 @@ case 's': case 'S': if (strcasecmp(key, LAUNCH_JOBKEY_STARTINTERVAL) == 0) { - if (value <= 0) { + if (unlikely(value <= 0)) { job_log(j, LOG_WARNING, "%s is not greater than zero. Ignoring.", LAUNCH_JOBKEY_STARTINTERVAL); - } else if (value > UINT32_MAX) { + } else if (unlikely(value > UINT32_MAX)) { job_log(j, LOG_WARNING, "%s is too large. Ignoring.", LAUNCH_JOBKEY_STARTINTERVAL); } else { runtime_add_ref(); @@ -1759,7 +1760,7 @@ job_t j = context; launch_data_type_t kind; - if (obj == NULL) { + if (!launchd_assumes(obj != NULL)) { return; } @@ -1798,7 +1799,7 @@ const char **argv = NULL; job_t j; - if (pload == NULL) { + if (!launchd_assumes(pload != NULL)) { errno = EINVAL; return NULL; } @@ -1854,7 +1855,7 @@ argv[i] = NULL; } - if ((j = job_find(label)) != NULL) { + if (unlikely((j = job_find(label)) != NULL)) { errno = EEXIST; return NULL; } else if (label[0] == '\0' || (strncasecmp(label, "", strlen("com.apple.launchd")) == 0) || @@ -2756,7 +2757,7 @@ } g.gl_pathv[0] = (char *)file2exec; argv = (const char **)g.gl_pathv; - } else if (j->argv) { + } else if (likely(j->argv)) { argv = alloca((j->argc + 2) * sizeof(char *)); argv[0] = file2exec; for (i = 0; i < j->argc; i++) { @@ -3998,7 +3999,7 @@ { if (j->prog) { return j->prog; - } else if (j->argv) { + } else if (likely(j->argv)) { return j->argv[0]; } else { return ""; -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071221/2b0d92ae/attachment-0001.html From source_changes at macosforge.org Fri Dec 21 13:53:38 2007 From: source_changes at macosforge.org (source_changes@macosforge.org) Date: Fri Dec 21 13:54:05 2007 Subject: [launchd-changes] [23476] trunk/launchd/src/launchd_core_logic.c Message-ID: <20071221215338.71B0E4662A3@beta.macosforge.org> Revision: 23476 http://trac.macosforge.org/projects/launchd/changeset/23476 Author: zarzycki@apple.com Date: 2007-12-21 13:53:37 -0800 (Fri, 21 Dec 2007) Log Message: ----------- Bug: launchd_core_logic.c:5810 (23281):0: mspolicy_new(target_j, target_service, flags & BOOTSTRAP_ALLOW_LOOKUP, flags & BOOTSTRAP_PER_PID_SERVICE, false) Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-12-21 21:37:17 UTC (rev 23475) +++ trunk/launchd/src/launchd_core_logic.c 2007-12-21 21:53:37 UTC (rev 23476) @@ -6522,7 +6522,11 @@ if (SLIST_EMPTY(&j->mspolicies)) { job_log(j, LOG_DEBUG, "Setting policy on job \"%s\" for Mach service: %s", target_j->label, target_service); if (target_service[0]) { - job_assumes(j, mspolicy_new(target_j, target_service, flags & BOOTSTRAP_ALLOW_LOOKUP, flags & BOOTSTRAP_PER_PID_SERVICE, false)); + bool r = mspolicy_new(target_j, target_service, flags & BOOTSTRAP_ALLOW_LOOKUP, flags & BOOTSTRAP_PER_PID_SERVICE, false); + + if (unlikely(!r) && job_assumes(j, errno == EEXIST)) { + job_log(j, LOG_ERR, "Tried to update a known policy on PID %u: %s", target_pid, target_service); + } } else { target_j->deny_unknown_mslookups = !(flags & BOOTSTRAP_ALLOW_LOOKUP); } @@ -6668,6 +6672,7 @@ if (msp->per_pid != pid_local) { continue; } else if (strcmp(msp->name, name) == 0) { + errno = EEXIST; return false; } } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.macosforge.org/pipermail/launchd-changes/attachments/20071221/81874453/attachment.html