]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Backport of pid table code from trunk & 2.2 to the 2.0 tree. httpd-2.0-pid-table httpd-2.0-pid-table
authorJim Jagielski <jim@apache.org>
Wed, 13 Jun 2007 23:09:11 +0000 (23:09 +0000)
committerJim Jagielski <jim@apache.org>
Wed, 13 Jun 2007 23:09:11 +0000 (23:09 +0000)
Create dev branch for this before we fold in

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/httpd-2.0-pid-table@547059 13f79535-47bb-0310-9956-ffa450edef68

12 files changed:
include/mpm_common.h
server/main.c
server/mpm/beos/mpm.h
server/mpm/mpmt_os2/mpm.h
server/mpm/mpmt_os2/mpmt_os2.c
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 68ead5f7d79734bfb4441a65fc0d7830ace26cff..34d65fc05f19072c3cfb291ee5a12cf5ba071caa 100644 (file)
@@ -260,6 +260,14 @@ const char *ap_mpm_set_scoreboard(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); 
+
 /*
  * The directory that the server changes directory to dump core.
  */
index 7007ce8c046ffbaa86656e5ef400b2f7921b3cf0..8a0e9ab2a87a6e8f0ce9d6bb4fee52ba52d2bc07 100644 (file)
@@ -404,6 +404,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);
 
     ap_setup_prelinked_modules(process);
 
index 57221b1c65422f0d0c6e1af42200ba508572b7e2..d139f157800250972329ff61adf4c65cd4109149 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 15f341ddfd0b00432155811f02be0f1ec8afc0fc..507bfd91d118b028706a9087b7bd7f20471c0e75 100644 (file)
@@ -22,6 +22,7 @@
 #include "httpd.h"
 #include "mpm_default.h"
 #include "scoreboard.h"
+#include "mpm_common.h"
 
 #define MPM_NAME "MPMT_OS2"
 
index 2c7f57bf23d2084634f0e636f64abc9c0a8e1563..b98699c9f66d555d9a55b2bfb227c4cb63cf5b26 100644 (file)
@@ -281,6 +281,7 @@ static char master_main()
 #endif
     if (one_process) {
         ap_scoreboard_image->parent[0].pid = getpid();
+        ap_set_pid_table(getpid());
         ap_mpm_child_main(pconf);
         return FALSE;
     }
@@ -307,6 +308,7 @@ static char master_main()
         rc = DosWaitChild(DCWA_PROCESSTREE, DCWW_NOWAIT, &proc_rc, &child_pid, 0);
 
         if (rc == 0) {
+            ap_unset_pid_table(child_pid);
             /* A child has terminated, remove its scoreboard entry & terminate if necessary */
             for (slot=0; ap_scoreboard_image->parent[slot].pid != child_pid && slot < HARD_SERVER_LIMIT; slot++);
 
@@ -330,7 +332,13 @@ static char master_main()
 
     /* Signal children to shut down, either gracefully or immediately */
     for (slot=0; slot<HARD_SERVER_LIMIT; slot++) {
-      kill(ap_scoreboard_image->parent[slot].pid, is_graceful ? SIGHUP : SIGTERM);
+        PID pid;
+
+        pid = ap_scoreboard_image->parent[n].pid;
+        if (ap_in_pid_table(pid)) {
+            kill(pid, is_graceful ? SIGHUP : SIGTERM);
+            ap_unset_pid_table(pid);
+        }
     }
 
     DosFreeMem(parent_info);
@@ -364,6 +372,7 @@ static void spawn_child(int slot)
     }
 
     ap_scoreboard_image->parent[slot].pid = proc_rc.codeTerminate;
+    ap_set_pid_table(proc_rc.codeTerminate);
 }
 
 
index 4b9a839204d120d6132eba96f708819a60370521..0eeea2091c12c15c45572ef635964715891ccc16 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_thread_stack_size;
index 51f810b39fc1cde1b0e2fdae1e5b1d92e60484ad..c89386e9b13631870677331439d986ecb8766879 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 8667b4ab51a845f2976f2e97a7fd45336d69d844..5f4aa6b603da1159159d3e83ad2d84f26b203057 100644 (file)
@@ -303,14 +303,19 @@ 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;
 }
@@ -705,6 +710,7 @@ static int make_child(server_rec *s, int slot)
     }
 
     ap_scoreboard_image->parent[slot].pid = pid;
+    ap_set_pid_table(pid);
 
     return 0;
 }
index 31830c6cdbcf41e5322bfb66972d9de6baa9af7a..eb095798ea71f591b1095ad4e81f65515df44916 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 6e0da64720ce9bcc47053df22469b6186f27a7a1..cc78669436d8bf77eaa02b7ded353909f3812d25 100644 (file)
@@ -1297,6 +1297,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;
 }
 
@@ -1527,6 +1529,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.pid);
                 ap_scoreboard_image->parent[child_slot].quiescing = 0;
                 if (processed_status == APEXIT_CHILDSICK) {
                     /* resource shortage, minimize the fork rate */
index b21dc8ad274b54275cfd1955da87d673a279c68b..5f0ee279a68af673d4cb4934dd1555f621127141 100644 (file)
@@ -70,6 +70,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;
+    apr_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];
+    apr_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];
+    apr_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));
@@ -97,6 +132,7 @@ int ap_unregister_extra_mpm_process(pid_t pid)
             extras = cur->next;
         }
         free(cur);
+        ap_unset_pid_table(pid);
         return 1; /* found */
     }
     else {
@@ -111,6 +147,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 c0b0ed05750ded3231c03568e718b0002b5c3821..a867ba113923b83db68f16a0e5aefa6bff713248 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;
@@ -339,7 +340,8 @@ AP_DECLARE(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;
         }
     }