]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Create work-in-progress branch
authorJim Jagielski <jim@apache.org>
Fri, 1 Jun 2007 19:28:31 +0000 (19:28 +0000)
committerJim Jagielski <jim@apache.org>
Fri, 1 Jun 2007 19:28:31 +0000 (19:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/httpd-pid-table@543583 13f79535-47bb-0310-9956-ffa450edef68

15 files changed:
include/mpm_common.h
server/main.c
server/mpm/beos/mpm.h
server/mpm/experimental/event/event.c
server/mpm/experimental/event/mpm.h
server/mpm/experimental/leader/mpm.h
server/mpm/experimental/perchild/mpm.h
server/mpm/experimental/threadpool/mpm.h
server/mpm/netware/mpm.h
server/mpm/prefork/mpm.h
server/mpm/prefork/prefork.c
server/mpm/worker/mpm.h
server/mpm/worker/worker.c
server/mpm_common.c
server/scoreboard.c

index 20a74ac6424d04c9f9d8d8597f09147765226703..1b69fb5e4cdb273dc7c6aa9a83c3a77cef6f638c 100644 (file)
@@ -349,6 +349,14 @@ extern const char *ap_mpm_set_exception_hook(cmd_parms *cmd, void *dummy,
                                              const char *arg);
 #endif
 
+/*
+ * The parent process pid table
+ */
+extern apr_table_t *ap_pid_table;
+int ap_in_pid_table(pid_t pid);
+void ap_set_pid_table(pid_t pid);
+void ap_unset_pid_table(pid_t pid);
+
 AP_DECLARE_HOOK(int,monitor,(apr_pool_t *p))
 
 #ifdef __cplusplus
index 7285eae1a0e08f3832d485e71324d9f3525c0219..f8a90a75f6eacfdcdcfe48fbee39754959aecefb 100644 (file)
@@ -480,6 +480,7 @@ int main(int argc, const char * const argv[])
     ap_server_pre_read_config  = apr_array_make(pcommands, 1, sizeof(char *));
     ap_server_post_read_config = apr_array_make(pcommands, 1, sizeof(char *));
     ap_server_config_defines   = apr_array_make(pcommands, 1, sizeof(char *));
+    ap_pid_table               = apr_table_make(pglobal, 1024);
 
     error = ap_setup_prelinked_modules(process);
     if (error) {
index d61594b0603ab1b4aa3b506f81998b0dc2a8af30..cadf36521a0063fb5946028ae9af3685d375383f 100644 (file)
 
 #define MPM_NAME "Beos"
 #define MPM_CHILD_PID(i) (ap_scoreboard_image->servers[0][i].tid)
-#define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0)
+#define MPM_NOTE_CHILD_KILLED(i) do {         \
+        ap_unset_pid_table(MPM_CHILD_PID(i)); \
+        MPM_CHILD_PID(i) = 0;                 \
+    } while(0) 
 
 #define AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
 #define AP_MPM_WANT_WAIT_OR_TIMEOUT
index 417f360cc13a49f201c0e7fee1ae91c939ba298f..7729af61803b5fa3b5edc29b3f34f4279670c46e 100644 (file)
@@ -1643,6 +1643,7 @@ static int make_child(server_rec * s, int slot)
     /* else */
     ap_scoreboard_image->parent[slot].quiescing = 0;
     ap_scoreboard_image->parent[slot].pid = pid;
+    ap_set_pid_table(pid);
     return 0;
 }
 
@@ -2062,10 +2063,13 @@ int ap_mpm_run(apr_pool_t * _pconf, apr_pool_t * plog, server_rec * s)
             active_children = 0;
             for (index = 0; index < ap_daemons_limit; ++index) {
                 if (MPM_CHILD_PID(index) != 0) {
-                    if (kill(MPM_CHILD_PID(index), 0) == 0) {
+                    if (ap_in_pid_table(MPM_CHILD_PID(index))) {
+                        if (kill(MPM_CHILD_PID(index), 0) == 0) {
                             active_children = 1;
+                            ap_unset_pid_table(MPM_CHILD_PID(index));
                             /* Having just one child is enough to stay around */
                             break;
+                        }
                     }
                 }
             }
index cf4e61d911519b6d22028b754e4db4c16f3fef09..c2731afd8c9962a79c2dd5e9e5a6ef8470720b2b 100644 (file)
 #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK
 
 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
-#define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0)
+#define MPM_NOTE_CHILD_KILLED(i) do {         \
+        ap_unset_pid_table(MPM_CHILD_PID(i)); \
+        MPM_CHILD_PID(i) = 0;                 \
+    } while(0) 
 #define MPM_ACCEPT_FUNC unixd_accept
 
 extern int ap_threads_per_child;
index d30be86a1fd0536f49a14edb06e6fee5966ff9d0..680c9ca6912cd0ad5a476b686734c61d128b234a 100644 (file)
 
 #define AP_MPM_USES_POD 1
 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
-#define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0)
+#define MPM_NOTE_CHILD_KILLED(i) do {         \
+        ap_unset_pid_table(MPM_CHILD_PID(i)); \
+        MPM_CHILD_PID(i) = 0;                 \
+    } while(0) 
 #define MPM_ACCEPT_FUNC unixd_accept
 
 extern int ap_threads_per_child;
index af9723872871c2a1dfec16e0cbbe00465ad92e75..c54863efe390443b6b601aa76e6b788767a6dc0f 100644 (file)
 #define AP_MPM_USES_POD
 
 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
-#define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0)
+#define MPM_NOTE_CHILD_KILLED(i) do {         \
+        ap_unset_pid_table(MPM_CHILD_PID(i)); \
+        MPM_CHILD_PID(i) = 0;                 \
+    } while(0) 
 #define MPM_ACCEPT_FUNC unixd_accept
 
 /* Table of child status */
index 806011b88570498a1c147776cce62d73c2c644f1..624f37c89a56d61c796416fc7bd332bf094633f6 100644 (file)
 #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK
 
 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
-#define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0)
+#define MPM_NOTE_CHILD_KILLED(i) do {         \
+        ap_unset_pid_table(MPM_CHILD_PID(i)); \
+        MPM_CHILD_PID(i) = 0;                 \
+    } while(0) 
 #define MPM_ACCEPT_FUNC unixd_accept
 
 extern int ap_threads_per_child;
index 106d62a5095894277d61d3134bad529c99b96ea7..93f1824e5a567714086ea73a5b6e32b60b88b7ad 100644 (file)
 */
 
 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
-#define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0)
+#define MPM_NOTE_CHILD_KILLED(i) do {         \
+        ap_unset_pid_table(MPM_CHILD_PID(i)); \
+        MPM_CHILD_PID(i) = 0;                 \
+    } while(0) 
 
 extern int ap_threads_per_child;
 extern int ap_max_workers_limit;
index bf1fb949996fe8adc21b92ca8eacbe72dd8e27fc..51743d2ccaedc7e75b4fa609d7e7b90a094a3455 100644 (file)
 
 #define AP_MPM_USES_POD 1
 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
-#define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0)
+#define MPM_NOTE_CHILD_KILLED(i) do {         \
+        ap_unset_pid_table(MPM_CHILD_PID(i)); \
+        MPM_CHILD_PID(i) = 0;                 \
+    } while(0) 
 #define MPM_ACCEPT_FUNC unixd_accept
 
 extern int ap_threads_per_child;
index 31c19df84f8d7d0bf2e023e301b71c7a20f357af..6a51f657f7d2b57648742b158e96e16845cb38f2 100644 (file)
@@ -305,13 +305,18 @@ int reap_children(int *exitcode, apr_exit_why_e *status)
     int n, pid;
 
     for (n = 0; n < ap_max_daemons_limit; ++n) {
-        if (ap_scoreboard_image->servers[n][0].status != SERVER_DEAD &&
-                kill((pid = ap_scoreboard_image->parent[n].pid), 0) == -1) {
-            ap_update_child_status_from_indexes(n, 0, SERVER_DEAD, NULL);
-            /* just mark it as having a successful exit status */
-            *status = APR_PROC_EXIT;
-            *exitcode = 0;
-            return(pid);
+        pid = ap_scoreboard_image->parent[n].pid;
+        if (ap_scoreboard_image->servers[n][0].status != SERVER_DEAD) {
+            if (ap_in_pid_table(pid)) {
+                if (kill(pid, 0) == -1) {
+                    ap_update_child_status_from_indexes(n, 0, SERVER_DEAD, NULL);
+                    /* just mark it as having a successful exit status */
+                    *status = APR_PROC_EXIT;
+                    *exitcode = 0;
+                    ap_unset_pid_table(pid);
+                    return(pid);
+                }
+            }
         }
     }
     return 0;
@@ -737,6 +742,7 @@ static int make_child(server_rec *s, int slot)
     }
 
     ap_scoreboard_image->parent[slot].pid = pid;
+    ap_set_pid_table(pid);
 
     return 0;
 }
@@ -1119,8 +1125,10 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
         for (index = 0; index < ap_daemons_limit; ++index) {
             if (ap_scoreboard_image->servers[index][0].status != SERVER_DEAD) {
                 /* Ask each child to close its listeners. */
-                kill(MPM_CHILD_PID(index), AP_SIG_GRACEFUL);
-                active_children++;
+                if (ap_in_pid_table(MPM_CHILD_PID(index))) {
+                    kill(MPM_CHILD_PID(index), AP_SIG_GRACEFUL);
+                    active_children++;
+                }
             }
         }
 
@@ -1158,10 +1166,12 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
             active_children = 0;
             for (index = 0; index < ap_daemons_limit; ++index) {
                 if (MPM_CHILD_PID(index) != 0) {
-                    if (kill(MPM_CHILD_PID(index), 0) == 0) {
+                    if (ap_in_pid_table(MPM_CHILD_PID(index))) {
+                        if (kill(MPM_CHILD_PID(index), 0) == 0) {
                             active_children = 1;
                             /* Having just one child is enough to stay around */
                             break;
+                        }
                     }
                 }
             }
@@ -1214,7 +1224,9 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
                  * piped loggers, etc. They almost certainly won't handle
                  * it gracefully.
                  */
-                kill(ap_scoreboard_image->parent[index].pid, AP_SIG_GRACEFUL);
+                if (ap_in_pid_table(MPM_CHILD_PID(index))) {
+                    kill(MPM_CHILD_PID(index), AP_SIG_GRACEFUL);
+                }
             }
         }
     }
index 335f4b6ace40aef35162eb42749ff2c88b08a762..a8585d375ee6d59972123c62e2845847b26f6204 100644 (file)
 #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK
 
 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
-#define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0)
+#define MPM_NOTE_CHILD_KILLED(i) do {         \
+        ap_unset_pid_table(MPM_CHILD_PID(i)); \
+        MPM_CHILD_PID(i) = 0;                 \
+    } while(0) 
 #define MPM_ACCEPT_FUNC unixd_accept
 
 extern int ap_threads_per_child;
index e8eca8c197ad5391d12d3a6e01f71f8461c623a8..0185002d48941ee1dda6f8fdc6212a496ff8ce27 100644 (file)
@@ -1360,6 +1360,8 @@ static int make_child(server_rec *s, int slot)
     }
     ap_scoreboard_image->parent[slot].quiescing = 0;
     ap_scoreboard_image->parent[slot].pid = pid;
+    ap_set_pid_table(pid);
+
     return 0;
 }
 
@@ -1600,6 +1602,7 @@ static void server_main_loop(int remaining_children_to_start)
                                                         (request_rec *) NULL);
 
                 ap_scoreboard_image->parent[child_slot].pid = 0;
+                ap_unset_pid_table(pid);
                 ap_scoreboard_image->parent[child_slot].quiescing = 0;
                 if (processed_status == APEXIT_CHILDSICK) {
                     /* resource shortage, minimize the fork rate */
@@ -1816,10 +1819,12 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
             active_children = 0;
             for (index = 0; index < ap_daemons_limit; ++index) {
                 if (MPM_CHILD_PID(index) != 0) {
-                    if (kill(MPM_CHILD_PID(index), 0) == 0) {
+                    if (ap_in_pid_table(MPM_CHILD_PID(index))) {
+                        if (kill(MPM_CHILD_PID(index), 0) == 0) {
                             active_children = 1;
                             /* Having just one child is enough to stay around */
                             break;
+                        }
                     }
                 }
             }
index 832cc4084b427bc24c6480de89ca3591eab9c906..f99e70c4d826aace9b809c01026a7f74a58d160e 100644 (file)
@@ -87,6 +87,41 @@ typedef struct extra_process_t {
 
 static extra_process_t *extras;
 
+/*
+ * Parent process local storage of child pids
+ */
+apr_table_t *ap_pid_table;
+
+/*
+ * Check the pid table to see if the actual pid exists
+ */
+int ap_in_pid_table(pid_t pid) {
+    char apid[64];
+    const char *spid;
+    snprintf(apid, sizeof(apid), "%" APR_PID_T_FMT, pid);
+    spid = apr_table_get(ap_pid_table, apid);
+    if (spid && spid[0] == '1' && spid[1] == '\0')
+        return 1;
+    else {
+        ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
+                     "child process %" APR_PID_T_FMT
+                     " does not exist in local pid table", pid);
+        return 0;
+    }
+}
+
+void ap_set_pid_table(pid_t pid) {
+    char apid[64];
+    snprintf(apid, sizeof(apid), "%" APR_PID_T_FMT, pid);
+    apr_table_set(ap_pid_table, apid, "1");
+}
+
+void ap_unset_pid_table(pid_t pid) {
+    char apid[64];
+    snprintf(apid, sizeof(apid), "%" APR_PID_T_FMT, pid);
+    apr_table_unset(ap_pid_table, apid);
+}
+
 void ap_register_extra_mpm_process(pid_t pid)
 {
     extra_process_t *p = (extra_process_t *)malloc(sizeof(extra_process_t));
@@ -128,6 +163,9 @@ static int reclaim_one_pid(pid_t pid, action_t action)
     apr_status_t waitret;
 
     proc.pid = pid;
+    if (!ap_in_pid_table(pid)) {
+        return 0;
+    }
     waitret = apr_proc_wait(&proc, NULL, NULL, APR_NOWAIT);
     if (waitret != APR_CHILD_NOTDONE) {
         return 1;
index 99238bac236e1d015532c65f768d36bfa5e2150c..2e00452c95c7a4744e5f122307101c2991d6a858 100644 (file)
@@ -35,6 +35,7 @@
 #include "ap_mpm.h"
 
 #include "mpm.h"
+#include "mpm_common.h"
 #include "scoreboard.h"
 
 AP_DECLARE_DATA scoreboard *ap_scoreboard_image = NULL;
@@ -363,7 +364,8 @@ int find_child_by_pid(apr_proc_t *pid)
     ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit);
 
     for (i = 0; i < max_daemons_limit; ++i) {
-        if (ap_scoreboard_image->parent[i].pid == pid->pid) {
+        if (ap_scoreboard_image->parent[i].pid == pid->pid &&
+            ap_in_pid_table(pid->pid)) {
             return i;
         }
     }