summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJeff Trawick <trawick@apache.org>2001-11-17 15:02:26 +0100
committerJeff Trawick <trawick@apache.org>2001-11-17 15:02:26 +0100
commit502a0a8eb9fb7e5707f1ed100d1a49c9287208bd (patch)
treef4002edd4673e583f925cf9adfd68743e80af7a2 /server
parentExternalize the functions to manage the mpm's queue of completion_contexts. (diff)
downloadapache2-502a0a8eb9fb7e5707f1ed100d1a49c9287208bd.tar.xz
apache2-502a0a8eb9fb7e5707f1ed100d1a49c9287208bd.zip
Get mod_cgid killed when a MPM exits due to a fatal error.
Presumably other such processes are affected to. Now we give main() a chance to clean up. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@92019 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'server')
-rw-r--r--server/mpm/beos/beos.c17
-rw-r--r--server/mpm/experimental/perchild/perchild.c20
-rw-r--r--server/mpm/perchild/perchild.c20
-rw-r--r--server/mpm/prefork/prefork.c5
-rw-r--r--server/mpm/spmt_os2/spmt_os2.c29
-rw-r--r--server/mpm/threaded/threaded.c6
-rw-r--r--server/mpm/worker/worker.c20
-rw-r--r--server/mpm_common.c17
8 files changed, 85 insertions, 49 deletions
diff --git a/server/mpm/beos/beos.c b/server/mpm/beos/beos.c
index 106d1c3ac5..f8a2be958d 100644
--- a/server/mpm/beos/beos.c
+++ b/server/mpm/beos/beos.c
@@ -171,6 +171,7 @@ static void sig_coredump(int sig)
static int volatile shutdown_pending;
static int volatile restart_pending;
static int volatile is_graceful;
+static int volatile child_fatal;
ap_generation_t volatile ap_my_generation = 0;
/*
@@ -610,7 +611,11 @@ static void server_main_loop(int remaining_threads_to_start)
ap_wait_or_timeout(&exitwhy, &status, &pid, pconf);
if (pid.pid >= 0) {
- ap_process_child_status(&pid, exitwhy, status);
+ if (ap_process_child_status(&pid, exitwhy, status) == APEXIT_CHILDFATAL) {
+ shutdown_pending = 1;
+ child_fatal = 1;
+ return;
+ }
/* non-fatal death... note that it's gone in the scoreboard. */
child_slot = -1;
for (i = 0; i < ap_max_child_assigned; ++i) {
@@ -887,7 +892,7 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
/* close the UDP socket we've been using... */
apr_socket_close(listening_sockets[0]);
- if (one_process || shutdown_pending) {
+ if ((one_process || shutdown_pending) && !child_fatal) {
const char *pidfile = NULL;
pidfile = ap_server_root_relative (pconf, ap_pid_fname);
if ( pidfile != NULL && unlink(pidfile) == 0)
@@ -914,9 +919,11 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
/* use ap_reclaim_child_processes starting with SIGTERM */
ap_reclaim_child_processes(1);
- /* record the shutdown in the log */
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
- "caught SIGTERM, shutting down");
+ if (!child_fatal) { /* already recorded */
+ /* record the shutdown in the log */
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
+ "caught SIGTERM, shutting down");
+ }
return 1;
}
diff --git a/server/mpm/experimental/perchild/perchild.c b/server/mpm/experimental/perchild/perchild.c
index 909567770a..385dbdae14 100644
--- a/server/mpm/experimental/perchild/perchild.c
+++ b/server/mpm/experimental/perchild/perchild.c
@@ -295,6 +295,7 @@ static void just_die(int sig)
static int volatile shutdown_pending;
static int volatile restart_pending;
static int volatile is_graceful;
+static int volatile child_fatal;
/* we don't currently track ap_my_generation, but mod_status
* references it so it must be defined */
ap_generation_t volatile ap_my_generation=0;
@@ -1100,7 +1101,11 @@ static void server_main_loop(int remaining_children_to_start)
ap_wait_or_timeout(&exitwhy, &status, &pid, pconf);
if (pid.pid != -1) {
- ap_process_child_status(&pid, exitwhy, status);
+ if (ap_process_child_status(&pid, exitwhy, status) == APEXIT_CHILDFATAL) {
+ shutdown_pending = 1;
+ child_fatal = 1;
+ return;
+ }
/* non-fatal death... note that it's gone in the child table and
* clean out the status table. */
child_slot = -1;
@@ -1257,9 +1262,9 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
"killpg SIGTERM");
}
ap_reclaim_child_processes(1); /* Start with SIGTERM */
-
- /* cleanup pid file on normal shutdown */
- {
+
+ if (!child_fatal) {
+ /* cleanup pid file on normal shutdown */
const char *pidfile = NULL;
pidfile = ap_server_root_relative (pconf, ap_pid_fname);
if ( pidfile != NULL && unlink(pidfile) == 0)
@@ -1267,11 +1272,10 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
ap_server_conf,
"removed PID file %s (pid=%ld)",
pidfile, (long)getpid());
- }
-
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
- ap_server_conf, "caught SIGTERM, shutting down");
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
+ ap_server_conf, "caught SIGTERM, shutting down");
+ }
return 1;
}
diff --git a/server/mpm/perchild/perchild.c b/server/mpm/perchild/perchild.c
index 909567770a..385dbdae14 100644
--- a/server/mpm/perchild/perchild.c
+++ b/server/mpm/perchild/perchild.c
@@ -295,6 +295,7 @@ static void just_die(int sig)
static int volatile shutdown_pending;
static int volatile restart_pending;
static int volatile is_graceful;
+static int volatile child_fatal;
/* we don't currently track ap_my_generation, but mod_status
* references it so it must be defined */
ap_generation_t volatile ap_my_generation=0;
@@ -1100,7 +1101,11 @@ static void server_main_loop(int remaining_children_to_start)
ap_wait_or_timeout(&exitwhy, &status, &pid, pconf);
if (pid.pid != -1) {
- ap_process_child_status(&pid, exitwhy, status);
+ if (ap_process_child_status(&pid, exitwhy, status) == APEXIT_CHILDFATAL) {
+ shutdown_pending = 1;
+ child_fatal = 1;
+ return;
+ }
/* non-fatal death... note that it's gone in the child table and
* clean out the status table. */
child_slot = -1;
@@ -1257,9 +1262,9 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
"killpg SIGTERM");
}
ap_reclaim_child_processes(1); /* Start with SIGTERM */
-
- /* cleanup pid file on normal shutdown */
- {
+
+ if (!child_fatal) {
+ /* cleanup pid file on normal shutdown */
const char *pidfile = NULL;
pidfile = ap_server_root_relative (pconf, ap_pid_fname);
if ( pidfile != NULL && unlink(pidfile) == 0)
@@ -1267,11 +1272,10 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
ap_server_conf,
"removed PID file %s (pid=%ld)",
pidfile, (long)getpid());
- }
-
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
- ap_server_conf, "caught SIGTERM, shutting down");
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
+ ap_server_conf, "caught SIGTERM, shutting down");
+ }
return 1;
}
diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c
index 0d7832404b..641b613be8 100644
--- a/server/mpm/prefork/prefork.c
+++ b/server/mpm/prefork/prefork.c
@@ -1016,7 +1016,10 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
* extra child
*/
if (pid.pid != -1) {
- ap_process_child_status(&pid, exitwhy, status);
+ if (ap_process_child_status(&pid, exitwhy, status) == APEXIT_CHILDFATAL) {
+ return 1;
+ }
+
/* non-fatal death... note that it's gone in the scoreboard. */
ap_sync_scoreboard_image();
child_slot = find_child_by_pid(&pid);
diff --git a/server/mpm/spmt_os2/spmt_os2.c b/server/mpm/spmt_os2/spmt_os2.c
index f4ad1db881..350d852415 100644
--- a/server/mpm/spmt_os2/spmt_os2.c
+++ b/server/mpm/spmt_os2/spmt_os2.c
@@ -297,6 +297,7 @@ static void usr1_handler(int sig)
static int volatile shutdown_pending;
static int volatile restart_pending;
static int volatile is_graceful;
+static int volatile child_fatal;
static void sig_term(int sig)
{
@@ -998,7 +999,11 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
if (tid >= 0) {
apr_proc_t dummyproc;
dummyproc.pid = tid;
- ap_process_child_status(&dummyproc, status);
+ if (ap_process_child_status(&dummyproc, status) == APEXIT_CHILDFATAL) {
+ shutdown_pending = 1;
+ child_fatal = 1;
+ break;
+ }
/* non-fatal death... note that it's gone in the scoreboard. */
thread_slot = find_thread_by_tid(tid);
if (thread_slot >= 0) {
@@ -1086,16 +1091,18 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
}
}
- /* cleanup pid file on normal shutdown */
- pidfile = ap_server_root_relative (pconf, ap_pid_fname);
- if ( pidfile != NULL && unlink(pidfile) == 0)
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0,
- ap_server_conf,
- "removed PID file %s (pid=%ld)",
- pidfile, (long)getpid());
-
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
- "caught SIGTERM, shutting down");
+ if (!child_fatal) {
+ /* cleanup pid file on normal shutdown */
+ pidfile = ap_server_root_relative (pconf, ap_pid_fname);
+ if ( pidfile != NULL && unlink(pidfile) == 0)
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0,
+ ap_server_conf,
+ "removed PID file %s (pid=%ld)",
+ pidfile, (long)getpid());
+
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
+ "caught SIGTERM, shutting down");
+ }
return 1;
}
diff --git a/server/mpm/threaded/threaded.c b/server/mpm/threaded/threaded.c
index ad2274d650..4a1498f6ed 100644
--- a/server/mpm/threaded/threaded.c
+++ b/server/mpm/threaded/threaded.c
@@ -1129,7 +1129,11 @@ static void server_main_loop(int remaining_children_to_start)
ap_wait_or_timeout(&exitwhy, &status, &pid, pconf);
if (pid.pid != -1) {
- ap_process_child_status(&pid, exitwhy, status);
+ if (ap_process_child_status(&pid, exitwhy, status) != 0) {
+ /* if we keep this MPM, somebody fix handling of APEXIT_CHILDFATAL */
+ exit(1);
+ }
+
/* non-fatal death... note that it's gone in the scoreboard. */
child_slot = find_child_by_pid(&pid);
if (child_slot >= 0) {
diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c
index 3d0c590c7d..d29e22881c 100644
--- a/server/mpm/worker/worker.c
+++ b/server/mpm/worker/worker.c
@@ -300,6 +300,7 @@ static void just_die(int sig)
static int volatile shutdown_pending;
static int volatile restart_pending;
static int volatile is_graceful;
+static volatile int child_fatal;
ap_generation_t volatile ap_my_generation;
/*
@@ -1178,7 +1179,11 @@ static void server_main_loop(int remaining_children_to_start)
ap_wait_or_timeout(&exitwhy, &status, &pid, pconf);
if (pid.pid != -1) {
- ap_process_child_status(&pid, exitwhy, status);
+ if (ap_process_child_status(&pid, exitwhy, status) == APEXIT_CHILDFATAL) {
+ shutdown_pending = 1;
+ child_fatal = 1;
+ return;
+ }
/* non-fatal death... note that it's gone in the scoreboard. */
child_slot = find_child_by_pid(&pid);
if (child_slot >= 0) {
@@ -1361,9 +1366,9 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGTERM");
}
ap_reclaim_child_processes(1); /* Start with SIGTERM */
-
- /* cleanup pid file on normal shutdown */
- {
+
+ if (!child_fatal) {
+ /* cleanup pid file on normal shutdown */
const char *pidfile = NULL;
pidfile = ap_server_root_relative (pconf, ap_pid_fname);
if ( pidfile != NULL && unlink(pidfile) == 0)
@@ -1371,11 +1376,10 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
ap_server_conf,
"removed PID file %s (pid=%ld)",
pidfile, (long)getpid());
- }
-
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
- "caught SIGTERM, shutting down");
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
+ ap_server_conf, "caught SIGTERM, shutting down");
+ }
return 1;
}
diff --git a/server/mpm_common.c b/server/mpm_common.c
index f066549639..e353f1c321 100644
--- a/server/mpm_common.c
+++ b/server/mpm_common.c
@@ -225,21 +225,24 @@ void ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode, apr_proc_t *ret,
#endif /* AP_MPM_WANT_WAIT_OR_TIMEOUT */
#ifdef AP_MPM_WANT_PROCESS_CHILD_STATUS
-void ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status)
+int ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status)
{
int signum = status;
const char *sigdesc = apr_signal_get_description(signum);
/* Child died... if it died due to a fatal error,
- * we should simply bail out.
- */
+ * we should simply bail out. The caller needs to
+ * check for bad rc from us and exit, running any
+ * appropriate cleanups.
+ */
if ((APR_PROC_CHECK_EXIT(why)) &&
(status == APEXIT_CHILDFATAL)) {
ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, 0, ap_server_conf,
- "Child %ld returned a Fatal error..." APR_EOL_STR
- "Apache is exiting!",
- (long)pid->pid);
- exit(APEXIT_CHILDFATAL);
+ "Child %" APR_OS_PROC_T_FMT
+ " returned a Fatal error..." APR_EOL_STR
+ "Apache is exiting!",
+ pid->pid);
+ return APEXIT_CHILDFATAL;
}
if (APR_PROC_CHECK_SIGNALED(why)) {