[launchd-changes] [23829] trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 24 19:16:41 PST 2009


Revision: 23829
          http://trac.macosforge.org/projects/launchd/changeset/23829
Author:   dsorresso at apple.com
Date:     2009-02-24 19:16:40 -0800 (Tue, 24 Feb 2009)
Log Message:
-----------
<rdar://problem/6609410> 10A278: per-user launchd of logged-out user still around with lots of zombies

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

Property Changed:
----------------
    trunk/
    trunk/launchd/src/bootstrap.h
    trunk/launchd/src/bootstrap_priv.h
    trunk/launchd/src/launch.h
    trunk/launchd/src/launch_internal.h
    trunk/launchd/src/launch_priv.h
    trunk/launchd/src/protocol_vproc.defs
    trunk/launchd/src/vproc.h
    trunk/launchd/src/vproc_internal.h
    trunk/launchd/src/vproc_priv.h


Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/PR-5092682:23731-23742
/branches/PR-5898404:23681-23700
/branches/PR-5978442:23651-23701
/branches/PR-6132016:23719-23738
/branches/PR-6271234:23818-23822
/branches/PR-6562592:23812-23822
/branches/PR-6589133:23810-23822
   + /branches/PR-5092682:23731-23742
/branches/PR-5898404:23681-23700
/branches/PR-5978442:23651-23701
/branches/PR-6132016:23719-23738
/branches/PR-6271234:23818-23822
/branches/PR-6562592:23812-23822
/branches/PR-6589133:23810-23822
/branches/PR-6609410:23828


Property changes on: trunk/launchd/src/bootstrap.h
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/PR-5898404/launchd/src/libbootstrap_public.h:23681-23700
/branches/PR-5978442/launchd/src/libbootstrap_public.h:23651-23701
/branches/PR-6271234/launchd/src/bootstrap.h:23818-23822
/branches/PR-6562592/launchd/src/bootstrap.h:23812-23822
/branches/PR-6589133/launchd/src/bootstrap.h:23810-23822
   + /branches/PR-5898404/launchd/src/libbootstrap_public.h:23681-23700
/branches/PR-5978442/launchd/src/libbootstrap_public.h:23651-23701
/branches/PR-6271234/launchd/src/bootstrap.h:23818-23822
/branches/PR-6562592/launchd/src/bootstrap.h:23812-23822
/branches/PR-6589133/launchd/src/bootstrap.h:23810-23822
/branches/PR-6609410/launchd/src/bootstrap.h:23828


Property changes on: trunk/launchd/src/bootstrap_priv.h
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/PR-5898404/launchd/src/libbootstrap_private.h:23681-23700
/branches/PR-5978442/launchd/src/libbootstrap_private.h:23651-23701
/branches/PR-6271234/launchd/src/bootstrap_priv.h:23818-23822
/branches/PR-6562592/launchd/src/bootstrap_priv.h:23812-23822
/branches/PR-6589133/launchd/src/bootstrap_priv.h:23810-23822
   + /branches/PR-5898404/launchd/src/libbootstrap_private.h:23681-23700
/branches/PR-5978442/launchd/src/libbootstrap_private.h:23651-23701
/branches/PR-6271234/launchd/src/bootstrap_priv.h:23818-23822
/branches/PR-6562592/launchd/src/bootstrap_priv.h:23812-23822
/branches/PR-6589133/launchd/src/bootstrap_priv.h:23810-23822
/branches/PR-6609410/launchd/src/bootstrap_priv.h:23828


Property changes on: trunk/launchd/src/launch.h
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/PR-5898404/launchd/src/liblaunch_public.h:23681-23700
/branches/PR-5978442/launchd/src/liblaunch_public.h:23651-23701
/branches/PR-6271234/launchd/src/launch.h:23818-23822
/branches/PR-6562592/launchd/src/launch.h:23812-23822
/branches/PR-6589133/launchd/src/launch.h:23810-23822
   + /branches/PR-5898404/launchd/src/liblaunch_public.h:23681-23700
/branches/PR-5978442/launchd/src/liblaunch_public.h:23651-23701
/branches/PR-6271234/launchd/src/launch.h:23818-23822
/branches/PR-6562592/launchd/src/launch.h:23812-23822
/branches/PR-6589133/launchd/src/launch.h:23810-23822
/branches/PR-6609410/launchd/src/launch.h:23828


Property changes on: trunk/launchd/src/launch_internal.h
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/PR-5898404/launchd/src/liblaunch_internal.h:23681-23700
/branches/PR-5978442/launchd/src/liblaunch_internal.h:23651-23701
/branches/PR-6271234/launchd/src/launch_internal.h:23818-23822
/branches/PR-6562592/launchd/src/launch_internal.h:23812-23822
/branches/PR-6589133/launchd/src/launch_internal.h:23810-23822
   + /branches/PR-5898404/launchd/src/liblaunch_internal.h:23681-23700
/branches/PR-5978442/launchd/src/liblaunch_internal.h:23651-23701
/branches/PR-6271234/launchd/src/launch_internal.h:23818-23822
/branches/PR-6562592/launchd/src/launch_internal.h:23812-23822
/branches/PR-6589133/launchd/src/launch_internal.h:23810-23822
/branches/PR-6609410/launchd/src/launch_internal.h:23828


Property changes on: trunk/launchd/src/launch_priv.h
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/PR-5898404/launchd/src/liblaunch_private.h:23681-23700
/branches/PR-5978442/launchd/src/liblaunch_private.h:23651-23701
/branches/PR-6271234/launchd/src/launch_priv.h:23818-23822
/branches/PR-6562592/launchd/src/launch_priv.h:23812-23822
/branches/PR-6589133/launchd/src/launch_priv.h:23810-23822
   + /branches/PR-5898404/launchd/src/liblaunch_private.h:23681-23700
/branches/PR-5978442/launchd/src/liblaunch_private.h:23651-23701
/branches/PR-6271234/launchd/src/launch_priv.h:23818-23822
/branches/PR-6562592/launchd/src/launch_priv.h:23812-23822
/branches/PR-6589133/launchd/src/launch_priv.h:23810-23822
/branches/PR-6609410/launchd/src/launch_priv.h:23828

Modified: trunk/launchd/src/launchd.c
===================================================================
--- trunk/launchd/src/launchd.c	2009-02-23 21:07:49 UTC (rev 23828)
+++ trunk/launchd/src/launchd.c	2009-02-25 03:16:40 UTC (rev 23829)
@@ -429,7 +429,7 @@
 
 	shutdown_in_progress = true;
 
-	if (pid1_magic) {
+	if( pid1_magic || g_log_per_user_shutdown ) {
 		/*
 		 * When this changes to a more sustainable API, update this:
 		 * http://howto.apple.com/db.cgi?Debugging_Apps_Non-Responsive_At_Shutdown

Modified: trunk/launchd/src/launchd_core_logic.c
===================================================================
--- trunk/launchd/src/launchd_core_logic.c	2009-02-23 21:07:49 UTC (rev 23828)
+++ trunk/launchd/src/launchd_core_logic.c	2009-02-25 03:16:40 UTC (rev 23829)
@@ -126,9 +126,10 @@
  *   it a SIGTERM, SIGKILL it. Can be overriden in the job plist.
  */
 #define LAUNCHD_MIN_JOB_RUN_TIME		10
-#define LAUNCHD_SAMPLE_TIMEOUT			1
+#define LAUNCHD_SAMPLE_TIMEOUT			2
 #define LAUNCHD_DEFAULT_EXIT_TIMEOUT	20
 #define LAUNCHD_SIGKILL_TIMER			5
+#define LAUNCHD_CLEAN_KILL_TIMER		1
 #define LAUNCHD_JETSAM_PRIORITY_UNSET	0xdead1eebabell
 
 #define SHUTDOWN_LOG_DIR "/var/log/shutdown"
@@ -522,6 +523,7 @@
 			needs_kickoff				:1, /* The job is to be kept alive continuously, but it must be initially kicked off. */
 			is_bootstrapper				:1, /* The job is a bootstrapper. */
 			has_console					:1, /* The job owns the console. */
+			clean_exit_timer_expired	:1, /* The job was clean, received SIGKILL and failed to exit after LAUNCHD_CLEAN_KILL_TIMER seconds. */
 			migratory					:1; /* The (anonymous) job called vprocmgr_switch_to_session(). */
 	mode_t mask;
 	pid_t tracing_pid;
@@ -2996,8 +2998,8 @@
 
 	j->sent_sigkill = true;
 
-	job_assumes(j, kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER,
-				EV_ADD, NOTE_SECONDS, LAUNCHD_SIGKILL_TIMER, j) != -1);
+	intptr_t timer = j->clean_kill ? LAUNCHD_CLEAN_KILL_TIMER : LAUNCHD_SIGKILL_TIMER;
+	job_assumes(j, kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, EV_ADD, NOTE_SECONDS, timer, j) != -1);
 
 	job_log(j, LOG_DEBUG, "Sent SIGKILL signal");
 }
@@ -3212,6 +3214,16 @@
 		if( !job_assumes(j, j->p != 0) ) {
 			return;
 		}
+		
+		if( j->clean_kill ) {
+			job_log(j, LOG_DEBUG | LOG_CONSOLE, "Clean job failed to exit %u seconds after receiving SIGKILL.", LAUNCHD_CLEAN_KILL_TIMER);
+			job_assumes(j, kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, EV_DELETE, 0, 0, NULL));
+			j->clean_exit_timer_expired = true;
+			
+			jobmgr_do_garbage_collection(j->mgr);
+			return;
+		}
+		
 		/*
 		 * This block might be executed up to 3 times for a given (slow) job
 		 *  - once for the SAMPLE_TIMEOUT timer, at which point sampling is triggered
@@ -5399,11 +5411,14 @@
 			/* If the job is active and we haven't told it to stop yet, stop it. */
 			job_stop(ji);
 			
-			/* We may have sent SIGKILL to the job in job_stop(). In this case,
-			 * "clean" jobs should exit immediately, so we shouldn't have to wait
-			 * for them.
+			/* We may have sent SIGKILL to the job in job_stop(). Clean jobs
+			 * get 1 second to exit.
 			 */
-			unkilled_cnt += !ji->sent_sigkill ? 1 : 0;
+			if( !ji->clean_kill ) {
+				unkilled_cnt += !ji->sent_sigkill ? 1 : 0;
+			} else {
+				unkilled_cnt += ji->clean_exit_timer_expired ? 1 : 0;
+			}
 		} else if( ji->stopped ) {
 			/* If the job is active and has been told to stop, disregard it
 			 * after we've sent SIGKILL.
@@ -5456,11 +5471,14 @@
 			/* If the job is active and we haven't told it to stop yet, stop it. */
 			job_stop(ji);
 			
-			/* We may have sent SIGKILL to the job in job_stop(). In this case,
-			 * "clean" jobs should exit immediately, so we shouldn't have to wait
-			 * for them.
+			/* We may have sent SIGKILL to the job in job_stop(). Clean jobs
+			 * get 1 second to exit.
 			 */
-			unkilled_cnt += !ji->sent_sigkill ? 1 : 0;
+			if( !ji->clean_kill ) {
+				unkilled_cnt += !ji->sent_sigkill ? 1 : 0;
+			} else {
+				unkilled_cnt += ji->clean_exit_timer_expired ? 1 : 0;
+			}
 		} else if( ji->stopped ) {
 			/* If the job is active and has been told to stop, disregard it
 			 * after we've sent SIGKILL.
@@ -5515,11 +5533,14 @@
 			/* If the job is active and we haven't told it to stop yet, stop it. */
 			job_stop(ji);
 			
-			/* We may have sent SIGKILL to the job in job_stop(). In this case,
-			 * "clean" jobs should exit immediately, so we shouldn't have to wait
-			 * for them.
+			/* We may have sent SIGKILL to the job in job_stop(). Clean jobs
+			 * get 1 second to exit.
 			 */
-			unkilled_cnt += !ji->sent_sigkill ? 1 : 0;
+			if( !ji->clean_kill ) {
+				unkilled_cnt += !ji->sent_sigkill ? 1 : 0;
+			} else {
+				unkilled_cnt += ji->clean_exit_timer_expired ? 1 : 0;
+			}
 		} else if( ji->stopped ) {
 			/* If the job is active and has been told to stop, disregard it
 			 * after we've sent SIGKILL.
@@ -5558,7 +5579,7 @@
 	}
 	
 	if( !_jm && SLIST_EMPTY(&jm->submgrs) ) {
-		jobmgr_log(jm, LOG_NOTICE | LOG_CONSOLE, "Removing.");
+		jobmgr_log(jm, LOG_DEBUG | LOG_CONSOLE, "Removing.");
 		jobmgr_log_stray_children(jm, false);
 		jobmgr_remove(jm);
 	} else {

Modified: trunk/launchd/src/launchd_runtime.c
===================================================================
--- trunk/launchd/src/launchd_runtime.c	2009-02-23 21:07:49 UTC (rev 23828)
+++ trunk/launchd/src/launchd_runtime.c	2009-02-25 03:16:40 UTC (rev 23829)
@@ -133,6 +133,7 @@
 bool g_flat_mach_namespace = true;
 bool g_simulate_pid1_crash = false;
 bool g_use_gmalloc = false;
+bool g_log_per_user_shutdown = false;
 pid_t g_wsp = 0;
 
 mach_port_t
@@ -1344,8 +1345,7 @@
 
 	offset = (void *)*outval;
 
-#if 0
-	if( !ourlogfile && !pid1_magic && shutdown_in_progress ) {
+	if( g_log_per_user_shutdown && !ourlogfile && !pid1_magic && shutdown_in_progress ) {
 		char logfile[NAME_MAX];
 		snprintf(logfile, sizeof(logfile), "/var/tmp/launchd-%s.shutdown.log", g_username);
 		
@@ -1355,7 +1355,6 @@
 		rename(logfile, logfile1);
 		ourlogfile = fopen(logfile, "a");
 	}
-#endif
 
 	static int64_t shutdown_start = 0;
 	if( shutdown_start == 0 ) {
@@ -1795,6 +1794,10 @@
 		g_force_old_kill_path = true;
 	}
 	
+	if( stat("/var/db/.launchd_log_per_user_shutdown", &sb) == 0 ) {
+		g_log_per_user_shutdown = true;
+	}
+	
 	if( !pid1_magic && stat("/var/db/.launchd_no_flat_per_user_namespace", &sb) == 0 ) {
 		g_flat_mach_namespace = false;
 	}

Modified: trunk/launchd/src/launchd_runtime.h
===================================================================
--- trunk/launchd/src/launchd_runtime.h	2009-02-23 21:07:49 UTC (rev 23828)
+++ trunk/launchd/src/launchd_runtime.h	2009-02-25 03:16:40 UTC (rev 23829)
@@ -103,6 +103,7 @@
 extern char g_username[128];
 extern bool g_shutdown_debugging;
 extern bool g_use_gmalloc;
+extern bool g_log_per_user_shutdown;
 extern pid_t g_wsp;
 
 mach_port_t runtime_get_kernel_port(void);


Property changes on: trunk/launchd/src/protocol_vproc.defs
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/PR-5092682/launchd/src/protocol_job.defs:23731-23742
/branches/PR-5898404/launchd/src/protocol_job.defs:23681-23700
/branches/PR-5978442/launchd/src/protocol_job.defs:23651-23701
/branches/PR-6132016/launchd/src/protocol_job.defs:23719-23738
/branches/PR-6271234/launchd/src/protocol_vproc.defs:23818-23822
/branches/PR-6562592/launchd/src/protocol_vproc.defs:23812-23822
/branches/PR-6589133/launchd/src/protocol_vproc.defs:23810-23822
   + /branches/PR-5092682/launchd/src/protocol_job.defs:23731-23742
/branches/PR-5898404/launchd/src/protocol_job.defs:23681-23700
/branches/PR-5978442/launchd/src/protocol_job.defs:23651-23701
/branches/PR-6132016/launchd/src/protocol_job.defs:23719-23738
/branches/PR-6271234/launchd/src/protocol_vproc.defs:23818-23822
/branches/PR-6562592/launchd/src/protocol_vproc.defs:23812-23822
/branches/PR-6589133/launchd/src/protocol_vproc.defs:23810-23822
/branches/PR-6609410/launchd/src/protocol_vproc.defs:23828


Property changes on: trunk/launchd/src/vproc.h
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/PR-5092682/launchd/src/libvproc_public.h:23731-23742
/branches/PR-5898404/launchd/src/libvproc_public.h:23681-23700
/branches/PR-5978442/launchd/src/libvproc_public.h:23651-23701
/branches/PR-6132016/launchd/src/libvproc_public.h:23719-23738
/branches/PR-6271234/launchd/src/vproc.h:23818-23822
/branches/PR-6562592/launchd/src/vproc.h:23812-23822
/branches/PR-6589133/launchd/src/vproc.h:23810-23822
   + /branches/PR-5092682/launchd/src/libvproc_public.h:23731-23742
/branches/PR-5898404/launchd/src/libvproc_public.h:23681-23700
/branches/PR-5978442/launchd/src/libvproc_public.h:23651-23701
/branches/PR-6132016/launchd/src/libvproc_public.h:23719-23738
/branches/PR-6271234/launchd/src/vproc.h:23818-23822
/branches/PR-6562592/launchd/src/vproc.h:23812-23822
/branches/PR-6589133/launchd/src/vproc.h:23810-23822
/branches/PR-6609410/launchd/src/vproc.h:23828


Property changes on: trunk/launchd/src/vproc_internal.h
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/PR-5898404/launchd/src/libvproc_internal.h:23681-23700
/branches/PR-5978442/launchd/src/libvproc_internal.h:23651-23701
/branches/PR-6271234/launchd/src/vproc_internal.h:23818-23822
/branches/PR-6562592/launchd/src/vproc_internal.h:23812-23822
/branches/PR-6589133/launchd/src/vproc_internal.h:23810-23822
   + /branches/PR-5898404/launchd/src/libvproc_internal.h:23681-23700
/branches/PR-5978442/launchd/src/libvproc_internal.h:23651-23701
/branches/PR-6271234/launchd/src/vproc_internal.h:23818-23822
/branches/PR-6562592/launchd/src/vproc_internal.h:23812-23822
/branches/PR-6589133/launchd/src/vproc_internal.h:23810-23822
/branches/PR-6609410/launchd/src/vproc_internal.h:23828


Property changes on: trunk/launchd/src/vproc_priv.h
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/PR-5092682/launchd/src/libvproc_private.h:23731-23742
/branches/PR-5898404/launchd/src/libvproc_private.h:23681-23700
/branches/PR-5978442/launchd/src/libvproc_private.h:23651-23701
/branches/PR-6132016/launchd/src/libvproc_private.h:23719-23738
/branches/PR-6271234/launchd/src/vproc_priv.h:23818-23822
/branches/PR-6562592/launchd/src/vproc_priv.h:23812-23822
/branches/PR-6589133/launchd/src/vproc_priv.h:23810-23822
   + /branches/PR-5092682/launchd/src/libvproc_private.h:23731-23742
/branches/PR-5898404/launchd/src/libvproc_private.h:23681-23700
/branches/PR-5978442/launchd/src/libvproc_private.h:23651-23701
/branches/PR-6132016/launchd/src/libvproc_private.h:23719-23738
/branches/PR-6271234/launchd/src/vproc_priv.h:23818-23822
/branches/PR-6562592/launchd/src/vproc_priv.h:23812-23822
/branches/PR-6589133/launchd/src/vproc_priv.h:23810-23822
/branches/PR-6609410/launchd/src/vproc_priv.h:23828
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/launchd-changes/attachments/20090224/456f0b8a/attachment-0001.html>


More information about the launchd-changes mailing list