Revision: 23409 http://trac.macosforge.org/projects/launchd/changeset/23409 Author: zarzycki@apple.com Date: 2007-09-19 09:05:30 -0700 (Wed, 19 Sep 2007) Log Message: ----------- More shutdown debug logging. Modified Paths: -------------- trunk/launchd/src/launchd_core_logic.c trunk/launchd/src/launchd_core_logic.h trunk/launchd/src/launchd_runtime.c Modified: trunk/launchd/src/launchd_core_logic.c =================================================================== --- trunk/launchd/src/launchd_core_logic.c 2007-09-19 01:00:28 UTC (rev 23408) +++ trunk/launchd/src/launchd_core_logic.c 2007-09-19 16:05:30 UTC (rev 23409) @@ -381,6 +381,7 @@ static void job_import_array(job_t j, const char *key, launch_data_t value); static void job_import_opaque(job_t j, const char *key, launch_data_t value); static bool job_set_global_on_demand(job_t j, bool val); +static const char *job_active(job_t j); static void job_watch(job_t j); static void job_ignore(job_t j); static void job_reap(job_t j); @@ -532,6 +533,8 @@ job_assumes(j, kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, EV_ADD|EV_ONESHOT, NOTE_SECONDS, j->exit_timeout, j) != -1); } + + job_log(j, LOG_DEBUG, "Sent SIGTERM signal."); } launch_data_t @@ -645,10 +648,31 @@ } static void +jobmgr_log_active_jobs(jobmgr_t jm) +{ + const char *why_active; + jobmgr_t jmi; + job_t ji; + + SLIST_FOREACH(jmi, &jm->submgrs, sle) { + jobmgr_log_active_jobs(jmi); + } + + LIST_FOREACH(ji, &jm->jobs, sle) { + why_active = job_active(ji); + + job_log(ji, LOG_DEBUG, "%s", why_active ? why_active : "Inactive"); + } + +} + +static void still_alive_with_check(void) { jobmgr_log(root_jobmgr, LOG_NOTICE, "Still alive with %lu children.", total_children); + jobmgr_log_active_jobs(root_jobmgr); + runtime_closelog(); /* hack to flush logs */ } @@ -675,7 +699,7 @@ } if (debug_shutdown_hangs && jm->parentmgr == NULL && getpid() == 1) { - runtime_set_timeout(still_alive_with_check, 3000); + runtime_set_timeout(still_alive_with_check, 5); } return jobmgr_do_garbage_collection(jm); @@ -2187,6 +2211,8 @@ job_assumes(j, kevent_mod((uintptr_t)&j->exit_timeout, EVFILT_TIMER, EV_ADD, NOTE_SECONDS, LAUNCHD_SIGKILL_TIMER, j) != -1); + + job_log(j, LOG_DEBUG, "Sent SIGKILL signal."); } void @@ -3773,30 +3799,30 @@ } } -bool +const char * job_active(job_t j) { struct machservice *ms; if (j->wait4pipe_eof && j->log_redirect_fd) { - return true; + return "Standard out/error is still valid"; } if (j->p) { - return true; + return "PID is still valid"; } if (j->priv_port_has_senders) { - return true; + return "Privileged Port still has outstanding senders"; } SLIST_FOREACH(ms, &j->machservices, sle) { if (ms->recv && ms->isActive) { - return true; + return "Mach service is still active"; } } - return false; + return NULL; } void Modified: trunk/launchd/src/launchd_core_logic.h =================================================================== --- trunk/launchd/src/launchd_core_logic.h 2007-09-19 01:00:28 UTC (rev 23408) +++ trunk/launchd/src/launchd_core_logic.h 2007-09-19 16:05:30 UTC (rev 23409) @@ -40,7 +40,6 @@ job_t job_find(const char *label); job_t job_find_by_service_port(mach_port_t p); bool job_ack_port_destruction(mach_port_t p); -bool job_active(job_t j); bool job_is_anonymous(job_t j); launch_data_t job_export(job_t j); void job_stop(job_t j); Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-09-19 01:00:28 UTC (rev 23408) +++ trunk/launchd/src/launchd_runtime.c 2007-09-19 16:05:30 UTC (rev 23409) @@ -90,8 +90,8 @@ static mach_msg_size_t max_msg_size; static mig_callback *mig_cb_table; static size_t mig_cb_table_sz; -static timeout_callback runtime_idle_callback = launchd_shutdown; -static mach_msg_timeout_t runtime_idle_timeout = RUNTIME_ADVISABLE_IDLE_TIMEOUT * 1000; +static timeout_callback runtime_idle_callback; +static mach_msg_timeout_t runtime_idle_timeout; static audit_token_t *au_tok; static size_t runtime_busy_cnt; @@ -912,11 +912,11 @@ } } - if ((tmp_options & MACH_RCV_MSG) && runtime_idle_callback && (runtime_busy_cnt == 0)) { + if ((tmp_options & MACH_RCV_MSG) && (runtime_idle_callback || (runtime_busy_cnt == 0))) { tmp_options |= MACH_RCV_TIMEOUT; if (!(tmp_options & MACH_SEND_TIMEOUT)) { - to = runtime_idle_timeout; + to = runtime_busy_cnt ? runtime_idle_timeout : (RUNTIME_ADVISABLE_IDLE_TIMEOUT * 1000); } } @@ -935,7 +935,11 @@ continue; } else if (mr == MACH_RCV_TIMED_OUT) { if (to != MACH_MSG_TIMEOUT_NONE) { - runtime_idle_callback(); + if (runtime_busy_cnt == 0) { + launchd_shutdown(); + } else if (runtime_idle_callback) { + runtime_idle_callback(); + } } continue; } else if (!launchd_assumes(mr == MACH_MSG_SUCCESS)) {