Revision: 23046 http://trac.macosforge.org/projects/launchd/changeset/23046 Author: zarzycki@apple.com Date: 2007-02-08 14:39:50 -0800 (Thu, 08 Feb 2007) Log Message: ----------- More shutdown logic clean up and sanity checking. 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-02-08 18:04:06 UTC (rev 23045) +++ trunk/launchd/src/launchd_core_logic.c 2007-02-08 22:39:50 UTC (rev 23046) @@ -516,6 +516,8 @@ jobmgr_t jmi, jmn; job_t ji, jn; + jobmgr_log(jm, LOG_DEBUG, "Beginning job manager shutdown"); + SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { jobmgr_shutdown(jmi); } @@ -539,18 +541,22 @@ jobmgr_t jmi; job_t ji; - while ((jmi = SLIST_FIRST(&jm->submgrs))) { - jobmgr_remove(jmi); + jobmgr_log(jm, LOG_DEBUG, "Removed job manager"); + + if (!jobmgr_assumes(jm, SLIST_EMPTY(&jm->submgrs))) { + while ((jmi = SLIST_FIRST(&jm->submgrs))) { + jobmgr_remove(jmi); + } } + /* We should have one job left and it should be the anonymous job */ + ji = SLIST_FIRST(&jm->jobs); + jobmgr_assumes(jm, ji && ji == jm->anonj && (SLIST_NEXT(ji, sle) == NULL)); + while ((ji = SLIST_FIRST(&jm->jobs))) { job_remove(ji); } - if (jm->parentmgr) { - SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); - } - if (jm->req_port) { jobmgr_assumes(jm, launchd_mport_deallocate(jm->req_port) == KERN_SUCCESS); } @@ -570,6 +576,11 @@ if (jm->jm_stderr) { free(jm->jm_stderr); } + + if (jm->parentmgr) { + SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); + jobmgr_tickle(jm->parentmgr); + } free(jm); } @@ -590,20 +601,16 @@ job_set_global_on_demand(j, false); } - if (j->p && !j->anonymous) { - if (kevent_mod(j->p, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, &kqsimple_zombie_reaper) == -1) { - job_reap(j); - } else { - /* we've attached the simple zombie reaper, we're going to delete the job before it is dead */ - job_stop(j); - } + if (!job_assumes(j, j->p == 0)) { + job_assumes(j, kill(j->p, SIGKILL) != -1); + job_reap(j); } - if (j->forkfd) { + if (!job_assumes(j, j->forkfd == 0)) { job_assumes(j, close(j->forkfd) != -1); } - if (j->log_redirect_fd) { + if (!job_assumes(j, j->log_redirect_fd == 0)) { job_assumes(j, close(j->log_redirect_fd) != -1); } @@ -2803,7 +2810,16 @@ job_log(j, LOG_INFO, "Exited. Was only configured to run once."); return true; } else if (j->mgr->shutting_down) { - job_log(j, LOG_INFO, "Exited while shutdown in progress."); + unsigned int cnt = 0; + job_t ji; + + SLIST_FOREACH(ji, &j->mgr->jobs, sle) { + if (ji->p) { + cnt++; + } + } + + job_log(j, LOG_INFO, "Exited while shutdown in progress. Processes remaining: %u", cnt); return true; } else if (!j->checkedin && (!SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices))) { job_log(j, LOG_WARNING, "Failed to check-in!"); @@ -3193,6 +3209,10 @@ { job_t ji; + if (!SLIST_EMPTY(&jm->submgrs)) { + return false; + } + SLIST_FOREACH(ji, &jm->jobs, sle) { if (ji->p) { return false; @@ -3320,6 +3340,8 @@ jobmgr_assumes(jmr, jmr->anonj != NULL); + jobmgr_log(jmr, LOG_DEBUG, "Created job manager"); + return jmr; out_bad: Modified: trunk/launchd/src/launchd_runtime.c =================================================================== --- trunk/launchd/src/launchd_runtime.c 2007-02-08 18:04:06 UTC (rev 23045) +++ trunk/launchd/src/launchd_runtime.c 2007-02-08 22:39:50 UTC (rev 23046) @@ -35,6 +35,7 @@ #include <mach/mach_host.h> #include <mach/exception.h> #include <sys/types.h> +#include <sys/stat.h> #include <sys/time.h> #include <sys/event.h> #include <sys/queue.h> @@ -578,7 +579,7 @@ /* XXX - So very gross */ if (gc_this_jobmgr) { - jobmgr_remove(gc_this_jobmgr); + jobmgr_shutdown(gc_this_jobmgr); gc_this_jobmgr = NULL; } @@ -674,7 +675,9 @@ pthread_mutex_lock(&ourlock); if (ourlogfile == NULL) { + rename("/var/log/launchd_raw.log", "/var/log/launchd_raw-old.log"); ourlogfile = fopen("/var/log/launchd_raw.log", "a"); + chmod("/var/log/launchd_raw.log", DEFFILEMODE); } pthread_mutex_unlock(&ourlock);
participants (1)
-
source_changes@macosforge.org