From: Ryan Bloom Date: Tue, 23 Oct 2001 17:30:07 +0000 (+0000) Subject: Fix the reporting for child processes that die. This removes X-Git-Tag: 2.0.27~38 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dbb19e0e8c5b8774c6227dcef2defb3a80e917cb;p=apache Fix the reporting for child processes that die. This removes all of the non-portable W* macros from Apache. Submitted by: Jeff Trawick and Ryan Bloom git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@91648 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 83a1b3d39f..6f25a3d9e9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,9 @@ Changes with Apache 2.0.27-dev + + *) Fix the reporting for child processes that die. This removes + all of the non-portable W* macros from Apache. + [Jeff Trawick and Ryan Bloom] + *) Win32: Track and display "Parent Server Generation:" in mod_status output. The generation will be bumped at server graceful restart, when the child process exits diff --git a/include/mpm_common.h b/include/mpm_common.h index d75c864afc..5f7b466296 100644 --- a/include/mpm_common.h +++ b/include/mpm_common.h @@ -125,7 +125,8 @@ void ap_reclaim_child_processes(int terminate); * @param p The pool to allocate out of */ #ifdef AP_MPM_WANT_WAIT_OR_TIMEOUT -void ap_wait_or_timeout(apr_wait_t *status, apr_proc_t *ret, apr_pool_t *p); +void ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode, apr_proc_t *ret, + apr_pool_t *p); #endif /** @@ -135,7 +136,7 @@ void ap_wait_or_timeout(apr_wait_t *status, apr_proc_t *ret, apr_pool_t *p); * @param status The status returned from ap_wait_or_timeout */ #ifdef AP_MPM_WANT_PROCESS_CHILD_STATUS -void ap_process_child_status(apr_proc_t *pid, apr_wait_t status); +void ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status); #endif #if defined(TCP_NODELAY) && !defined(MPE) && !defined(TPF) diff --git a/server/mpm/beos/beos.c b/server/mpm/beos/beos.c index 2ecbe6d5cb..f94a3198b4 100644 --- a/server/mpm/beos/beos.c +++ b/server/mpm/beos/beos.c @@ -597,16 +597,17 @@ static void perform_idle_server_maintenance(void) static void server_main_loop(int remaining_threads_to_start) { int child_slot; - apr_wait_t status; + apr_exit_why_e exitwhy; + int status; apr_proc_t pid; int i; while (!restart_pending && !shutdown_pending) { - ap_wait_or_timeout(&status, &pid, pconf); + ap_wait_or_timeout(&exitwhy, &status, &pid, pconf); if (pid.pid >= 0) { - ap_process_child_status(&pid, status); + ap_process_child_status(&pid, exitwhy, status); /* non-fatal death... note that it's gone in the scoreboard. */ child_slot = -1; for (i = 0; i < ap_max_child_assigned; ++i) { diff --git a/server/mpm/experimental/perchild/perchild.c b/server/mpm/experimental/perchild/perchild.c index 6c1e1d6b97..21bb3634b4 100644 --- a/server/mpm/experimental/perchild/perchild.c +++ b/server/mpm/experimental/perchild/perchild.c @@ -1091,15 +1091,16 @@ static void perform_child_maintenance(void) static void server_main_loop(int remaining_children_to_start) { int child_slot; - apr_wait_t status; + apr_exit_why exitwhy; + int status; apr_proc_t pid; int i; while (!restart_pending && !shutdown_pending) { - ap_wait_or_timeout(&status, &pid, pconf); + ap_wait_or_timeout(&exitwhy, &status, &pid, pconf); if (pid.pid != -1) { - ap_process_child_status(&pid, status); + ap_process_child_status(&pid, exitwhy, status); /* non-fatal death... note that it's gone in the child table and * clean out the status table. */ child_slot = -1; diff --git a/server/mpm/perchild/perchild.c b/server/mpm/perchild/perchild.c index 6c1e1d6b97..21bb3634b4 100644 --- a/server/mpm/perchild/perchild.c +++ b/server/mpm/perchild/perchild.c @@ -1091,15 +1091,16 @@ static void perform_child_maintenance(void) static void server_main_loop(int remaining_children_to_start) { int child_slot; - apr_wait_t status; + apr_exit_why exitwhy; + int status; apr_proc_t pid; int i; while (!restart_pending && !shutdown_pending) { - ap_wait_or_timeout(&status, &pid, pconf); + ap_wait_or_timeout(&exitwhy, &status, &pid, pconf); if (pid.pid != -1) { - ap_process_child_status(&pid, status); + ap_process_child_status(&pid, exitwhy, status); /* non-fatal death... note that it's gone in the child table and * clean out the status table. */ child_slot = -1; diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index e19c7968de..ee3d6e7bd0 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -369,7 +369,7 @@ AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result) Systems without a real waitpid sometimes lose a child's exit while waiting for another. Search through the scoreboard for missing children. */ -int reap_children(apr_wait_t *status) +int reap_children(int *exitcode, apr_exit_why_e *status) { int n, pid; @@ -379,7 +379,8 @@ int reap_children(apr_wait_t *status) kill((pid = ap_scoreboard_image->parent[n].pid), 0) == -1) { ap_update_child_status(AP_CHILD_THREAD_FROM_ID(n), SERVER_DEAD, NULL); /* just mark it as having a successful exit status */ - memset(status, 0, sizeof(apr_wait_t)); + *status = APR_PROC_EXIT; + *exitcode = 0; return(pid); } } @@ -1171,18 +1172,19 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) while (!restart_pending && !shutdown_pending) { int child_slot; - apr_wait_t status; + apr_exit_why_e exitwhy; + int status; /* this is a memory leak, but I'll fix it later. */ apr_proc_t pid; - ap_wait_or_timeout(&status, &pid, pconf); + ap_wait_or_timeout(&exitwhy, &status, &pid, pconf); /* XXX: if it takes longer than 1 second for all our children * to start up and get into IDLE state then we may spawn an * extra child */ if (pid.pid != -1) { - ap_process_child_status(&pid, status); + ap_process_child_status(&pid, exitwhy, status); /* 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/threaded/threaded.c b/server/mpm/threaded/threaded.c index 8b4f583421..a9f6248c25 100644 --- a/server/mpm/threaded/threaded.c +++ b/server/mpm/threaded/threaded.c @@ -1122,15 +1122,16 @@ static void perform_idle_server_maintenance(void) static void server_main_loop(int remaining_children_to_start) { int child_slot; - apr_wait_t status; + apr_exit_why_e exitwhy; + int status; apr_proc_t pid; int i; while (!restart_pending && !shutdown_pending) { - ap_wait_or_timeout(&status, &pid, pconf); + ap_wait_or_timeout(&exitwhy, &status, &pid, pconf); if (pid.pid != -1) { - ap_process_child_status(&pid, status); + ap_process_child_status(&pid, exitwhy, status); /* 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 a796fc3989..f27f4d7258 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -1187,15 +1187,16 @@ static void perform_idle_server_maintenance(void) static void server_main_loop(int remaining_children_to_start) { int child_slot; - apr_wait_t status; + apr_exit_why_e exitwhy; + int status; apr_proc_t pid; int i; while (!restart_pending && !shutdown_pending) { - ap_wait_or_timeout(&status, &pid, pconf); + ap_wait_or_timeout(&exitwhy, &status, &pid, pconf); if (pid.pid != -1) { - ap_process_child_status(&pid, status); + ap_process_child_status(&pid, exitwhy, status); /* 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_common.c b/server/mpm_common.c index 4ba1c25626..f066549639 100644 --- a/server/mpm_common.c +++ b/server/mpm_common.c @@ -124,7 +124,7 @@ void ap_reclaim_child_processes(int terminate) continue; proc.pid = pid; - waitret = apr_proc_wait(&proc, NULL, APR_NOWAIT); + waitret = apr_proc_wait(&proc, NULL, NULL, APR_NOWAIT); if (waitret != APR_CHILD_NOTDONE) { MPM_NOTE_CHILD_KILLED(i); continue; @@ -196,7 +196,8 @@ void ap_reclaim_child_processes(int terminate) #endif static int wait_or_timeout_counter; -void ap_wait_or_timeout(apr_wait_t *status, apr_proc_t *ret, apr_pool_t *p) +void ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode, apr_proc_t *ret, + apr_pool_t *p) { apr_status_t rv; @@ -204,7 +205,7 @@ void ap_wait_or_timeout(apr_wait_t *status, apr_proc_t *ret, apr_pool_t *p) if (wait_or_timeout_counter == INTERVAL_OF_WRITABLE_PROBES) { wait_or_timeout_counter = 0; } - rv = apr_proc_wait_all_procs(ret, status, APR_NOWAIT, p); + rv = apr_proc_wait_all_procs(ret, exitcode, status, APR_NOWAIT, p); if (APR_STATUS_IS_EINTR(rv)) { ret->pid = -1; return; @@ -213,7 +214,7 @@ void ap_wait_or_timeout(apr_wait_t *status, apr_proc_t *ret, apr_pool_t *p) return; } #ifdef NEED_WAITPID - if ((ret = reap_children(status)) > 0) { + if ((ret = reap_children(exitcode, status)) > 0) { return; } #endif @@ -224,16 +225,16 @@ void ap_wait_or_timeout(apr_wait_t *status, apr_proc_t *ret, apr_pool_t *p) #endif /* AP_MPM_WANT_WAIT_OR_TIMEOUT */ #ifdef AP_MPM_WANT_PROCESS_CHILD_STATUS -void ap_process_child_status(apr_proc_t *pid, apr_wait_t status) +void ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status) { - int signum = WTERMSIG(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. */ - if ((WIFEXITED(status)) && - WEXITSTATUS(status) == APEXIT_CHILDFATAL) { + 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!", @@ -241,7 +242,7 @@ void ap_process_child_status(apr_proc_t *pid, apr_wait_t status) exit(APEXIT_CHILDFATAL); } - if (WIFSIGNALED(status)) { + if (APR_PROC_CHECK_SIGNALED(why)) { switch (signum) { case SIGTERM: case SIGHUP: @@ -249,8 +250,7 @@ void ap_process_child_status(apr_proc_t *pid, apr_wait_t status) case SIGKILL: break; default: -#ifdef WCOREDUMP - if (WCOREDUMP(status)) { + if (APR_PROC_CHECK_CORE_DUMP(why)) { ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf, "child pid %ld exit signal %s (%d), " @@ -258,9 +258,7 @@ void ap_process_child_status(apr_proc_t *pid, apr_wait_t status) (long)pid->pid, sigdesc, signum, ap_coredump_dir); } - else -#endif - { + else { ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf, "child pid %ld exit signal %s (%d)",