From a21012b7aab06e9e9e9afb1b7f37b7339ff65145 Mon Sep 17 00:00:00 2001 From: Manoj Kasichainula Date: Tue, 10 Aug 1999 21:18:43 +0000 Subject: [PATCH] Put back the process_child_status code from 1.3. Handling of synchronous signals like SEGV and FPE is still a bit dodgy, though, so this won't accomplish much by itself. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@83644 13f79535-47bb-0310-9956-ffa450edef68 --- server/mpm/dexter/dexter.c | 53 +++++++++++++++++++++++++ server/mpm/mpmt_pthread/mpmt_pthread.c | 55 +++++++++++++++++++++++++- 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/server/mpm/dexter/dexter.c b/server/mpm/dexter/dexter.c index 3046bdf345f..4cde4c99f8f 100644 --- a/server/mpm/dexter/dexter.c +++ b/server/mpm/dexter/dexter.c @@ -744,6 +744,57 @@ static void set_signals(void) #endif } + +static void process_child_status(int pid, ap_wait_t status) +{ + /* Child died... if it died due to a fatal error, + * we should simply bail out. + */ + if ((WIFEXITED(status)) && + WEXITSTATUS(status) == APEXIT_CHILDFATAL) { + ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, server_conf, + "Child %d returned a Fatal error... \n" + "Apache is exiting!", + pid); + exit(APEXIT_CHILDFATAL); + } + if (WIFSIGNALED(status)) { + switch (WTERMSIG(status)) { + case SIGTERM: + case SIGHUP: + case SIGUSR1: + case SIGKILL: + break; + default: +#ifdef SYS_SIGLIST +#ifdef WCOREDUMP + if (WCOREDUMP(status)) { + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, + server_conf, + "child pid %d exit signal %s (%d), " + "possible coredump in %s", + pid, (WTERMSIG(status) >= NumSIG) ? "" : + SYS_SIGLIST[WTERMSIG(status)], WTERMSIG(status), + ap_coredump_dir); + } + else { +#endif + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, + server_conf, + "child pid %d exit signal %s (%d)", pid, + SYS_SIGLIST[WTERMSIG(status)], WTERMSIG(status)); +#ifdef WCOREDUMP + } +#endif +#else + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, + server_conf, + "child pid %d exit signal %d", + pid, WTERMSIG(status)); +#endif + } + } +} static int setup_listeners(pool *pconf, server_rec *s) { @@ -1253,6 +1304,8 @@ static void server_main_loop(int remaining_children_to_start) pid = wait_or_timeout(&status); if (pid >= 0) { + process_child_status(pid, status); + /* non-fatal death... note that it's gone in the scoreboard. */ child_slot = find_child_by_pid(pid); if (child_slot >= 0) { ap_update_child_status(child_slot, SERVER_DEAD); diff --git a/server/mpm/mpmt_pthread/mpmt_pthread.c b/server/mpm/mpmt_pthread/mpmt_pthread.c index 60ce966d648..9c4c0b65d7a 100644 --- a/server/mpm/mpmt_pthread/mpmt_pthread.c +++ b/server/mpm/mpmt_pthread/mpmt_pthread.c @@ -568,7 +568,7 @@ static void sig_coredump(int sig) { chdir(ap_coredump_dir); signal(sig, SIG_DFL); - kill(getpid(), sig); + kill(my_pid, sig); /* At this point we've got sig blocked, because we're still inside * the signal handler. When we leave the signal handler it will * be unblocked, and we'll take the signal... and coredump or whatever @@ -752,6 +752,57 @@ static void set_signals(void) #endif } + +static void process_child_status(int pid, ap_wait_t status) +{ + /* Child died... if it died due to a fatal error, + * we should simply bail out. + */ + if ((WIFEXITED(status)) && + WEXITSTATUS(status) == APEXIT_CHILDFATAL) { + ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, server_conf, + "Child %d returned a Fatal error... \n" + "Apache is exiting!", + pid); + exit(APEXIT_CHILDFATAL); + } + if (WIFSIGNALED(status)) { + switch (WTERMSIG(status)) { + case SIGTERM: + case SIGHUP: + case SIGUSR1: + case SIGKILL: + break; + default: +#ifdef SYS_SIGLIST +#ifdef WCOREDUMP + if (WCOREDUMP(status)) { + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, + server_conf, + "child pid %d exit signal %s (%d), " + "possible coredump in %s", + pid, (WTERMSIG(status) >= NumSIG) ? "" : + SYS_SIGLIST[WTERMSIG(status)], WTERMSIG(status), + ap_coredump_dir); + } + else { +#endif + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, + server_conf, + "child pid %d exit signal %s (%d)", pid, + SYS_SIGLIST[WTERMSIG(status)], WTERMSIG(status)); +#ifdef WCOREDUMP + } +#endif +#else + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, + server_conf, + "child pid %d exit signal %d", + pid, WTERMSIG(status)); +#endif + } + } +} static int setup_listeners(pool *pconf, server_rec *s) { @@ -1296,6 +1347,8 @@ static void server_main_loop(int remaining_children_to_start) pid = wait_or_timeout(&status); if (pid >= 0) { + process_child_status(pid, status); + /* non-fatal death... note that it's gone in the scoreboard. */ child_slot = find_child_by_pid(pid); if (child_slot >= 0) { for (i = 0; i < ap_threads_per_child; i++) -- 2.47.2