[mapserver-commits] r12460 - in trunk/mapserver/mapcache: include src

svn at osgeo.org svn at osgeo.org
Fri Aug 26 07:28:23 EDT 2011


Author: tbonfort
Date: 2011-08-26 04:28:23 -0700 (Fri, 26 Aug 2011)
New Revision: 12460

Modified:
   trunk/mapserver/mapcache/include/geocache.h
   trunk/mapserver/mapcache/src/configuration.c
   trunk/mapserver/mapcache/src/fastcgi_geocache.c
   trunk/mapserver/mapcache/src/mod_geocache.c
Log:


Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:28:18 UTC (rev 12459)
+++ trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:28:23 UTC (rev 12460)
@@ -885,6 +885,7 @@
  * @return
  */
 void geocache_configuration_parse(geocache_context *ctx, const char *filename, geocache_cfg *config);
+void geocache_configuration_post_config(geocache_context *ctx, geocache_cfg *config);
 void geocache_configuration_parse_json(geocache_context *ctx, const char *filename, geocache_cfg *config);
 void parse_keyvalues(geocache_context *ctx, cJSON *node, apr_table_t *tbl);
 void geocache_configuration_parse_xml(geocache_context *ctx, const char *filename, geocache_cfg *config);

Modified: trunk/mapserver/mapcache/src/configuration.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:28:18 UTC (rev 12459)
+++ trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:28:23 UTC (rev 12460)
@@ -64,7 +64,9 @@
          apr_table_setn(config->metadata,"url",url);
       }
    }
+}
 
+void geocache_configuration_post_config(geocache_context *ctx, geocache_cfg *config) {
    apr_hash_index_t *cachei = apr_hash_first(ctx->pool,config->caches);
    while(cachei) {
       geocache_cache *cache;
@@ -74,7 +76,9 @@
       GC_CHECK_ERROR(ctx);
       cachei = apr_hash_next(cachei);
    }
-}
+} 
+
+
 geocache_cfg* geocache_configuration_create(apr_pool_t *pool) {
    geocache_grid *grid;
    int i;

Modified: trunk/mapserver/mapcache/src/fastcgi_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/fastcgi_geocache.c	2011-08-26 11:28:18 UTC (rev 12459)
+++ trunk/mapserver/mapcache/src/fastcgi_geocache.c	2011-08-26 11:28:23 UTC (rev 12460)
@@ -224,6 +224,11 @@
       c->log(c,500,"failed to parse %s: %s",conffile,c->get_error_message(c));
       return 1;
    }
+   geocache_configuration_post_config(ctx, cfg);
+   if(GC_HAS_ERROR(c)) {
+      c->log(c,500,"post-config failed for %s: %s",conffile,c->get_error_message(c));
+      return 1;
+   }
    
    while (FCGX_Accept(&in, &out, &err, &envp) >= 0) {
       apr_table_t *params;

Modified: trunk/mapserver/mapcache/src/mod_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/mod_geocache.c	2011-08-26 11:28:18 UTC (rev 12459)
+++ trunk/mapserver/mapcache/src/mod_geocache.c	2011-08-26 11:28:23 UTC (rev 12460)
@@ -384,11 +384,12 @@
       return report_error(apache_ctx);
    }
 }
-
+#define ap_unixd_setup_child unixd_setup_child
 static int mod_geocache_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) {
-   apr_status_t rc;
+   apr_status_t rc,rv;
    geocache_server_cfg* cfg = ap_get_module_config(s->module_config, &geocache_module);
    apr_lockmech_e lock_type = APR_LOCK_DEFAULT;
+   server_rec *sconf;
 
    if(!cfg) {
       ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "configuration not found in server context");
@@ -415,17 +416,63 @@
 #ifndef DISABLE_VERSION_STRING
    ap_add_version_component(p, GEOCACHE_USERAGENT);
 #endif
-   for (s = s->next; s; s = s->next) {
-      geocache_server_cfg* config = ap_get_module_config(s->module_config, &geocache_module);
+   for (sconf = s->next; sconf; sconf = sconf->next) {
+      geocache_server_cfg* config = ap_get_module_config(sconf->module_config, &geocache_module);
       config->mutex = cfg->mutex;
    }
+   
+   /* fork a child process to let it accomplish post-configuration tasks with the uid of the runtime user */
+   apr_proc_t proc;
+   rv = apr_proc_fork(&proc, ptemp);
+   if (rv == APR_INCHILD) {
+      ap_unixd_setup_child();
+      geocache_context *ctx = (geocache_context*)apache_server_context_create(s,ptemp);
+      for (sconf = s; sconf; sconf = sconf->next) {
+         geocache_server_cfg* config = ap_get_module_config(sconf->module_config, &geocache_module);
+         if(config->aliases) {
+            apr_hash_index_t *entry = apr_hash_first(ptemp,config->aliases);
 
-   return OK;
+            /* loop through the configured configurations */
+            while (entry) {
+               const char *alias;
+               apr_ssize_t aliaslen;
+               geocache_cfg *c;
+               apr_hash_this(entry,(const void**)&alias,&aliaslen,(void**)&c);
+               geocache_configuration_post_config(ctx, c);
+               if(GC_HAS_ERROR(ctx)) {
+                  ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EGENERAL, s, "post config for %s failed: %s", alias,
+                        ctx->get_error_message(ctx));
+                  exit(0);
+               }
+               entry = apr_hash_next(entry);
+            }
+         }
+      }
+      exit(0);
+   } else if (rv == APR_INPARENT) {
+      apr_exit_why_e exitwhy;
+      int exitcode;
+      apr_proc_wait(&proc,&exitcode,&exitwhy,APR_WAIT);
+      if(exitwhy != APR_PROC_EXIT) {
+         ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EGENERAL, s, "geocache post-config child terminated abnormally");
+      } else {
+         if(exitcode != 0) {
+            return APR_EGENERAL;
+         }
+      }
+      return OK;
+   } else {
+      ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EGENERAL, s, "failed to fork geocache post-config child");
+      return APR_EGENERAL;
+   }
 }
 
 static void mod_geocache_child_init(apr_pool_t *pool, server_rec *s) {
-   geocache_server_cfg* cfg = ap_get_module_config(s->module_config, &geocache_module);
-   apr_global_mutex_child_init(&(cfg->mutex),cfg->mutex_name, pool);
+   while(s) {
+      geocache_server_cfg* cfg = ap_get_module_config(s->module_config, &geocache_module);
+      apr_global_mutex_child_init(&(cfg->mutex),cfg->mutex_name, pool);
+      s = s->next;
+   }
 }
 
 static int geocache_alias_matches(const char *uri, const char *alias_fakename)



More information about the mapserver-commits mailing list