View | Details | Raw Unified | Return to bug 61558
Collapse All | Expand All

(-)os/unix/unixd.c (+24 lines)
Lines 437-447 AP_DECLARE(apr_status_t) ap_unixd_accept(void **ac Link Here
437
/* Unixes MPMs' */
437
/* Unixes MPMs' */
438
438
439
static ap_unixd_mpm_retained_data *retained_data = NULL;
439
static ap_unixd_mpm_retained_data *retained_data = NULL;
440
static apr_status_t retained_data_cleanup(void *unused)
441
{
442
    (void)unused;
443
    retained_data = NULL;
444
    return APR_SUCCESS;
445
}
446
440
AP_DECLARE(ap_unixd_mpm_retained_data *) ap_unixd_mpm_get_retained_data()
447
AP_DECLARE(ap_unixd_mpm_retained_data *) ap_unixd_mpm_get_retained_data()
441
{
448
{
442
    if (!retained_data) {
449
    if (!retained_data) {
443
        retained_data = ap_retained_data_create("ap_unixd_mpm_retained_data",
450
        retained_data = ap_retained_data_create("ap_unixd_mpm_retained_data",
444
                                                sizeof(*retained_data));
451
                                                sizeof(*retained_data));
452
        apr_pool_pre_cleanup_register(ap_pglobal, NULL, retained_data_cleanup);
445
        retained_data->mpm_state = AP_MPMQ_STARTING;
453
        retained_data->mpm_state = AP_MPMQ_STARTING;
446
    }
454
    }
447
    return retained_data;
455
    return retained_data;
Lines 449-454 AP_DECLARE(ap_unixd_mpm_retained_data *) ap_unixd_ Link Here
449
457
450
static void sig_term(int sig)
458
static void sig_term(int sig)
451
{
459
{
460
    if (!retained_data) {
461
        /* Main process (ap_pglobal) is dying */
462
        return;
463
    }
452
    retained_data->mpm_state = AP_MPMQ_STOPPING;
464
    retained_data->mpm_state = AP_MPMQ_STOPPING;
453
    if (retained_data->shutdown_pending
465
    if (retained_data->shutdown_pending
454
            && (retained_data->is_ungraceful
466
            && (retained_data->is_ungraceful
Lines 465-470 static void sig_term(int sig) Link Here
465
477
466
static void sig_restart(int sig)
478
static void sig_restart(int sig)
467
{
479
{
480
    if (!retained_data) {
481
        /* Main process (ap_pglobal) is dying */
482
        return;
483
    }
468
    retained_data->mpm_state = AP_MPMQ_STOPPING;
484
    retained_data->mpm_state = AP_MPMQ_STOPPING;
469
    if (retained_data->restart_pending
485
    if (retained_data->restart_pending
470
            && (retained_data->is_ungraceful
486
            && (retained_data->is_ungraceful
Lines 481-486 static void sig_restart(int sig) Link Here
481
497
482
static apr_status_t unset_signals(void *unused)
498
static apr_status_t unset_signals(void *unused)
483
{
499
{
500
    if (!retained_data) {
501
        /* Main process (ap_pglobal) is dying */
502
        return APR_SUCCESS;
503
    }
484
    retained_data->shutdown_pending = retained_data->restart_pending = 0;
504
    retained_data->shutdown_pending = retained_data->restart_pending = 0;
485
    retained_data->was_graceful = !retained_data->is_ungraceful;
505
    retained_data->was_graceful = !retained_data->is_ungraceful;
486
    retained_data->is_ungraceful = 0;
506
    retained_data->is_ungraceful = 0;
Lines 494-499 AP_DECLARE(void) ap_unixd_mpm_set_signals(apr_pool Link Here
494
    struct sigaction sa;
514
    struct sigaction sa;
495
#endif
515
#endif
496
516
517
    if (!one_process) {
518
        ap_fatal_signal_setup(ap_server_conf, pconf);
519
    }
520
497
    /* Signals' handlers depend on retained data */
521
    /* Signals' handlers depend on retained data */
498
    (void)ap_unixd_mpm_get_retained_data();
522
    (void)ap_unixd_mpm_get_retained_data();
499
523
(-)server/main.c (-5 / +28 lines)
Lines 273-278 static int abort_on_oom(int retcode) Link Here
273
    return retcode; /* unreachable, hopefully. */
273
    return retcode; /* unreachable, hopefully. */
274
}
274
}
275
275
276
/* Deregister all hooks when clearing pconf (pre_cleanup).
277
 * TODO: have a hook to deregister and run them from here?
278
 *       ap_clear_auth_internal() is already a candidate.
279
 */
280
static apr_status_t deregister_all_hooks(void *unused)
281
{
282
    (void)unused;
283
    ap_clear_auth_internal();
284
    apr_hook_deregister_all();
285
    return APR_SUCCESS;
286
}
287
288
static void reset_process_pconf(process_rec *process)
289
{
290
    if (process->pconf) {
291
        apr_pool_clear(process->pconf);
292
    }
293
    else {
294
        apr_pool_create(&process->pconf, process->pool);
295
        apr_pool_tag(process->pconf, "pconf");
296
    }
297
    apr_pool_pre_cleanup_register(process->pconf, NULL, deregister_all_hooks);
298
}
299
276
static process_rec *init_process(int *argc, const char * const * *argv)
300
static process_rec *init_process(int *argc, const char * const * *argv)
277
{
301
{
278
    process_rec *process;
302
    process_rec *process;
Lines 317-324 static process_rec *init_process(int *argc, const Link Here
317
    process = apr_palloc(cntx, sizeof(process_rec));
341
    process = apr_palloc(cntx, sizeof(process_rec));
318
    process->pool = cntx;
342
    process->pool = cntx;
319
343
320
    apr_pool_create(&process->pconf, process->pool);
344
    process->pconf = NULL;
321
    apr_pool_tag(process->pconf, "pconf");
345
    reset_process_pconf(process);
346
322
    process->argc = *argc;
347
    process->argc = *argc;
323
    process->argv = *argv;
348
    process->argv = *argv;
324
    process->short_name = apr_filepath_name_get((*argv)[0]);
349
    process->short_name = apr_filepath_name_get((*argv)[0]);
Lines 721-729 int main(int argc, const char * const argv[]) Link Here
721
746
722
    do {
747
    do {
723
        ap_main_state = AP_SQ_MS_DESTROY_CONFIG;
748
        ap_main_state = AP_SQ_MS_DESTROY_CONFIG;
724
        apr_hook_deregister_all();
749
        reset_process_pconf(process);
725
        apr_pool_clear(pconf);
726
        ap_clear_auth_internal();
727
750
728
        ap_main_state = AP_SQ_MS_CREATE_CONFIG;
751
        ap_main_state = AP_SQ_MS_CREATE_CONFIG;
729
        ap_config_generation++;
752
        ap_config_generation++;
(-)server/mpm/event/event.c (-3 lines)
Lines 2880-2888 static int event_run(apr_pool_t * _pconf, apr_pool Link Here
2880
        ap_scoreboard_image->global->running_generation = retained->mpm->my_generation;
2880
        ap_scoreboard_image->global->running_generation = retained->mpm->my_generation;
2881
    }
2881
    }
2882
2882
2883
    if (!one_process) {
2884
        ap_fatal_signal_setup(ap_server_conf, pconf);
2885
    }
2886
    ap_unixd_mpm_set_signals(pconf, one_process);
2883
    ap_unixd_mpm_set_signals(pconf, one_process);
2887
2884
2888
    /* Don't thrash since num_buckets depends on the
2885
    /* Don't thrash since num_buckets depends on the
(-)server/mpm/prefork/prefork.c (-3 lines)
Lines 863-871 static int prefork_run(apr_pool_t *_pconf, apr_poo Link Here
863
        ap_scoreboard_image->global->running_generation = retained->mpm->my_generation;
863
        ap_scoreboard_image->global->running_generation = retained->mpm->my_generation;
864
    }
864
    }
865
865
866
    if (!one_process) {
867
        ap_fatal_signal_setup(ap_server_conf, pconf);
868
    }
869
    ap_unixd_mpm_set_signals(pconf, one_process);
866
    ap_unixd_mpm_set_signals(pconf, one_process);
870
867
871
    if (one_process) {
868
    if (one_process) {
(-)server/mpm/worker/worker.c (-3 lines)
Lines 1671-1679 static int worker_run(apr_pool_t *_pconf, apr_pool Link Here
1671
        ap_scoreboard_image->global->running_generation = retained->mpm->my_generation;
1671
        ap_scoreboard_image->global->running_generation = retained->mpm->my_generation;
1672
    }
1672
    }
1673
1673
1674
    if (!one_process) {
1675
        ap_fatal_signal_setup(ap_server_conf, pconf);
1676
    }
1677
    ap_unixd_mpm_set_signals(pconf, one_process);
1674
    ap_unixd_mpm_set_signals(pconf, one_process);
1678
1675
1679
    /* Don't thrash since num_buckets depends on the
1676
    /* Don't thrash since num_buckets depends on the
(-)server/mpm_unix.c (+29 lines)
Lines 1009-1014 AP_DECLARE(apr_status_t) ap_fatal_signal_child_set Link Here
1009
    return APR_SUCCESS;
1009
    return APR_SUCCESS;
1010
}
1010
}
1011
1011
1012
/* We can't call sig_coredump (ap_log_error) once pconf is destroyed, so
1013
 * avoid double faults by restoring each default signal handler on cleanup.
1014
 */
1015
static apr_status_t fatal_signal_cleanup(void *unused)
1016
{
1017
    (void)unused;
1018
1019
    apr_signal(SIGSEGV, SIG_DFL);
1020
#ifdef SIGBUS
1021
    apr_signal(SIGBUS, SIG_DFL);
1022
#endif /* SIGBUS */
1023
#ifdef SIGABORT
1024
    apr_signal(SIGABORT, SIG_DFL);
1025
#endif /* SIGABORT */
1026
#ifdef SIGABRT
1027
    apr_signal(SIGABRT, SIG_DFL);
1028
#endif /* SIGABRT */
1029
#ifdef SIGILL
1030
    apr_signal(SIGILL, SIG_DFL);
1031
#endif /* SIGILL */
1032
#ifdef SIGFPE
1033
    apr_signal(SIGFPE, SIG_DFL);
1034
#endif /* SIGFPE */
1035
1036
    return APR_SUCCESS;
1037
}
1038
1012
AP_DECLARE(apr_status_t) ap_fatal_signal_setup(server_rec *s,
1039
AP_DECLARE(apr_status_t) ap_fatal_signal_setup(server_rec *s,
1013
                                               apr_pool_t *in_pconf)
1040
                                               apr_pool_t *in_pconf)
1014
{
1041
{
Lines 1071-1076 AP_DECLARE(apr_status_t) ap_fatal_signal_setup(ser Link Here
1071
1098
1072
    pconf = in_pconf;
1099
    pconf = in_pconf;
1073
    parent_pid = my_pid = getpid();
1100
    parent_pid = my_pid = getpid();
1101
    apr_pool_cleanup_register(pconf, NULL, fatal_signal_cleanup,
1102
                              fatal_signal_cleanup);
1074
1103
1075
    return APR_SUCCESS;
1104
    return APR_SUCCESS;
1076
}
1105
}

Return to bug 61558