AP_DECLARE(void) ap_unixd_mpm_set_signals(apr_pool_t *pconf, int one_process) { #ifndef NO_USE_SIGACTION struct sigaction sa; #endif if (!one_process) { ap_fatal_signal_setup(ap_server_conf, pconf); } else if (!ap_retained_data_get("ap_unixd_mpm_one_process_cleanup")) { /* In one process mode (debug), httpd will exit immediately when asked * to (SIGTERM/SIGINT) and never restart. We still want the cleanups to * run though (such that e.g. temporary files/IPCs don't leak on the * system), so the first time around we use atexit() to cleanup after * ourselves. */ ap_retained_data_create("ap_unixd_mpm_one_process_cleanup", 1); atexit(ap_terminate); } /* Signals' handlers depend on retained data */ (void)ap_unixd_mpm_get_retained_data(); #ifndef NO_USE_SIGACTION memset(&sa, 0, sizeof sa); sigemptyset(&sa.sa_mask); #ifdef SIGPIPE sa.sa_handler = SIG_IGN; if (sigaction(SIGPIPE, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00269) "sigaction(SIGPIPE)"); #endif #ifdef SIGXCPU sa.sa_handler = SIG_DFL; if (sigaction(SIGXCPU, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00267) "sigaction(SIGXCPU)"); #endif #ifdef SIGXFSZ /* For systems following the LFS standard, ignoring SIGXFSZ allows * a write() beyond the 2GB limit to fail gracefully with E2BIG * rather than terminate the process. */ sa.sa_handler = SIG_IGN; if (sigaction(SIGXFSZ, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00268) "sigaction(SIGXFSZ)"); #endif sa.sa_handler = sig_term; if (sigaction(SIGTERM, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00264) "sigaction(SIGTERM)"); #ifdef SIGINT if (sigaction(SIGINT, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00266) "sigaction(SIGINT)"); #endif #ifdef AP_SIG_GRACEFUL_STOP if (sigaction(AP_SIG_GRACEFUL_STOP, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00265) "sigaction(" AP_SIG_GRACEFUL_STOP_STRING ")"); #endif /* Don't catch restart signals in ONE_PROCESS mode :) */ if (!one_process) { sa.sa_handler = sig_restart; if (sigaction(SIGHUP, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00270) "sigaction(SIGHUP)"); if (sigaction(AP_SIG_GRACEFUL, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, APLOGNO(00271) "sigaction(" AP_SIG_GRACEFUL_STRING ")"); } #else /* NO_USE_SIGACTION */ #ifdef SIGPIPE apr_signal(SIGPIPE, SIG_IGN); #endif /* SIGPIPE */ #ifdef SIGXCPU apr_signal(SIGXCPU, SIG_DFL); #endif /* SIGXCPU */ #ifdef SIGXFSZ apr_signal(SIGXFSZ, SIG_IGN); #endif /* SIGXFSZ */ apr_signal(SIGTERM, sig_term); #ifdef AP_SIG_GRACEFUL_STOP apr_signal(AP_SIG_GRACEFUL_STOP, sig_term); #endif /* AP_SIG_GRACEFUL_STOP */ if (!one_process) { /* Don't restart in ONE_PROCESS mode :) */ #ifdef SIGHUP apr_signal(SIGHUP, sig_restart); #endif /* SIGHUP */ #ifdef AP_SIG_GRACEFUL apr_signal(AP_SIG_GRACEFUL, sig_restart); #endif /* AP_SIG_GRACEFUL */ } #endif /* NO_USE_SIGACTION */ apr_pool_cleanup_register(pconf, NULL, unset_signals, apr_pool_cleanup_null); }
static void set_signals(void) { #ifndef NO_USE_SIGACTION struct sigaction sa; #endif if (!one_process) { ap_fatal_signal_setup(ap_server_conf, pconf); } #ifndef NO_USE_SIGACTION sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = sig_term; if (sigaction(SIGTERM, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGTERM)"); #ifdef SIGINT if (sigaction(SIGINT, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGINT)"); #endif #ifdef SIGXCPU sa.sa_handler = SIG_DFL; if (sigaction(SIGXCPU, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXCPU)"); #endif #ifdef SIGXFSZ sa.sa_handler = SIG_DFL; if (sigaction(SIGXFSZ, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXFSZ)"); #endif #ifdef SIGPIPE sa.sa_handler = SIG_IGN; if (sigaction(SIGPIPE, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGPIPE)"); #endif /* we want to ignore HUPs and AP_SIG_GRACEFUL while we're busy * processing one */ sigaddset(&sa.sa_mask, SIGHUP); sigaddset(&sa.sa_mask, AP_SIG_GRACEFUL); sa.sa_handler = restart; if (sigaction(SIGHUP, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGHUP)"); if (sigaction(AP_SIG_GRACEFUL, &sa, NULL) < 0) ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(" AP_SIG_GRACEFUL_STRING ")"); #else if (!one_process) { #ifdef SIGXCPU apr_signal(SIGXCPU, SIG_DFL); #endif /* SIGXCPU */ #ifdef SIGXFSZ apr_signal(SIGXFSZ, SIG_DFL); #endif /* SIGXFSZ */ } apr_signal(SIGTERM, sig_term); #ifdef SIGHUP apr_signal(SIGHUP, restart); #endif /* SIGHUP */ #ifdef AP_SIG_GRACEFUL apr_signal(AP_SIG_GRACEFUL, restart); #endif /* AP_SIG_GRACEFUL */ #ifdef SIGPIPE apr_signal(SIGPIPE, SIG_IGN); #endif /* SIGPIPE */ #endif }