]> granicus.if.org Git - apache/commitdiff
prefork, worker, and event MPMs: use retained-data API to maintain
authorJeff Trawick <trawick@apache.org>
Wed, 25 Mar 2009 09:23:23 +0000 (09:23 +0000)
committerJeff Trawick <trawick@apache.org>
Wed, 25 Mar 2009 09:23:23 +0000 (09:23 +0000)
information across reconfigs, to allow these MPMs to work as DSOs

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

server/mpm/experimental/event/event.c
server/mpm/prefork/prefork.c
server/mpm/worker/worker.c

index cde6937c643bc309dcef4111eb628cc641611f90..b1d3e9659c93242a752b66221fee9fccaa425082 100644 (file)
@@ -148,9 +148,7 @@ static int max_spare_threads = 0;
 static int ap_daemons_limit = 0;
 static int max_clients = 0;
 static int server_limit = 0;
-static int first_server_limit = 0;
 static int thread_limit = 0;
-static int first_thread_limit = 0;
 static int dying = 0;
 static int workers_may_exit = 0;
 static int start_thread_may_exit = 0;
@@ -202,6 +200,17 @@ typedef struct
     void *baton;
 } listener_poll_type;
 
+/* data retained by event across load/unload of the module
+ * allocated on first call to pre-config hook; located on
+ * subsequent calls to pre-config hook
+ */
+typedef struct event_retained_data {
+    int first_server_limit;
+    int first_thread_limit;
+    int module_loads;
+} event_retained_data;
+static event_retained_data *retained;
+
 #define ID_FROM_CHILD_THREAD(c, t)    ((c * thread_limit) + t)
 
 /*
@@ -2299,7 +2308,6 @@ static int event_run(apr_pool_t * _pconf, apr_pool_t * plog, server_rec * s)
 static int event_open_logs(apr_pool_t * p, apr_pool_t * plog,
                            apr_pool_t * ptemp, server_rec * s)
 {
-    static int restart_num = 0;
     int startup = 0;
     int level_flags = 0;
     apr_status_t rv;
@@ -2307,7 +2315,7 @@ static int event_open_logs(apr_pool_t * p, apr_pool_t * plog,
     pconf = p;
 
     /* the reverse of pre_config, we want this only the first time around */
-    if (restart_num++ == 0) {
+    if (retained->module_loads == 1) {
         startup = 1;
         level_flags |= APLOG_STARTUP;
     }
@@ -2333,9 +2341,9 @@ static int event_open_logs(apr_pool_t * p, apr_pool_t * plog,
 static int event_pre_config(apr_pool_t * pconf, apr_pool_t * plog,
                             apr_pool_t * ptemp)
 {
-    static int restart_num = 0;
     int no_detach, debug, foreground;
     apr_status_t rv;
+    const char *userdata_key = "mpm_event_module";
 
     mpm_state = AP_MPMQ_STARTING;
 
@@ -2352,7 +2360,12 @@ static int event_pre_config(apr_pool_t * pconf, apr_pool_t * plog,
     }
 
     /* sigh, want this only the second time around */
-    if (restart_num++ == 1) {
+    retained = ap_get_retained_data(userdata_key);
+    if (!retained) {
+        retained = ap_set_retained_data(userdata_key, sizeof(*retained));
+    }
+    ++retained->module_loads;
+    if (retained->module_loads == 2) {
         is_graceful = 0;
         rv = apr_pollset_create(&event_pollset, 1, plog,
                                 APR_POLLSET_THREADSAFE | APR_POLLSET_NOCOPY);
@@ -2401,11 +2414,10 @@ static int event_pre_config(apr_pool_t * pconf, apr_pool_t * plog,
 static int event_check_config(apr_pool_t *p, apr_pool_t *plog,
                               apr_pool_t *ptemp, server_rec *s)
 {
-    static int restart_num = 0;
     int startup = 0;
 
     /* the reverse of pre_config, we want this only the first time around */
-    if (restart_num++ == 0) {
+    if (retained->module_loads == 1) {
         startup = 1;
     }
 
@@ -2441,16 +2453,16 @@ static int event_check_config(apr_pool_t *p, apr_pool_t *plog,
     /* you cannot change ServerLimit across a restart; ignore
      * any such attempts
      */
-    if (!first_server_limit) {
-        first_server_limit = server_limit;
+    if (!retained->first_server_limit) {
+        retained->first_server_limit = server_limit;
     }
-    else if (server_limit != first_server_limit) {
+    else if (server_limit != retained->first_server_limit) {
         /* don't need a startup console version here */
         ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
                      "changing ServerLimit to %d from original value of %d "
                      "not allowed during restart",
-                     server_limit, first_server_limit);
-        server_limit = first_server_limit;
+                     server_limit, retained->first_server_limit);
+        server_limit = retained->first_server_limit;
     }
 
     if (thread_limit > MAX_THREAD_LIMIT) {
@@ -2485,16 +2497,16 @@ static int event_check_config(apr_pool_t *p, apr_pool_t *plog,
     /* you cannot change ThreadLimit across a restart; ignore
      * any such attempts
      */
-    if (!first_thread_limit) {
-        first_thread_limit = thread_limit;
+    if (!retained->first_thread_limit) {
+        retained->first_thread_limit = thread_limit;
     }
-    else if (thread_limit != first_thread_limit) {
+    else if (thread_limit != retained->first_thread_limit) {
         /* don't need a startup console version here */
         ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
                      "changing ThreadLimit to %d from original value of %d "
                      "not allowed during restart",
-                     thread_limit, first_thread_limit);
-        thread_limit = first_thread_limit;
+                     thread_limit, retained->first_thread_limit);
+        thread_limit = retained->first_thread_limit;
     }
 
     if (threads_per_child > thread_limit) {
index 00528d204a6f6a0d01c6f5dc8428fb7d1f7140f7..13acdb7769d93f778cfa9b30b96a7142c05c5df5 100644 (file)
@@ -94,10 +94,19 @@ static int ap_daemons_min_free=0;
 static int ap_daemons_max_free=0;
 static int ap_daemons_limit=0;      /* MaxClients */
 static int server_limit = 0;
-static int first_server_limit = 0;
 static int mpm_state = AP_MPMQ_STARTING;
 static ap_pod_t *pod;
 
+/* data retained by prefork across load/unload of the module
+ * allocated on first call to pre-config hook; located on
+ * subsequent calls to pre-config hook
+ */
+typedef struct prefork_retained_data {
+    int first_server_limit;
+    int module_loads;
+} prefork_retained_data;
+static prefork_retained_data *retained;
+
 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
 
 /*
@@ -1251,7 +1260,6 @@ static int prefork_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
  */
 static int prefork_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
 {
-    static int restart_num = 0;
     int startup = 0;
     int level_flags = 0;
     apr_status_t rv;
@@ -1259,7 +1267,7 @@ static int prefork_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
     pconf = p;
 
     /* the reverse of pre_config, we want this only the first time around */
-    if (restart_num++ == 0) {
+    if (retained->module_loads == 1) {
         startup = 1;
         level_flags |= APLOG_STARTUP;
     }
@@ -1282,9 +1290,9 @@ static int prefork_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
 
 static int prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
 {
-    static int restart_num = 0;
     int no_detach, debug, foreground;
     apr_status_t rv;
+    const char *userdata_key = "mpm_prefork_module";
 
     mpm_state = AP_MPMQ_STARTING;
 
@@ -1302,7 +1310,12 @@ static int prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp
     }
 
     /* sigh, want this only the second time around */
-    if (restart_num++ == 1) {
+    retained = ap_get_retained_data(userdata_key);
+    if (!retained) {
+        retained = ap_set_retained_data(userdata_key, sizeof(*retained));
+    }
+    ++retained->module_loads;
+    if (retained->module_loads == 2) {
         is_graceful = 0;
 
         if (!one_process && !foreground) {
@@ -1340,11 +1353,10 @@ static int prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp
 static int prefork_check_config(apr_pool_t *p, apr_pool_t *plog,
                                 apr_pool_t *ptemp, server_rec *s)
 {
-    static int restart_num = 0;
     int startup = 0;
 
     /* the reverse of pre_config, we want this only the first time around */
-    if (restart_num++ == 0) {
+    if (retained->module_loads == 1) {
         startup = 1;
     }
 
@@ -1380,16 +1392,16 @@ static int prefork_check_config(apr_pool_t *p, apr_pool_t *plog,
     /* you cannot change ServerLimit across a restart; ignore
      * any such attempts
      */
-    if (!first_server_limit) {
-        first_server_limit = server_limit;
+    if (!retained->first_server_limit) {
+        retained->first_server_limit = server_limit;
     }
-    else if (server_limit != first_server_limit) {
+    else if (server_limit != retained->first_server_limit) {
         /* don't need a startup console version here */
         ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
                      "changing ServerLimit to %d from original value of %d "
                      "not allowed during restart",
-                     server_limit, first_server_limit);
-        server_limit = first_server_limit;
+                     server_limit, retained->first_server_limit);
+        server_limit = retained->first_server_limit;
     }
 
     if (ap_daemons_limit > server_limit) {
index ddfaa6525259d0c31eba10c5ef461165db1c77e0..846f26da781281dcff4458e3506356cd34ea71d1 100644 (file)
@@ -120,9 +120,7 @@ static int max_spare_threads = 0;
 static int ap_daemons_limit = 0;
 static int max_clients = 0;
 static int server_limit = 0;
-static int first_server_limit = 0;
 static int thread_limit = 0;
-static int first_thread_limit = 0;
 static int dying = 0;
 static int workers_may_exit = 0;
 static int start_thread_may_exit = 0;
@@ -136,6 +134,17 @@ static int mpm_state = AP_MPMQ_STARTING;
 static int sick_child_detected;
 static ap_generation_t volatile my_generation = 0;
 
+/* data retained by worker across load/unload of the module
+ * allocated on first call to pre-config hook; located on
+ * subsequent calls to pre-config hook
+ */
+typedef struct worker_retained_data {
+    int first_server_limit;
+    int first_thread_limit;
+    int module_loads;
+} worker_retained_data;
+static worker_retained_data *retained;
+
 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid)
 
 /* The structure used to pass unique initialization info to each thread */
@@ -1880,7 +1889,7 @@ static int worker_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
                     "SIGHUP received.  Attempting to restart");
     }
 
-    return 0;
+    return OK;
 }
 
 /* This really should be a post_config hook, but the error log is already
@@ -1888,7 +1897,6 @@ static int worker_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
  */
 static int worker_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
 {
-    static int restart_num = 0;
     int startup = 0;
     int level_flags = 0;
     apr_status_t rv;
@@ -1896,7 +1904,7 @@ static int worker_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
     pconf = p;
 
     /* the reverse of pre_config, we want this only the first time around */
-    if (restart_num++ == 0) {
+    if (retained->module_loads == 1) {
         startup = 1;
         level_flags |= APLOG_STARTUP;
     }
@@ -1922,9 +1930,9 @@ static int worker_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
 static int worker_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
                              apr_pool_t *ptemp)
 {
-    static int restart_num = 0;
     int no_detach, debug, foreground;
     apr_status_t rv;
+    const char *userdata_key = "mpm_worker_module";
 
     mpm_state = AP_MPMQ_STARTING;
 
@@ -1941,7 +1949,12 @@ static int worker_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
     }
 
     /* sigh, want this only the second time around */
-    if (restart_num++ == 1) {
+    retained = ap_get_retained_data(userdata_key);
+    if (!retained) {
+        retained = ap_set_retained_data(userdata_key, sizeof(*retained));
+    }
+    ++retained->module_loads;
+    if (retained->module_loads == 2) {
         is_graceful = 0;
 
         if (!one_process && !foreground) {
@@ -2021,16 +2034,16 @@ static int worker_check_config(apr_pool_t *p, apr_pool_t *plog,
     /* you cannot change ServerLimit across a restart; ignore
      * any such attempts
      */
-    if (!first_server_limit) {
-        first_server_limit = server_limit;
+    if (!retained->first_server_limit) {
+        retained->first_server_limit = server_limit;
     }
-    else if (server_limit != first_server_limit) {
+    else if (server_limit != retained->first_server_limit) {
         /* don't need a startup console version here */
         ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
                      "changing ServerLimit to %d from original value of %d "
                      "not allowed during restart",
-                     server_limit, first_server_limit);
-        server_limit = first_server_limit;
+                     server_limit, retained->first_server_limit);
+        server_limit = retained->first_server_limit;
     }
 
     if (thread_limit > MAX_THREAD_LIMIT) {
@@ -2065,16 +2078,16 @@ static int worker_check_config(apr_pool_t *p, apr_pool_t *plog,
     /* you cannot change ThreadLimit across a restart; ignore
      * any such attempts
      */
-    if (!first_thread_limit) {
-        first_thread_limit = thread_limit;
+    if (!retained->first_thread_limit) {
+        retained->first_thread_limit = thread_limit;
     }
-    else if (thread_limit != first_thread_limit) {
+    else if (thread_limit != retained->first_thread_limit) {
         /* don't need a startup console version here */
         ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
                      "changing ThreadLimit to %d from original value of %d "
                      "not allowed during restart",
-                     thread_limit, first_thread_limit);
-        thread_limit = first_thread_limit;
+                     thread_limit, retained->first_thread_limit);
+        thread_limit = retained->first_thread_limit;
     }
 
     if (threads_per_child > thread_limit) {