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);
#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 */
#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.
*/
{
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;
}
#ifdef APR_HAS_OTHER_CHILD
}
- else if (reap_other_child(pid, status) == 0) {
+ else if (ap_reap_other_child(pid, status) == 0) {
/* handled */
#endif
}
#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 */
#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.
*/
{
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);
}
#ifdef APR_HAS_OTHER_CHILD
}
- else if (reap_other_child(pid, status) == 0) {
+ else if (ap_reap_other_child(pid, status) == 0) {
/* handled */
#endif
}
}
-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;
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);
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) {
-#!/usr/local/bin/perl
+#!/usr/bin/perl
# ====================================================================
# The Apache Software License, Version 1.1
#