]> granicus.if.org Git - apache/commitdiff
Change the Windows MPM to only use the pre_mpm phase in the parent process.
authorRyan Bloom <rbb@apache.org>
Wed, 30 Jan 2002 22:35:57 +0000 (22:35 +0000)
committerRyan Bloom <rbb@apache.org>
Wed, 30 Jan 2002 22:35:57 +0000 (22:35 +0000)
The child processes use the child_init phase to reattach to the shared
memory.  This makes Windows work like Unix, which should make it easier
for module authors to write portable modules.

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

include/scoreboard.h
server/mpm/prefork/prefork.c
server/mpm/winnt/mpm_winnt.c
server/mpm/worker/worker.c
server/scoreboard.c

index c8c67d7abc08985d21f6a2cd91f3f91ca5214a99..a58dd72e7ad533cde0134f0ebde326a8acdd0441 100644 (file)
@@ -73,6 +73,7 @@ extern "C" {
 #include "apr_hooks.h"
 #include "apr_thread_proc.h"
 #include "apr_portable.h"
+#include "apr_shm.h"
 
 /* Scoreboard info on a process is, for now, kept very brief --- 
  * just status value and pid (the latter so that the caretaker process
@@ -113,8 +114,7 @@ typedef int ap_generation_t;
  */
 typedef enum {
     SB_NOT_SHARED = 1,
-    SB_SHARED = 2,      /* PARENT */
-    SB_SHARED_CHILD = 3
+    SB_SHARED = 2
 } ap_scoreboard_e;
 
 #define SB_WORKING  0  /* The server is busy and the child is useful. */
@@ -185,7 +185,7 @@ AP_DECLARE(int) ap_exists_scoreboard_image(void);
 AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r);
 
 int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
-apr_status_t reopen_scoreboard(apr_pool_t *p, int detached);
+apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached);
 void ap_init_scoreboard(void *shared_score);
 int ap_calc_scoreboard_size(void);
 apr_status_t ap_cleanup_scoreboard(void *d);
index cac1a3b37d9977945cf7af921c7d3198f2e0d25c..78c47a0e9a0926290119dd2483f41fcf231bde5a 100644 (file)
@@ -594,7 +594,7 @@ static void child_main(int child_num_arg)
     apr_pool_tag(ptrans, "transaction");
 
     /* needs to be done before we switch UIDs so we have permissions */
-    reopen_scoreboard(pchild, 0);
+    ap_reopen_scoreboard(pchild, NULL, 0);
     SAFE_ACCEPT(accept_mutex_child_init(pchild));
 
     if (unixd_setup_child()) {
index 040afa86a8313a3b093af36917f002e32311df53..fbbf1dec982c655e185a10f36939502c080dd485 100644 (file)
@@ -67,6 +67,7 @@
 #include "apr_getopt.h"
 #include "apr_strings.h"
 #include "apr_lib.h"
+#include "apr_shm.h"
 #include "ap_mpm.h"
 #include "ap_config.h"
 #include "ap_listen.h"
@@ -281,6 +282,23 @@ static void CleanNullACL( void *sa ) {
     }
 }
 
+static void winnt_child_init(apr_pool_t *pchild, struct server_rec *ap_server_conf)
+{
+    void *sb_shared;
+    int rv;
+
+    rv = ap_reopen_scoreboard(pchild, &ap_scoreboard_shm, 1);
+    if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
+       ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL, "Looks like we're gonna die %d %x", rv, ap_scoreboard_shm);
+        exit(APEXIT_INIT); /* XXX need to return an error from this function */
+    }
+    ap_init_scoreboard(sb_shared);
+
+    ap_scoreboard_image->parent[0].pid = parent_pid;
+    ap_scoreboard_image->parent[0].quiescing = 0;
+}
+
+
 /*
  * The Win32 call WaitForMultipleObjects will only allow you to wait for 
  * a maximum of MAXIMUM_WAIT_OBJECTS (current 64).  Since the threading 
@@ -994,7 +1012,14 @@ static void child_main()
         exit_event = OpenEvent(EVENT_ALL_ACCESS, FALSE, exit_event_name);
         ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf,
                      "Child %d: exit_event_name = %s", my_pid, exit_event_name);
+        /* Set up the scoreboard. */
+        ap_my_generation = atoi(getenv("AP_MY_GENERATION"));
+    ap_log_error(APLOG_MARK, APLOG_CRIT, APR_SUCCESS, ap_server_conf,
+                     "getting listeners child_main", my_pid);        
+        get_listeners_from_parent(ap_server_conf);
     }
+    ap_log_error(APLOG_MARK, APLOG_CRIT, APR_SUCCESS, ap_server_conf,
+                     "in child_main", my_pid);        
 
     /* Initialize the child_events */
     max_requests_per_child_event = CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -2117,7 +2142,6 @@ AP_DECLARE(int) ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s )
             HANDLE sb_os_shm;
             DWORD BytesRead;
             apr_status_t rv;
-
             pipe = GetStdHandle(STD_INPUT_HANDLE);
             if (!ReadFile(pipe, &sb_os_shm, sizeof(sb_os_shm),
                           &BytesRead, (LPOVERLAPPED) NULL)
@@ -2135,18 +2159,14 @@ AP_DECLARE(int) ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s )
                 exit(1);
             }
 
-            if (ap_run_pre_mpm(pconf, SB_SHARED_CHILD) != OK) {
-                exit(1);
-            }
+
             ap_my_generation = atoi(getenv("AP_MY_GENERATION"));
-            get_listeners_from_parent(ap_server_conf);
         }
-        ap_scoreboard_image->parent[0].pid = parent_pid;
-        ap_scoreboard_image->parent[0].quiescing = 0;
-            
+
         if (!set_listeners_noninheritable(pconf)) {
             return 1;
         }
+
         child_main();
 
         ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf,
@@ -2195,6 +2215,7 @@ static void winnt_hooks(apr_pool_t *p)
 {
     ap_hook_pre_config(winnt_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
     ap_hook_post_config(winnt_post_config, NULL, NULL, 0);
+    ap_hook_child_init(winnt_child_init, NULL, NULL, APR_HOOK_MIDDLE);
 }
 
 /* 
index fe7cc4ad0e6e0546df75c1afa46d52cec71f7174..d3f95dfdf32fd9060e4f102e18d72208844f2722 100644 (file)
@@ -874,7 +874,7 @@ static void child_main(int child_num_arg)
     apr_pool_create(&pchild, pconf);
 
     /*stuff to do before we switch id's, so we have permissions.*/
-    reopen_scoreboard(pchild, 0);
+    ap_reopen_scoreboard(pchild, NULL, 0);
 
     rv = SAFE_ACCEPT(apr_proc_mutex_child_init(&accept_mutex, ap_lock_fname,
                                                pchild));
index 23e454151796cffc046ae8337dcaf6e33f4b9547..81a2ed6e17ef5fe038fabed04f9b48f872c41deb 100644 (file)
@@ -143,7 +143,8 @@ void ap_init_scoreboard(void *shared_score)
 {
     char *more_storage;
     int i;
-
+    
+       ap_calc_scoreboard_size();
     ap_scoreboard_image = 
         calloc(1, sizeof(scoreboard) + server_limit * sizeof(worker_score *));
     more_storage = shared_score;
@@ -200,7 +201,7 @@ static apr_status_t open_scoreboard(apr_pool_t *p)
 /* If detach is non-zero, this is a seperate child process,
  * if zero, it is a forked child.
  */
-apr_status_t reopen_scoreboard(apr_pool_t *p, int detached)
+apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached)
 {
 #if APR_HAS_SHARED_MEMORY
     if (!detached) {
@@ -215,6 +216,9 @@ apr_status_t reopen_scoreboard(apr_pool_t *p, int detached)
     }
     /* everything will be cleared shortly */
 #endif
+    if (*shm) {
+        *shm = ap_scoreboard_shm;
+    }
     return APR_SUCCESS;
 }
 
@@ -260,14 +264,6 @@ int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
             memset(sb_shared, 0, scoreboard_size);
             ap_init_scoreboard(sb_shared);
         }
-        else if (sb_type == SB_SHARED_CHILD) {
-            void *sb_shared;
-            rv = reopen_scoreboard(p, 1);
-            if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
-                return HTTP_INTERNAL_SERVER_ERROR;
-            }
-            ap_init_scoreboard(sb_shared);
-        }
         else 
 #endif
         {
@@ -282,14 +278,10 @@ int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
             ap_init_scoreboard(sb_mem);
         }
     }
-    /* can't just memset() */
-    if (sb_type != SB_SHARED_CHILD) {
-        ap_scoreboard_image->global->sb_type = sb_type;
-        ap_scoreboard_image->global->running_generation = running_gen;
-        apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard,
-                                  apr_pool_cleanup_null);
-    }
+    ap_scoreboard_image->global->sb_type = sb_type;
+    ap_scoreboard_image->global->running_generation = running_gen;
     ap_restart_time = apr_time_now();
+    apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
     return OK;
 }