From fcc4d8c6691504b61980fabfa883a3ea09a94de2 Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Thu, 4 May 2000 19:42:57 +0000 Subject: [PATCH] Port reliable piped logs to mpmt_pthread and dexter. Also a couple of small cleanups for reliable piped logs. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85137 13f79535-47bb-0310-9956-ffa450edef68 --- server/log.c | 7 +++++ server/mpm/dexter/dexter.c | 42 ++++++++++++++++---------- server/mpm/mpmt_pthread/mpmt_pthread.c | 39 +++++++++++++++--------- server/mpm/mpmt_pthread/scoreboard.c | 7 +++-- server/mpm/mpmt_pthread/scoreboard.h | 2 +- server/mpm/prefork/prefork.c | 4 +-- support/apxs.in | 2 +- 7 files changed, 66 insertions(+), 37 deletions(-) diff --git a/server/log.c b/server/log.c index 2d3e87f7ca..3ccf6b4fde 100644 --- a/server/log.c +++ b/server/log.c @@ -636,6 +636,13 @@ static void piped_log_maintenance(int reason, void *data, ap_wait_t status) switch (reason) { case APR_OC_REASON_DEATH: + pl->pid = NULL; + ap_unregister_other_child(pl); + if (pl->program == NULL) { + /* during a restart */ + break; + } + break; case APR_OC_REASON_LOST: pl->pid = NULL; ap_unregister_other_child(pl); diff --git a/server/mpm/dexter/dexter.c b/server/mpm/dexter/dexter.c index 0f04013bc0..933482bc07 100644 --- a/server/mpm/dexter/dexter.c +++ b/server/mpm/dexter/dexter.c @@ -275,29 +275,35 @@ static void reclaim_child_processes(int terminate) #endif static int wait_or_timeout_counter; -static int wait_or_timeout(ap_wait_t *status) +static ap_proc_t *wait_or_timeout(ap_wait_t *status, ap_pool_t *p) { struct timeval tv; - int ret; + ap_status_t rv; + ap_proc_t *ret = NULL; ++wait_or_timeout_counter; if (wait_or_timeout_counter == INTERVAL_OF_WRITABLE_PROBES) { - wait_or_timeout_counter = 0; + wait_or_timeout_counter = 0; #ifdef APR_HAS_OTHER_CHILD - probe_writable_fds(); + ap_probe_writable_fds(); #endif } - ret = waitpid(-1, status, WNOHANG); - if (ret == -1 && errno == EINTR) { - return -1; + rv = ap_wait_all_procs(&ret, APR_NOWAIT, p); + if (ap_canonical_error(rv) == APR_EINTR) { + return NULL; } - if (ret > 0) { - return ret; + if (rv == APR_CHILD_DONE) { + return ret; } +#ifdef NEED_WAITPID + if ((ret = reap_children(status)) > 0) { + return ret; + } +#endif tv.tv_sec = SCOREBOARD_MAINTENANCE_INTERVAL / 1000000; tv.tv_usec = SCOREBOARD_MAINTENANCE_INTERVAL % 1000000; ap_select(0, NULL, NULL, NULL, &tv); - return -1; + return NULL; } /* handle all varieties of core dumping signals */ @@ -489,8 +495,10 @@ static void set_signals(void) #endif } -static void process_child_status(int pid, ap_wait_t status) +static void process_child_status(ap_proc_t *abs_pid, ap_wait_t status) { + int pid; + ap_get_os_proc(&pid, abs_pid); /* Child died... if it died due to a fatal error, * we should simply bail out. */ @@ -1077,19 +1085,21 @@ static void server_main_loop(int remaining_children_to_start) { int child_slot; ap_wait_t status; - int pid; + ap_proc_t *pid; int i; while (!restart_pending && !shutdown_pending) { - pid = wait_or_timeout(&status); + pid = wait_or_timeout(&status, pconf); - if (pid >= 0) { + if (pid != NULL) { + int actual_pid; + ap_get_os_proc(&actual_pid, pid); process_child_status(pid, status); /* non-fatal death... note that it's gone in the child table and * clean out the status table. */ child_slot = -1; for (i = 0; i < max_daemons_limit; ++i) { - if (child_table[i].pid == pid) { + if (child_table[i].pid == actual_pid) { int j; child_slot = i; @@ -1112,7 +1122,7 @@ static void server_main_loop(int remaining_children_to_start) } #ifdef APR_HAS_OTHER_CHILD } - else if (reap_other_child(pid, status) == 0) { + else if (ap_reap_other_child(pid, status) == 0) { /* handled */ #endif } diff --git a/server/mpm/mpmt_pthread/mpmt_pthread.c b/server/mpm/mpmt_pthread/mpmt_pthread.c index 59604438ea..e78d354a0b 100644 --- a/server/mpm/mpmt_pthread/mpmt_pthread.c +++ b/server/mpm/mpmt_pthread/mpmt_pthread.c @@ -271,29 +271,35 @@ static void reclaim_child_processes(int terminate) #endif static int wait_or_timeout_counter; -static int wait_or_timeout(ap_wait_t *status) +static ap_proc_t *wait_or_timeout(ap_wait_t *status, ap_pool_t *p) { struct timeval tv; - int ret; + ap_status_t rv; + ap_proc_t *ret = NULL; ++wait_or_timeout_counter; if (wait_or_timeout_counter == INTERVAL_OF_WRITABLE_PROBES) { - wait_or_timeout_counter = 0; + wait_or_timeout_counter = 0; #ifdef APR_HAS_OTHER_CHILD - probe_writable_fds(); + ap_probe_writable_fds(); #endif } - ret = waitpid(-1, status, WNOHANG); - if (ret == -1 && errno == EINTR) { - return -1; + rv = ap_wait_all_procs(&ret, APR_NOWAIT, p); + if (ap_canonical_error(rv) == APR_EINTR) { + return NULL; } - if (ret > 0) { - return ret; + if (rv == APR_CHILD_DONE) { + return ret; } +#ifdef NEED_WAITPID + if ((ret = reap_children(status)) > 0) { + return ret; + } +#endif tv.tv_sec = SCOREBOARD_MAINTENANCE_INTERVAL / 1000000; tv.tv_usec = SCOREBOARD_MAINTENANCE_INTERVAL % 1000000; ap_select(0, NULL, NULL, NULL, &tv); - return -1; + return NULL; } /* handle all varieties of core dumping signals */ @@ -486,8 +492,10 @@ static void set_signals(void) #endif } -static void process_child_status(int pid, ap_wait_t status) +static void process_child_status(ap_proc_t *abs_pid, ap_wait_t status) { + int pid; + ap_get_os_proc(&pid, abs_pid); /* Child died... if it died due to a fatal error, * we should simply bail out. */ @@ -1110,13 +1118,14 @@ static void server_main_loop(int remaining_children_to_start) { int child_slot; ap_wait_t status; - int pid; + ap_proc_t *pid; int i; while (!restart_pending && !shutdown_pending) { - pid = wait_or_timeout(&status); + /* this is a memory leak, but I'll fix it later. */ + pid = wait_or_timeout(&status, pconf); - if (pid >= 0) { + if (pid != NULL) { process_child_status(pid, status); /* non-fatal death... note that it's gone in the scoreboard. */ child_slot = find_child_by_pid(pid); @@ -1135,7 +1144,7 @@ static void server_main_loop(int remaining_children_to_start) } #ifdef APR_HAS_OTHER_CHILD } - else if (reap_other_child(pid, status) == 0) { + else if (ap_reap_other_child(pid, status) == 0) { /* handled */ #endif } diff --git a/server/mpm/mpmt_pthread/scoreboard.c b/server/mpm/mpmt_pthread/scoreboard.c index f112c5ce58..8a1a1d7dfd 100644 --- a/server/mpm/mpmt_pthread/scoreboard.c +++ b/server/mpm/mpmt_pthread/scoreboard.c @@ -201,13 +201,16 @@ void increment_counts(int child_num, int thread_num, request_rec *r) } -API_EXPORT(int) find_child_by_pid(int pid) +API_EXPORT(int) find_child_by_pid(ap_proc_t *pid) { int i; + int actual_pid; + int max_daemons_limit = ap_get_max_daemons(); + ap_get_os_proc(&actual_pid, pid); for (i = 0; i < max_daemons_limit; ++i) - if (ap_scoreboard_image->parent[i].pid == pid) + if (ap_scoreboard_image->parent[i].pid == actual_pid) return i; return -1; diff --git a/server/mpm/mpmt_pthread/scoreboard.h b/server/mpm/mpmt_pthread/scoreboard.h index c601d4804f..9d64c9a191 100644 --- a/server/mpm/mpmt_pthread/scoreboard.h +++ b/server/mpm/mpmt_pthread/scoreboard.h @@ -234,7 +234,7 @@ API_EXPORT(void) reopen_scoreboard(ap_pool_t *p); ap_inline void ap_sync_scoreboard_image(void); void increment_counts(int child_num, int thread_num, request_rec *r); void update_scoreboard_global(void); -API_EXPORT(int) find_child_by_pid(int pid); +API_EXPORT(int) find_child_by_pid(ap_proc_t *pid); int ap_update_child_status(int child_num, int thread_num, int status, request_rec *r); void ap_time_process_request(int child_num, int thread_num, int status); diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 052a76a503..61b9e02f76 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -1162,8 +1162,8 @@ static ap_proc_t *wait_or_timeout(ap_wait_t *status, ap_pool_t *p) ap_probe_writable_fds(); #endif } - rv = ap_wait_all_procs(&ret, WNOHANG, p); - if (rv != -1 && rv == APR_CHILD_NOTDONE) { + rv = ap_wait_all_procs(&ret, APR_NOWAIT, p); + if (ap_canonical_error(rv) == APR_EINTR) { return NULL; } if (rv == APR_CHILD_DONE) { diff --git a/support/apxs.in b/support/apxs.in index eb3e2d184a..9320b05168 100644 --- a/support/apxs.in +++ b/support/apxs.in @@ -1,4 +1,4 @@ -#!/usr/local/bin/perl +#!/usr/bin/perl # ==================================================================== # The Apache Software License, Version 1.1 # -- 2.50.1