httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject [patch] new API to control how many times httpd.conf was parsed
Date Fri, 24 Oct 2003 21:06:46 GMT
mod_rewrite and and mod_cgid need to know when Apache restarts itself, so they 
won't perform the same thing more than once. Other modules need this 
functionality as well (Glen suggested macros to do that). Instead of copying 
the hack around and having each module stash its data into the main server 
pool, here is a new API which tells the module how many times httpd.conf was 
parsed, performing this work only once. I've adjusted mod_rewrite and and 
mod_cgid to use it. Feel free to suggested a better name than ap_config_read_cnt.

Index: include/http_config.h
===================================================================
RCS file: /home/cvs/httpd-2.0/include/http_config.h,v
retrieving revision 1.97.2.2
diff -u -r1.97.2.2 http_config.h
--- include/http_config.h	9 Mar 2003 00:27:16 -0000	1.97.2.2
+++ include/http_config.h	24 Oct 2003 20:54:53 -0000
@@ -1053,6 +1053,20 @@
   */
  AP_DECLARE_HOOK(void,optional_fn_retrieve,(void))

+/**
+ * Increment the number of times httpd.conf was parsed
+ * @param main_server The main server for this Apache configuration
+ * @return nothing
+ */
+AP_DECLARE(void) ap_config_read_cnt_inc(server_rec *main_server);
+
+/**
+ * Get the number of times httpd.conf was parsed
+ * @param main_server The main server for this Apache configuration
+ * @return the number of times httpd.conf was parsed
+ */
+AP_DECLARE(int) ap_config_read_cnt(server_rec *main_server);
+
  #ifdef __cplusplus
  }
  #endif
Index: server/config.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/config.c,v
retrieving revision 1.156.2.7
diff -u -r1.156.2.7 config.c
--- server/config.c	14 Oct 2003 03:43:18 -0000	1.156.2.7
+++ server/config.c	24 Oct 2003 20:54:54 -0000
@@ -2054,3 +2054,25 @@
  {
      return MPM_NAME;
  }
+
+AP_DECLARE(void) ap_config_read_cnt_inc(server_rec *main_server)
+{
+    void *data;
+    int cnt = 1;
+    const char *key = "config_read_cnt";
+    apr_pool_userdata_get(&data, key, main_server->process->pool);
+    if (data) {
+        cnt = (int)data + 1;
+    }
+
+    apr_pool_userdata_set((const void *)cnt, key,
+                          apr_pool_cleanup_null, main_server->process->pool);
+}
+
+AP_DECLARE(int) ap_config_read_cnt(server_rec *main_server)
+{
+    void *data;
+    const char *key = "config_read_cnt";
+    apr_pool_userdata_get(&data, key, main_server->process->pool);
+    return data ? (int)data : 0;
+}
Index: server/main.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/main.c,v
retrieving revision 1.140.2.3
diff -u -r1.140.2.3 main.c
--- server/main.c	27 Feb 2003 12:09:44 -0000	1.140.2.3
+++ server/main.c	24 Oct 2003 20:54:54 -0000
@@ -581,6 +581,7 @@
      ap_process_config_tree(server_conf, ap_conftree, process->pconf, ptemp);
      ap_fixup_virtual_hosts(pconf, server_conf);
      ap_fini_vhost_config(pconf, server_conf);
+    ap_config_read_cnt_inc(server_conf);
      apr_hook_sort_all();
      if (configtestonly) {
          ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK");
@@ -638,6 +639,7 @@
          ap_process_config_tree(server_conf, ap_conftree, process->pconf, ptemp);
          ap_fixup_virtual_hosts(pconf, server_conf);
          ap_fini_vhost_config(pconf, server_conf);
+        ap_config_read_cnt_inc(server_conf);
          apr_hook_sort_all();
          apr_pool_clear(plog);
          if (ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) {
Index: modules/generators/mod_cgid.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/generators/mod_cgid.c,v
retrieving revision 1.145.2.9
diff -u -r1.145.2.9 mod_cgid.c
--- modules/generators/mod_cgid.c	24 Oct 2003 16:37:06 -0000	1.145.2.9
+++ modules/generators/mod_cgid.c	24 Oct 2003 20:54:55 -0000
@@ -801,16 +801,8 @@
  {
      apr_proc_t *procnew;
      void *data;
-    int first_time = 0;
-    const char *userdata_key = "cgid_init";
+    int first_time = ap_config_read_cnt(main_server);
      module **m;
-
-    apr_pool_userdata_get(&data, userdata_key, main_server->process->pool);
-    if (!data) {
-        first_time = 1;
-        apr_pool_userdata_set((const void *)1, userdata_key,
-                         apr_pool_cleanup_null, main_server->process->pool);
-    }

      if (!first_time) {
          total_modules = 0;
Index: modules/mappers/mod_rewrite.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_rewrite.c,v
retrieving revision 1.135.2.18
diff -u -r1.135.2.18 mod_rewrite.c
--- modules/mappers/mod_rewrite.c	24 Oct 2003 16:19:32 -0000	1.135.2.18
+++ modules/mappers/mod_rewrite.c	24 Oct 2003 20:54:55 -0000
@@ -997,15 +997,7 @@
  {
      apr_status_t rv;
      void *data;
-    int first_time = 0;
-    const char *userdata_key = "rewrite_init_module";
-
-    apr_pool_userdata_get(&data, userdata_key, s->process->pool);
-    if (!data) {
-        first_time = 1;
-        apr_pool_userdata_set((const void *)1, userdata_key,
-                              apr_pool_cleanup_null, s->process->pool);
-    }
+    int first_time = ap_config_read_cnt(s);

      /* check if proxy module is available */
      proxy_available = (ap_find_linked_module("mod_proxy.c") != NULL);


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Mime
View raw message