You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by tr...@apache.org on 2009/03/25 10:23:31 UTC

svn commit: r758185 - in /httpd/httpd/trunk/server/mpm: experimental/event/event.c prefork/prefork.c worker/worker.c

Author: trawick
Date: Wed Mar 25 09:23:23 2009
New Revision: 758185

URL: http://svn.apache.org/viewvc?rev=758185&view=rev
Log:
prefork, worker, and event MPMs: use retained-data API to maintain
information across reconfigs, to allow these MPMs to work as DSOs

Modified:
    httpd/httpd/trunk/server/mpm/experimental/event/event.c
    httpd/httpd/trunk/server/mpm/prefork/prefork.c
    httpd/httpd/trunk/server/mpm/worker/worker.c

Modified: httpd/httpd/trunk/server/mpm/experimental/event/event.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/experimental/event/event.c?rev=758185&r1=758184&r2=758185&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/experimental/event/event.c (original)
+++ httpd/httpd/trunk/server/mpm/experimental/event/event.c Wed Mar 25 09:23:23 2009
@@ -148,9 +148,7 @@
 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 @@
     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_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 @@
     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_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 @@
     }
 
     /* 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_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 @@
     /* 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 @@
     /* 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) {

Modified: httpd/httpd/trunk/server/mpm/prefork/prefork.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/prefork/prefork.c?rev=758185&r1=758184&r2=758185&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/prefork/prefork.c (original)
+++ httpd/httpd/trunk/server/mpm/prefork/prefork.c Wed Mar 25 09:23:23 2009
@@ -94,10 +94,19 @@
 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_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 @@
     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_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 @@
     }
 
     /* 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_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 @@
     /* 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) {

Modified: httpd/httpd/trunk/server/mpm/worker/worker.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/worker/worker.c?rev=758185&r1=758184&r2=758185&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/worker/worker.c (original)
+++ httpd/httpd/trunk/server/mpm/worker/worker.c Wed Mar 25 09:23:23 2009
@@ -120,9 +120,7 @@
 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 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 @@
                     "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_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 @@
     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_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 @@
     }
 
     /* 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 @@
     /* 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 @@
     /* 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) {