Projects
Browse Source     Search     Timeline     Wiki

Changeset 23046

Show
Ignore:
Timestamp:
02/08/07 14:39:50 (22 months ago)
Author:
zarzycki@…
Message:

More shutdown logic clean up and sanity checking.

Location:
trunk/launchd/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/launchd/src/launchd_core_logic.c

    r23045 r23046  
    517517        job_t ji, jn; 
    518518 
     519        jobmgr_log(jm, LOG_DEBUG, "Beginning job manager shutdown"); 
     520 
    519521        SLIST_FOREACH_SAFE(jmi, &jm->submgrs, sle, jmn) { 
    520522                jobmgr_shutdown(jmi); 
     
    540542        job_t ji; 
    541543 
    542         while ((jmi = SLIST_FIRST(&jm->submgrs))) { 
    543                 jobmgr_remove(jmi); 
    544         } 
     544        jobmgr_log(jm, LOG_DEBUG, "Removed job manager"); 
     545 
     546        if (!jobmgr_assumes(jm, SLIST_EMPTY(&jm->submgrs))) { 
     547                while ((jmi = SLIST_FIRST(&jm->submgrs))) { 
     548                        jobmgr_remove(jmi); 
     549                } 
     550        } 
     551 
     552        /* We should have one job left and it should be the anonymous job */ 
     553        ji = SLIST_FIRST(&jm->jobs); 
     554        jobmgr_assumes(jm, ji && ji == jm->anonj && (SLIST_NEXT(ji, sle) == NULL)); 
    545555 
    546556        while ((ji = SLIST_FIRST(&jm->jobs))) { 
    547557                job_remove(ji); 
    548         } 
    549  
    550         if (jm->parentmgr) { 
    551                 SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); 
    552558        } 
    553559 
     
    570576        if (jm->jm_stderr) { 
    571577                free(jm->jm_stderr); 
     578        } 
     579 
     580        if (jm->parentmgr) { 
     581                SLIST_REMOVE(&jm->parentmgr->submgrs, jm, jobmgr_s, sle); 
     582                jobmgr_tickle(jm->parentmgr); 
    572583        } 
    573584         
     
    591602        } 
    592603 
    593         if (j->p && !j->anonymous) { 
    594                 if (kevent_mod(j->p, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, &kqsimple_zombie_reaper) == -1) { 
    595                         job_reap(j); 
    596                 } else { 
    597                         /* we've attached the simple zombie reaper, we're going to delete the job before it is dead */ 
    598                         job_stop(j); 
    599                 } 
    600         } 
    601  
    602         if (j->forkfd) { 
     604        if (!job_assumes(j, j->p == 0)) { 
     605                job_assumes(j, kill(j->p, SIGKILL) != -1); 
     606                job_reap(j); 
     607        } 
     608 
     609        if (!job_assumes(j, j->forkfd == 0)) { 
    603610                job_assumes(j, close(j->forkfd) != -1); 
    604611        } 
    605612 
    606         if (j->log_redirect_fd) { 
     613        if (!job_assumes(j, j->log_redirect_fd == 0)) { 
    607614                job_assumes(j, close(j->log_redirect_fd) != -1); 
    608615        } 
     
    28042811                return true; 
    28052812        } else if (j->mgr->shutting_down) { 
    2806                 job_log(j, LOG_INFO, "Exited while shutdown in progress."); 
     2813                unsigned int cnt = 0; 
     2814                job_t ji; 
     2815 
     2816                SLIST_FOREACH(ji, &j->mgr->jobs, sle) { 
     2817                        if (ji->p) { 
     2818                                cnt++; 
     2819                        } 
     2820                } 
     2821 
     2822                job_log(j, LOG_INFO, "Exited while shutdown in progress. Processes remaining: %u", cnt); 
    28072823                return true; 
    28082824        } else if (!j->checkedin && (!SLIST_EMPTY(&j->sockets) || !SLIST_EMPTY(&j->machservices))) { 
     
    31943210        job_t ji; 
    31953211 
     3212        if (!SLIST_EMPTY(&jm->submgrs)) { 
     3213                return false; 
     3214        } 
     3215 
    31963216        SLIST_FOREACH(ji, &jm->jobs, sle) { 
    31973217                if (ji->p) { 
     
    33203340 
    33213341        jobmgr_assumes(jmr, jmr->anonj != NULL); 
     3342 
     3343        jobmgr_log(jmr, LOG_DEBUG, "Created job manager"); 
    33223344 
    33233345        return jmr; 
  • trunk/launchd/src/launchd_runtime.c

    r23032 r23046  
    3636#include <mach/exception.h> 
    3737#include <sys/types.h> 
     38#include <sys/stat.h> 
    3839#include <sys/time.h> 
    3940#include <sys/event.h> 
     
    579580                /* XXX - So very gross */ 
    580581                if (gc_this_jobmgr) { 
    581                         jobmgr_remove(gc_this_jobmgr); 
     582                        jobmgr_shutdown(gc_this_jobmgr); 
    582583                        gc_this_jobmgr = NULL; 
    583584                } 
     
    675676 
    676677        if (ourlogfile == NULL) { 
     678                rename("/var/log/launchd_raw.log", "/var/log/launchd_raw-old.log"); 
    677679                ourlogfile = fopen("/var/log/launchd_raw.log", "a"); 
     680                chmod("/var/log/launchd_raw.log", DEFFILEMODE); 
    678681        } 
    679682