[mapserver-commits] r13200 - in trunk/mapserver/mapcache: . apache
lib
svn at osgeo.org
svn at osgeo.org
Mon Mar 5 08:40:52 EST 2012
Author: tbonfort
Date: 2012-03-05 05:40:51 -0800 (Mon, 05 Mar 2012)
New Revision: 13200
Modified:
trunk/mapserver/mapcache/apache/mod_mapcache.c
trunk/mapserver/mapcache/lib/cache_sqlite.c
trunk/mapserver/mapcache/mapcache.xml
Log:
don't fork an apache process with runtime user rights as this is non-portable. Instead make sure that the different caches do not need an initialization step before being functional (#4215)
Modified: trunk/mapserver/mapcache/apache/mod_mapcache.c
===================================================================
--- trunk/mapserver/mapcache/apache/mod_mapcache.c 2012-03-04 20:30:24 UTC (rev 13199)
+++ trunk/mapserver/mapcache/apache/mod_mapcache.c 2012-03-05 13:40:51 UTC (rev 13200)
@@ -317,9 +317,6 @@
mapcache_server_cfg* cfg = ap_get_module_config(s->module_config, &mapcache_module);
server_rec *sconf;
apr_status_t rv;
-#if APR_HAS_FORK
- apr_proc_t proc;
-#endif
mapcache_context *ctx = (mapcache_context*)apache_server_context_create(s,p);
if(!cfg) {
@@ -331,77 +328,6 @@
ap_add_version_component(p, MAPCACHE_USERAGENT);
#endif
-#if APR_HAS_FORK
- /* fork a child process to let it accomplish post-configuration tasks with the uid of the runtime user */
- rv = apr_proc_fork(&proc, ptemp);
- if (rv == APR_INCHILD) {
-#define ap_unixd_setup_child unixd_setup_child
- ap_unixd_setup_child();
- mapcache_context *ctx = (mapcache_context*)apache_server_context_create(s,p);
- for (sconf = s; sconf; sconf = sconf->next) {
- mapcache_server_cfg* config = ap_get_module_config(sconf->module_config, &mapcache_module);
- if(config->aliases) {
- apr_hash_index_t *entry = apr_hash_first(ptemp,config->aliases);
-
- /* loop through the configured configurations */
- while (entry) {
- const char *alias;
- apr_ssize_t aliaslen;
- mapcache_cfg *c;
- apr_hash_this(entry,(const void**)&alias,&aliaslen,(void**)&c);
- mapcache_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(APR_EGENERAL);
- }
- 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, "mapcache post-config child terminated abnormally");
- return APR_EGENERAL;
- } else {
- if(exitcode != 0) {
- return APR_EGENERAL;
- }
- }
- return OK;
- } else {
- ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EGENERAL, s, "failed to fork mapcache post-config child");
- return APR_EGENERAL;
- }
-#else /* APR_HAS_FORK */
- for (sconf = s; sconf; sconf = sconf->next) {
- mapcache_server_cfg* config = ap_get_module_config(sconf->module_config, &mapcache_module);
- if(config->aliases) {
- apr_hash_index_t *entry = apr_hash_first(ptemp,config->aliases);
-
- /* loop through the configured configurations */
- while (entry) {
- const char *alias;
- apr_ssize_t aliaslen;
- mapcache_cfg *c;
- apr_hash_this(entry,(const void**)&alias,&aliaslen,(void**)&c);
- mapcache_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));
- return APR_EGENERAL;
- }
- entry = apr_hash_next(entry);
- }
- }
- }
- return OK;
-#endif
-
rv = ap_mpm_query(AP_MPMQ_IS_THREADED,&is_threaded);
}
@@ -530,6 +456,10 @@
if(GC_HAS_ERROR(ctx)) {
return ctx->get_error_message(ctx);
}
+ mapcache_configuration_post_config(ctx, config);
+ if(GC_HAS_ERROR(ctx)) {
+ return ctx->get_error_message(ctx);
+ }
ap_log_error(APLOG_MARK, APLOG_INFO, 0, cmd->server, "loaded mapcache configuration file from %s on alias %s", config->configFile, alias);
if(!sconfig->aliases) {
sconfig->aliases = apr_hash_make(cmd->pool);
Modified: trunk/mapserver/mapcache/lib/cache_sqlite.c
===================================================================
--- trunk/mapserver/mapcache/lib/cache_sqlite.c 2012-03-04 20:30:24 UTC (rev 13199)
+++ trunk/mapserver/mapcache/lib/cache_sqlite.c 2012-03-05 13:40:51 UTC (rev 13200)
@@ -83,13 +83,36 @@
if(readonly) {
flags = SQLITE_OPEN_READONLY;
} else {
- flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
+ flags = SQLITE_OPEN_READWRITE;
}
dbfile = _get_dbname(ctx,tile->tileset, tile->grid_link->grid);
ret = sqlite3_open_v2(dbfile,&handle,flags,NULL);
if(ret != SQLITE_OK) {
- ctx->set_error(ctx,500,"failed to connect to sqlite db %s: %s",dbfile,sqlite3_errmsg(handle));
- return NULL;
+ /* maybe the database file doesn't exist yet. so we create it and setup the schema */
+ mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*)tile->tileset->cache;
+ ret = sqlite3_open_v2(dbfile, &handle,SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE,NULL);
+ if (ret != SQLITE_OK) {
+ ctx->set_error(ctx, 500, "sqlite backend failed to open db %s: %s", dbfile, sqlite3_errmsg(handle));
+ sqlite3_close(handle);
+ return NULL;
+ }
+ ret = sqlite3_exec(handle, cache->create_stmt.sql, 0, 0, NULL);
+ if(ret != SQLITE_OK) {
+ ctx->set_error(ctx, 500, "sqlite backend failed to create db schema on %s: %s",dbfile, sqlite3_errmsg(handle));
+ sqlite3_close(handle);
+ return NULL;
+ }
+
+ /* re-open the db read-only if that's what we were asked for */
+ if(readonly) {
+ sqlite3_close(handle);
+ ret = sqlite3_open_v2(dbfile,&handle,flags,NULL);
+ if (ret != SQLITE_OK) {
+ ctx->set_error(ctx, 500, "sqlite backend failed to re-open freshly created db %s readonly: %s",dbfile, sqlite3_errmsg(handle));
+ sqlite3_close(handle);
+ return NULL;
+ }
+ }
}
sqlite3_busy_timeout(handle,300000);
return handle;
@@ -294,40 +317,6 @@
*/
static void _mapcache_cache_sqlite_configuration_post_config(mapcache_context *ctx,
mapcache_cache *cache, mapcache_cfg *cfg) {
- mapcache_cache_sqlite *dcache = (mapcache_cache_sqlite*)cache;
- sqlite3 *db;
- char *errmsg;
- int ret;
-
- apr_hash_index_t *tileindex_index = apr_hash_first(ctx->pool,cfg->tilesets);
-
- while(tileindex_index) {
- mapcache_tileset *tileset;
- const void *key; apr_ssize_t keylen;
- apr_hash_this(tileindex_index,&key,&keylen,(void**)&tileset);
- if(!strcmp(tileset->cache->name,cache->name)) {
- int i;
- for(i=0;i<tileset->grid_links->nelts;i++) {
- mapcache_grid_link *gridlink = APR_ARRAY_IDX(tileset->grid_links,i,mapcache_grid_link*);
- mapcache_grid *grid = gridlink->grid;
- char *dbname = _get_dbname(ctx,tileset,grid);
- ret = sqlite3_open(dbname, &db);
- if(ret != SQLITE_OK) {
- ctx->set_error(ctx,500,"sqlite backend failed to open db %s: %s",dbname,sqlite3_errmsg(db));
- sqlite3_close(db);
- return;
- }
- ret = sqlite3_exec(db, dcache->create_stmt.sql, 0, 0, &errmsg);
- if(ret != SQLITE_OK) {
- ctx->set_error(ctx,500,"sqlite backend failed to create tiles table: %s",sqlite3_errmsg(db));
- sqlite3_close(db);
- return;
- }
- sqlite3_close(db);
- }
- }
- tileindex_index = apr_hash_next(tileindex_index);
- }
}
/**
Modified: trunk/mapserver/mapcache/mapcache.xml
===================================================================
--- trunk/mapserver/mapcache/mapcache.xml 2012-03-04 20:30:24 UTC (rev 13199)
+++ trunk/mapserver/mapcache/mapcache.xml 2012-03-05 13:40:51 UTC (rev 13200)
@@ -7,6 +7,9 @@
<base>/tmp</base>
<symlink_blank/>
</cache>
+ <cache name="sqlite" type="sqlite3">
+ <base>/tmp</base>
+ </cache>
<source name="vmap0" type="wms">
<getmap>
@@ -26,7 +29,7 @@
<tileset name="test">
<source>vmap0</source>
- <cache>disk</cache>
+ <cache>sqlite</cache>
<grid>WGS84</grid>
<grid>g</grid>
<format>PNG</format>
More information about the mapserver-commits
mailing list