[launchd-changes] [23828] branches/PR-6609410/launchd/src
source_changes at macosforge.org
source_changes at macosforge.org
Mon Feb 23 13:07:49 PST 2009
Revision: 23828
http://trac.macosforge.org/projects/launchd/changeset/23828
Author: dsorresso at apple.com
Date: 2009-02-23 13:07:49 -0800 (Mon, 23 Feb 2009)
Log Message:
-----------
Now giving clean jobs that were SIGKILLed 1 second to exit before advancing state of shutdown.
Modified Paths:
--------------
branches/PR-6609410/launchd/src/launchd.c
branches/PR-6609410/launchd/src/launchd_core_logic.c
branches/PR-6609410/launchd/src/launchd_runtime.c
branches/PR-6609410/launchd/src/launchd_runtime.h
Modified: branches/PR-6609410/launchd/src/launchd.c
===================================================================
--- branches/PR-6609410/launchd/src/launchd.c 2009-02-23 21:04:45 UTC (rev 23827)
+++ branches/PR-6609410/launchd/src/launchd.c 2009-02-23 21:07:49 UTC (rev 23828)
@@ -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: branches/PR-6609410/launchd/src/launchd_core_logic.c
===================================================================
--- branches/PR-6609410/launchd/src/launchd_core_logic.c 2009-02-23 21:04:45 UTC (rev 23827)
+++ branches/PR-6609410/launchd/src/launchd_core_logic.c 2009-02-23 21:07:49 UTC (rev 23828)
@@ -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: branches/PR-6609410/launchd/src/launchd_runtime.c
===================================================================
--- branches/PR-6609410/launchd/src/launchd_runtime.c 2009-02-23 21:04:45 UTC (rev 23827)
+++ branches/PR-6609410/launchd/src/launchd_runtime.c 2009-02-23 21:07:49 UTC (rev 23828)
@@ -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: branches/PR-6609410/launchd/src/launchd_runtime.h
===================================================================
--- branches/PR-6609410/launchd/src/launchd_runtime.h 2009-02-23 21:04:45 UTC (rev 23827)
+++ branches/PR-6609410/launchd/src/launchd_runtime.h 2009-02-23 21:07:49 UTC (rev 23828)
@@ -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);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/launchd-changes/attachments/20090223/ae9dec4f/attachment-0001.html>
More information about the launchd-changes
mailing list