]> granicus.if.org Git - apache/commitdiff
Fix the mpmt_pthread MPM to use an APR pipe for the pipe of death. This
authorRyan Bloom <rbb@apache.org>
Fri, 23 Jun 2000 18:12:44 +0000 (18:12 +0000)
committerRyan Bloom <rbb@apache.org>
Fri, 23 Jun 2000 18:12:44 +0000 (18:12 +0000)
allows us to use APR_SOCKETS_AS_FILES to poll on an APR socket.  Finally,
this makes the MPM more portable, because it is now always possible to set
the pipe to be non-blocking.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85676 13f79535-47bb-0310-9956-ffa450edef68

server/mpm/mpmt_pthread/mpm.h
server/mpm/mpmt_pthread/mpmt_pthread.c

index 33497a1979a945d9e2a007a75a43516351c8a951..455e3c5545d89d496c7477dfd6a35d55c85db306 100644 (file)
@@ -65,7 +65,6 @@
 
 extern int ap_threads_per_child;
 extern int ap_max_requests_per_child;
-extern int ap_pipe_of_death[2];
 extern int ap_extended_status;
 extern int ap_max_daemons_limit;
 extern int ap_my_pid;
index 1268eefbc97126887e44d26535b75fe845b1475e..a0c2e29e60e15e8ddaf5efe6c6a8f2fd1ebd0dc1 100644 (file)
@@ -123,7 +123,8 @@ int ap_max_daemons_limit = -1;
 
 static char ap_coredump_dir[MAX_STRING_LEN];
 
-int pipe_of_death[2];
+static ap_file_t *pipe_of_death_in = NULL;
+static ap_file_t *pipe_of_death_out = NULL;
 static pthread_mutex_t pipe_of_death_mutex;
 
 /* *Non*-shared http_main globals... */
@@ -736,19 +737,9 @@ static void child_main(int child_num_arg)
     /* Set up the pollfd array */
     listensocks = ap_pcalloc(pchild,
                            sizeof(*listensocks) * (num_listensocks + 1));
-
-    /* It is a horrible crime to use ap_create_tcp_socket() here, but it
-     * keeps ap_put_os_sock() from doing getsockname() on the pipe of death
-     * (which won't work).
-     * TODO - remove the need for such a hack!  Jeff owns this problem.
-     */
-    ap_create_tcp_socket(&listensocks[0], pchild);
-    rv = ap_put_os_sock(&listensocks[0], &pipe_of_death[0], pchild);
-    if (rv != APR_SUCCESS) {
-        ap_log_error(APLOG_MARK, APLOG_ALERT, rv, ap_server_conf,
-                     "ap_put_os_sock() failed for the pipe of death");
-        clean_child_exit(APEXIT_CHILDFATAL);
-    }
+#if APR_FILES_AS_SOCKETS
+    ap_socket_from_file(&listensocks[0], pipe_of_death_in);
+#endif
     for (lr = ap_listeners, i = 1; i <= num_listensocks; lr = lr->next, ++i)
        listensocks[i]=lr->sd;
 
@@ -921,6 +912,7 @@ static void perform_idle_server_maintenance(void)
     int free_slots[MAX_SPAWN_RATE];
     int last_non_dead;
     int total_non_dead;
+    int one = 1;
 
     /* initialize the free_list */
     free_length = 0;
@@ -975,7 +967,7 @@ static void perform_idle_server_maintenance(void)
     if (idle_thread_count > max_spare_threads) {
         /* Kill off one child */
         char char_of_death = '!';
-        if (write(pipe_of_death[1], &char_of_death, 1) == -1) {
+        if (ap_write(pipe_of_death_out, &char_of_death, &one) != APR_SUCCESS) {
             ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "write pipe_of_death");
         }
         idle_spawn_rate = 1;
@@ -1095,17 +1087,18 @@ int ap_mpm_run(ap_pool_t *_pconf, ap_pool_t *plog, server_rec *s)
 {
     int remaining_children_to_start;
     ap_status_t rv;
+    int one = 1;
 
     pconf = _pconf;
     ap_server_conf = s;
-    if (pipe(pipe_of_death) == -1) {
+    if (ap_create_pipe(&pipe_of_death_in, &pipe_of_death_out, pconf) == -1) {
         ap_log_error(APLOG_MARK, APLOG_ERR, errno,
                      (const server_rec*) ap_server_conf,
                      "pipe: (pipe_of_death)");
         exit(1);
     }
 
-    if (fcntl(pipe_of_death[0], F_SETFL, O_NONBLOCK) == -1) {
+    if (ap_set_pipe_timeout(pipe_of_death_in, 0) != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_ERR, errno,
                      (const server_rec*) ap_server_conf,
                      "fcntl: O_NONBLOCKing (pipe_of_death)");
@@ -1224,7 +1217,7 @@ int ap_mpm_run(ap_pool_t *_pconf, ap_pool_t *plog, server_rec *s)
 
        /* give the children the signal to die */
         for (i = 0; i < ap_daemons_limit;) {
-            if (write(pipe_of_death[1], &char_of_death, 1) == -1) {
+            if (ap_write(pipe_of_death_in, &char_of_death, &one) == -1) {
                 if (errno == EINTR) continue;
                 ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "write pipe_of_death");
             }