Projects
Browse Source     Search     Timeline     Wiki

Changeset 23376

Show
Ignore:
Timestamp:
09/12/07 17:48:46 (15 months ago)
Author:
zarzycki@…
Message:

<rdar://problem/5475980> The per-user launchd needs to idle exit

Location:
trunk/launchd/src
Files:
3 modified

Legend:

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

    r23375 r23376  
    9494 
    9595#define LAUNCHD_MIN_JOB_RUN_TIME 10 
    96 #define LAUNCHD_ADVISABLE_IDLE_TIMEOUT 30 
    9796#define LAUNCHD_DEFAULT_EXIT_TIMEOUT 20 
    9897#define LAUNCHD_SIGKILL_TIMER 5 
     
    451450 
    452451/* file local globals */ 
    453 static unsigned int total_children; 
     452static size_t total_children; 
    454453static mach_port_t the_exception_server; 
    455454static bool did_first_per_user_launchd_BootCache_hack; 
     
    647646still_alive_with_check(void) 
    648647{ 
    649         jobmgr_log(root_jobmgr, LOG_NOTICE, "Still alive with %u children.", total_children); 
     648        jobmgr_log(root_jobmgr, LOG_NOTICE, "Still alive with %lu children.", total_children); 
    650649 
    651650        runtime_closelog(); /* hack to flush logs */ 
     
    741740        struct envitem *ei; 
    742741 
     742        if (j == workaround_5477111) { 
     743                job_log(j, LOG_NOTICE, "@@@@@ Tried to remove ahead of schedule!"); 
     744        } 
     745 
    743746        if (j->p && j->anonymous) { 
    744747                job_reap(j); 
     
    838841        } 
    839842        if (j->start_interval) { 
     843                runtime_del_ref(); 
    840844                job_assumes(j, kevent_mod((uintptr_t)&j->start_interval, EVFILT_TIMER, EV_DELETE, 0, 0, NULL) != -1); 
    841845        } 
     
    11231127        j->mgr = jm; 
    11241128        j->min_run_time = LAUNCHD_MIN_JOB_RUN_TIME; 
    1125         j->timeout = LAUNCHD_ADVISABLE_IDLE_TIMEOUT; 
     1129        j->timeout = RUNTIME_ADVISABLE_IDLE_TIMEOUT; 
    11261130        j->exit_timeout = LAUNCHD_DEFAULT_EXIT_TIMEOUT; 
    11271131        j->currently_ignored = true; 
     
    14611465                                job_log(j, LOG_WARNING, "StartInterval is not greater than zero, ignoring"); 
    14621466                        } else { 
     1467                                runtime_add_ref(); 
    14631468                                j->start_interval = value; 
    14641469                        } 
     
    19511956        } 
    19521957 
     1958        if (!j->anonymous) { 
     1959                runtime_del_ref(); 
     1960        } 
    19531961        total_children--; 
    19541962        LIST_REMOVE(j, pid_hash_sle); 
     
    23892397                j->start_pending = false; 
    23902398 
     2399                runtime_add_ref(); 
    23912400                total_children++; 
    23922401                LIST_INSERT_HEAD(&j->mgr->active_jobs[ACTIVE_JOB_HASH(c)], j, pid_hash_sle); 
     
    32633272        calendarinterval_setalarm(j, ci); 
    32643273 
     3274        runtime_add_ref(); 
     3275 
    32653276        return true; 
    32663277} 
     
    32733284 
    32743285        free(ci); 
     3286 
     3287        runtime_del_ref(); 
    32753288} 
    32763289 
     
    33303343        SLIST_INSERT_HEAD(&j->sockets, sg, sle); 
    33313344 
     3345        runtime_add_ref(); 
     3346 
    33323347        return true; 
    33333348} 
     
    33463361        free(sg->fds); 
    33473362        free(sg); 
     3363 
     3364        runtime_del_ref(); 
    33483365} 
    33493366 
     
    35433560                return true; 
    35443561        } else if (j->mgr->shutting_down) { 
    3545                 job_log(j, LOG_DEBUG, "Exited while shutdown in progress. Processes remaining: %u", total_children); 
     3562                job_log(j, LOG_DEBUG, "Exited while shutdown in progress. Processes remaining: %lu", total_children); 
    35463563                return true; 
    35473564        } else if (j->legacy_mach_job) { 
     
    45604577        SLIST_INSERT_HEAD(&j->semaphores, si, sle); 
    45614578 
     4579        runtime_add_ref(); 
     4580 
    45624581        return true; 
    45634582} 
     
    45734592 
    45744593        free(si); 
     4594 
     4595        runtime_del_ref(); 
    45754596} 
    45764597 
     
    51235144        case VPROC_GSK_START_INTERVAL: 
    51245145                if ((unsigned int)inval > 0) { 
     5146                        if (j->start_interval == 0) { 
     5147                                runtime_add_ref(); 
     5148                        } 
    51255149                        j->start_interval = inval; 
    51265150                        job_assumes(j, kevent_mod((uintptr_t)&j->start_interval, EVFILT_TIMER, EV_ADD, NOTE_SECONDS, j->start_interval, j) != -1); 
    51275151                } else if (j->start_interval) { 
    51285152                        job_assumes(j, kevent_mod((uintptr_t)&j->start_interval, EVFILT_TIMER, EV_DELETE, 0, 0, NULL) != -1); 
     5153                        if (j->start_interval != 0) { 
     5154                                runtime_del_ref(); 
     5155                        } 
    51295156                        j->start_interval = 0; 
    51305157                } 
  • trunk/launchd/src/launchd_runtime.c

    r23373 r23376  
    9191static mig_callback *mig_cb_table; 
    9292static size_t mig_cb_table_sz; 
    93 static timeout_callback runtime_idle_callback; 
    94 static mach_msg_timeout_t runtime_idle_timeout; 
     93static timeout_callback runtime_idle_callback = launchd_shutdown; 
     94static mach_msg_timeout_t runtime_idle_timeout = RUNTIME_ADVISABLE_IDLE_TIMEOUT * 1000; 
    9595static audit_token_t *au_tok; 
     96static size_t runtime_busy_cnt; 
    9697 
    9798 
     
    636637 
    637638void 
    638 runtime_set_timeout(timeout_callback to_cb, mach_msg_timeout_t to) 
    639 { 
    640         if (to == 0 || to_cb == NULL) { 
     639runtime_set_timeout(timeout_callback to_cb, unsigned int sec) 
     640{ 
     641        if (sec == 0 || to_cb == NULL) { 
    641642                runtime_idle_callback = NULL; 
    642643                runtime_idle_timeout = 0; 
     
    644645 
    645646        runtime_idle_callback = to_cb; 
    646         runtime_idle_timeout = to; 
     647        runtime_idle_timeout = sec * 1000; 
    647648} 
    648649 
     
    912913                } 
    913914 
    914                 if ((tmp_options & MACH_RCV_MSG) && runtime_idle_callback) { 
     915                if ((tmp_options & MACH_RCV_MSG) && runtime_idle_callback && (runtime_busy_cnt == 0)) { 
    915916                        tmp_options |= MACH_RCV_TIMEOUT; 
    916917 
     
    13501351        return runtime_log_pack(outval, outvalCnt); 
    13511352} 
     1353 
     1354void 
     1355runtime_add_ref(void) 
     1356{ 
     1357        runtime_busy_cnt++; 
     1358} 
     1359 
     1360void 
     1361runtime_del_ref(void) 
     1362{ 
     1363        runtime_busy_cnt--; 
     1364} 
  • trunk/launchd/src/launchd_runtime.h

    r23362 r23376  
    5757boolean_t launchd_internal_demux(mach_msg_header_t *Request, mach_msg_header_t *Reply); 
    5858 
     59void runtime_add_ref(void); 
     60void runtime_del_ref(void); 
     61 
    5962void launchd_runtime_init(void); 
    6063void launchd_runtime_init2(void); 
     
    6467int runtime_fsync(int fd); 
    6568 
    66 void runtime_set_timeout(timeout_callback to_cb, mach_msg_timeout_t to); 
     69#define RUNTIME_ADVISABLE_IDLE_TIMEOUT 30 
     70 
     71void runtime_set_timeout(timeout_callback to_cb, unsigned int sec); 
    6772kern_return_t runtime_add_mport(mach_port_t name, mig_callback demux, mach_msg_size_t msg_size); 
    6873kern_return_t runtime_remove_mport(mach_port_t name);