apr_status_t jxr_conn_setup(jaxer_worker* aw) { apr_status_t rv = APR_SUCCESS; ap_log_perror(APLOG_MARK, APLOG_ZDEBUG, 0, aw->pool, "mod_jaxer: jxr_conn_setup: creating connection pool (min=%d keep=%d max=%d) for worker %s", aw->nmin, aw->nkeep, aw->nmax, aw->name); rv = apr_reslist_create(&aw->ac_cache, aw->nmin, aw->nkeep, aw->nmax, apr_time_from_sec(aw->exptime), jxr_conn_construct, jxr_conn_destruct, aw, aw->res_pool); if (rv == APR_SUCCESS) { apr_reslist_timeout_set(aw->ac_cache, apr_time_from_sec(aw->acquire_timeout)); apr_pool_cleanup_register(aw->res_pool, aw->ac_cache, (void*)apr_reslist_destroy, apr_pool_cleanup_null); ap_log_perror(APLOG_MARK, APLOG_NOTICE, 0, aw->res_pool, "mod_jaxer: connection pool (min=%d keep=%d max=%d) created for worker %s", aw->nmin, aw->nkeep, aw->nmax, aw->name); }else { ap_log_perror(APLOG_MARK, APLOG_CRIT, rv, aw->res_pool, "mod_jaxer: failed to initialize connection reslist for worker %s", aw->name); // apr_pool_destroy(aw->pool); // aw->pool = 0; } return rv; }
static void _mapcache_cache_bdb_configuration_parse_xml(mapcache_context *ctx, ezxml_t node, mapcache_cache *cache, mapcache_cfg *config) { ezxml_t cur_node; apr_status_t rv; mapcache_cache_bdb *dcache = (mapcache_cache_bdb*)cache; if ((cur_node = ezxml_child(node,"base")) != NULL) { dcache->basedir = apr_pstrdup(ctx->pool,cur_node->txt); } if ((cur_node = ezxml_child(node,"key_template")) != NULL) { dcache->key_template = apr_pstrdup(ctx->pool,cur_node->txt); } else { dcache->key_template = apr_pstrdup(ctx->pool,"{tileset}-{grid}-{dim}-{z}-{y}-{x}.{ext}"); } if(!dcache->basedir) { ctx->set_error(ctx,500,"dbd cache \"%s\" is missing <base> entry",cache->name); return; } dcache->ctx = ctx; rv = apr_reslist_create(&(dcache->ro_connection_pool), 0 /* min */, 10 /* soft max */, 200 /* hard max */, 60*1000000 /*60 seconds, ttl*/, _bdb_reslist_get_connection, /* resource constructor */ _bdb_reslist_free_connection, /* resource destructor */ dcache, ctx->pool); if(rv != APR_SUCCESS) { ctx->set_error(ctx,500,"failed to create bdb connection pool"); return; } rv = apr_reslist_create(&(dcache->rw_connection_pool), 0 /* min */, 1 /* soft max */, 1 /* hard max */, 60*1000000 /*60 seconds, ttl*/, _bdb_reslist_get_connection, /* resource constructor */ _bdb_reslist_free_connection, /* resource destructor */ dcache, ctx->pool); if(rv != APR_SUCCESS) { ctx->set_error(ctx,500,"failed to create bdb connection pool"); return; } }
/** * Redis Pool Setting * * this handler manage redis resource that use apache resource list(apr_reslist_create) * this reslist have a construct and a destruct for resource management */ static int redis_pool_handler(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { redis_cfg *redis_config = (redis_cfg*) ap_get_module_config(s->module_config, &apachelog_module); if (apr_reslist_create(&redis_config->redis_pool, redis_config->nmin, redis_config->nkeep, redis_config->nmax, redis_config->exptime, pool_construct, pool_destruct, s, p) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "[APACHELOG][REDIS POOL CREATE FAIL]"); } apr_pool_cleanup_register(p, redis_config->redis_pool, (void*) apr_reslist_destroy, apr_pool_cleanup_null); return OK; }
static struct mc_mapobj* _get_mapboj(mapcache_context *ctx, mapcache_map *map) { apr_status_t rv; mapcache_source_mapserver *src = (mapcache_source_mapserver*) map->tileset->source; struct mc_mapobj *mcmap; apr_reslist_t *mapobjs = NULL; if(!mapobj_container || NULL == (mapobjs = apr_hash_get(mapobj_container,src->source.name,APR_HASH_KEY_STRING))) { #ifdef APR_HAS_THREADS if(ctx->threadlock) apr_thread_mutex_lock((apr_thread_mutex_t*)ctx->threadlock); #endif if(!mapobj_container) { mapobj_container = apr_hash_make(ctx->process_pool); } mapobjs = apr_hash_get(mapobj_container,src->source.name,APR_HASH_KEY_STRING); if(!mapobjs) { apr_status_t rv; rv = apr_reslist_create(&mapobjs, 0 /* min */, 1 /* soft max */, 30 /* hard max */, 6 * 1000000 /*6 seconds, ttl*/, _ms_get_mapobj, /* resource constructor */ _ms_free_mapobj, /* resource destructor */ src, ctx->process_pool); if (rv != APR_SUCCESS) { ctx->set_error(ctx, 500, "failed to create mapobj connection pool for cache %s", src->source.name); #ifdef APR_HAS_THREADS if(ctx->threadlock) apr_thread_mutex_unlock((apr_thread_mutex_t*)ctx->threadlock); #endif return NULL; } apr_hash_set(mapobj_container,src->source.name,APR_HASH_KEY_STRING,mapobjs); } assert(mapobjs); #ifdef APR_HAS_THREADS if(ctx->threadlock) apr_thread_mutex_unlock((apr_thread_mutex_t*)ctx->threadlock); #endif } rv = apr_reslist_acquire(mapobjs, (void **) &mcmap); if (rv != APR_SUCCESS) { ctx->set_error(ctx, 500, "failed to aquire mappObj instance: %s", mcmap->error); return NULL; } return mcmap; }
static void test_reslist(abts_case *tc, void *data) { int i; apr_status_t rv; apr_reslist_t *rl; my_parameters_t *params; apr_thread_pool_t *thrp; my_thread_info_t thread_info[CONSUMER_THREADS]; rv = apr_thread_pool_create(&thrp, CONSUMER_THREADS/2, CONSUMER_THREADS, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); /* Create some parameters that will be passed into each * constructor and destructor call. */ params = apr_pcalloc(p, sizeof(*params)); params->sleep_upon_construct = CONSTRUCT_SLEEP_TIME; params->sleep_upon_destruct = DESTRUCT_SLEEP_TIME; /* We're going to want 10 blocks of data from our target rmm. */ rv = apr_reslist_create(&rl, RESLIST_MIN, RESLIST_SMAX, RESLIST_HMAX, RESLIST_TTL, my_constructor, my_destructor, params, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); for (i = 0; i < CONSUMER_THREADS; i++) { thread_info[i].tid = i; thread_info[i].tc = tc; thread_info[i].reslist = rl; thread_info[i].work_delay_sleep = WORK_DELAY_SLEEP_TIME; rv = apr_thread_pool_push(thrp, resource_consuming_thread, &thread_info[i], 0, NULL); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } rv = apr_thread_pool_destroy(thrp); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); test_timeout(tc, rl); test_shrinking(tc, rl); ABTS_INT_EQUAL(tc, RESLIST_SMAX, params->c_count - params->d_count); rv = apr_reslist_destroy(rl); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); }
static int setup_db_pool(apr_pool_t* p, apr_pool_t* plog, apr_pool_t* ptemp, server_rec* s) { void *data = NULL; char *key; const char *userdata_key = "pgasp_post_config"; apr_hash_index_t *idx; apr_ssize_t len; pgasp_config *pgasp; // This code is used to prevent double initialization of the module during Apache startup apr_pool_userdata_get(&data, userdata_key, s->process->pool); if ( data == NULL ) { apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool); return OK; } for (idx = apr_hash_first(p, pgasp_pool_config); idx; idx = apr_hash_next(idx)) { apr_hash_this(idx, (void *) &key, &len, (void *) &pgasp); if ( apr_reslist_create(&pgasp->dbpool, pgasp->nmin, pgasp->nkeep, pgasp->nmax, pgasp->exptime, pgasp_pool_construct, pgasp_pool_destruct, (void*)pgasp, p) != APR_SUCCESS ) { ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "mod_pgasp: failed to initialise") ; return 500 ; } apr_pool_cleanup_register(p, pgasp->dbpool, (void*)apr_reslist_destroy, apr_pool_cleanup_null) ; apr_hash_set(pgasp_pool_config, key, APR_HASH_KEY_STRING, pgasp); } return OK ; }
static struct sqlite_conn* _sqlite_get_conn(mapcache_context *ctx, mapcache_tile* tile, int readonly) { apr_status_t rv; mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*) tile->tileset->cache; struct sqlite_conn *conn = NULL; apr_reslist_t *pool = NULL; apr_hash_t *pool_container; if (readonly) { pool_container = ro_connection_pools; } else { pool_container = rw_connection_pools; } if(!pool_container || NULL == (pool = apr_hash_get(pool_container,cache->cache.name, APR_HASH_KEY_STRING)) ) { #ifdef APR_HAS_THREADS if(ctx->threadlock) apr_thread_mutex_lock((apr_thread_mutex_t*)ctx->threadlock); #endif if(!ro_connection_pools) { ro_connection_pools = apr_hash_make(ctx->process_pool); rw_connection_pools = apr_hash_make(ctx->process_pool); } /* probably doesn't exist, unless the previous mutex locked us, so we check */ pool = apr_hash_get(ro_connection_pools,cache->cache.name, APR_HASH_KEY_STRING); if(!pool) { /* there where no existing connection pools, create them*/ rv = apr_reslist_create(&pool, 0 /* min */, 10 /* soft max */, 200 /* hard max */, 60*1000000 /*60 seconds, ttl*/, _sqlite_reslist_get_ro_connection, /* resource constructor */ _sqlite_reslist_free_connection, /* resource destructor */ cache, ctx->process_pool); if(rv != APR_SUCCESS) { ctx->set_error(ctx,500,"failed to create bdb ro connection pool"); #ifdef APR_HAS_THREADS if(ctx->threadlock) apr_thread_mutex_unlock((apr_thread_mutex_t*)ctx->threadlock); #endif return NULL; } apr_hash_set(ro_connection_pools,cache->cache.name,APR_HASH_KEY_STRING,pool); rv = apr_reslist_create(&pool, 0 /* min */, 1 /* soft max */, 1 /* hard max */, 60*1000000 /*60 seconds, ttl*/, _sqlite_reslist_get_rw_connection, /* resource constructor */ _sqlite_reslist_free_connection, /* resource destructor */ cache, ctx->process_pool); if(rv != APR_SUCCESS) { ctx->set_error(ctx,500,"failed to create bdb rw connection pool"); #ifdef APR_HAS_THREADS if(ctx->threadlock) apr_thread_mutex_unlock((apr_thread_mutex_t*)ctx->threadlock); #endif return NULL; } apr_hash_set(rw_connection_pools,cache->cache.name,APR_HASH_KEY_STRING,pool); } #ifdef APR_HAS_THREADS if(ctx->threadlock) apr_thread_mutex_unlock((apr_thread_mutex_t*)ctx->threadlock); #endif if(readonly) pool = apr_hash_get(ro_connection_pools,cache->cache.name, APR_HASH_KEY_STRING); else pool = apr_hash_get(rw_connection_pools,cache->cache.name, APR_HASH_KEY_STRING); assert(pool); } rv = apr_reslist_acquire(pool, (void **) &conn); if (rv != APR_SUCCESS) { ctx->set_error(ctx, 500, "failed to aquire connection to sqlite backend: %s", (conn && conn->errmsg)?conn->errmsg:"unknown error"); return NULL; } return conn; }
static apr_status_t test_reslist(apr_pool_t *parpool) { apr_status_t rv; apr_pool_t *pool; apr_reslist_t *rl; my_parameters_t *params; int i; apr_thread_t *my_threads[CONSUMER_THREADS]; my_thread_info_t my_thread_info[CONSUMER_THREADS]; printf("Creating child pool......................."); rv = apr_pool_create(&pool, parpool); if (rv != APR_SUCCESS) { fprintf(stderr, "Error creating child pool\n"); return rv; } printf("OK\n"); /* Create some parameters that will be passed into each * constructor and destructor call. */ params = apr_pcalloc(pool, sizeof(*params)); params->sleep_upon_construct = CONSTRUCT_SLEEP_TIME; params->sleep_upon_destruct = DESTRUCT_SLEEP_TIME; /* We're going to want 10 blocks of data from our target rmm. */ printf("Creating resource list:\n" " min/smax/hmax: %d/%d/%d\n" " ttl: %" APR_TIME_T_FMT "\n", RESLIST_MIN, RESLIST_SMAX, RESLIST_HMAX, RESLIST_TTL); rv = apr_reslist_create(&rl, RESLIST_MIN, RESLIST_SMAX, RESLIST_HMAX, RESLIST_TTL, my_constructor, my_destructor, params, pool); if (rv != APR_SUCCESS) { fprintf(stderr, "Error allocating shared memory block\n"); return rv; } fprintf(stdout, "OK\n"); printf("Creating %d threads", CONSUMER_THREADS); for (i = 0; i < CONSUMER_THREADS; i++) { putchar('.'); my_thread_info[i].tid = i; my_thread_info[i].reslist = rl; my_thread_info[i].work_delay_sleep = WORK_DELAY_SLEEP_TIME; rv = apr_thread_create(&my_threads[i], NULL, resource_consuming_thread, &my_thread_info[i], pool); if (rv != APR_SUCCESS) { fprintf(stderr, "Failed to create thread %d\n", i); return rv; } } printf("\nDone!\n"); printf("Waiting for threads to finish"); for (i = 0; i < CONSUMER_THREADS; i++) { apr_status_t thread_rv; putchar('.'); apr_thread_join(&thread_rv, my_threads[i]); if (rv != APR_SUCCESS) { fprintf(stderr, "Failed to join thread %d\n", i); return rv; } } printf("\nDone!\n"); printf("Destroying resource list................."); rv = apr_reslist_destroy(rl); if (rv != APR_SUCCESS) { printf("FAILED\n"); return rv; } printf("OK\n"); apr_pool_destroy(pool); return APR_SUCCESS; }
/** * Function used to create a lua_State instance bound into the web * server in the appropriate scope. */ lua_State *ap_lua_get_lua_state(apr_pool_t *lifecycle_pool, ap_lua_vm_spec *spec, request_rec* r) { lua_State *L = NULL; ap_lua_finfo *cache_info = NULL; int tryCache = 0; if (spec->scope == AP_LUA_SCOPE_SERVER) { char *hash; apr_reslist_t* reslist = NULL; ap_lua_server_spec* sspec = NULL; hash = apr_psprintf(r->pool, "reslist:%s", spec->file); #if APR_HAS_THREADS apr_thread_mutex_lock(ap_lua_mutex); #endif if (apr_pool_userdata_get((void **)&reslist, hash, r->server->process->pool) == APR_SUCCESS) { if (reslist != NULL) { if (apr_reslist_acquire(reslist, (void**) &sspec) == APR_SUCCESS) { L = sspec->L; cache_info = sspec->finfo; } } } if (L == NULL) { ap_lua_vm_spec* server_spec = copy_vm_spec(r->server->process->pool, spec); if ( apr_reslist_create(&reslist, spec->vm_min, spec->vm_max, spec->vm_max, 0, (apr_reslist_constructor) server_vm_construct, (apr_reslist_destructor) server_cleanup_lua, server_spec, r->server->process->pool) == APR_SUCCESS && reslist != NULL) { apr_pool_userdata_set(reslist, hash, NULL, r->server->process->pool); if (apr_reslist_acquire(reslist, (void**) &sspec) == APR_SUCCESS) { L = sspec->L; cache_info = sspec->finfo; } else { return NULL; } } } #if APR_HAS_THREADS apr_thread_mutex_unlock(ap_lua_mutex); #endif } else { if (apr_pool_userdata_get((void **)&L, spec->file, lifecycle_pool) != APR_SUCCESS) { L = NULL; } } if (L == NULL) { ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, lifecycle_pool, APLOGNO(01483) "creating lua_State with file %s", spec->file); /* not available, so create */ if (!vm_construct(&L, spec, lifecycle_pool)) { AP_DEBUG_ASSERT(L != NULL); apr_pool_userdata_set(L, spec->file, cleanup_lua, lifecycle_pool); } } if (spec->codecache == AP_LUA_CACHE_FOREVER || (spec->bytecode && spec->bytecode_len > 0)) { tryCache = 1; } else { char* mkey; if (spec->scope != AP_LUA_SCOPE_SERVER) { mkey = apr_psprintf(r->pool, "ap_lua_modified:%s", spec->file); apr_pool_userdata_get((void **)&cache_info, mkey, lifecycle_pool); if (cache_info == NULL) { cache_info = apr_pcalloc(lifecycle_pool, sizeof(ap_lua_finfo)); apr_pool_userdata_set((void*) cache_info, mkey, NULL, lifecycle_pool); } } if (spec->codecache == AP_LUA_CACHE_STAT) { apr_finfo_t lua_finfo; apr_stat(&lua_finfo, spec->file, APR_FINFO_MTIME|APR_FINFO_SIZE, lifecycle_pool); /* On first visit, modified will be zero, but that's fine - The file is loaded in the vm_construct function. */ if ((cache_info->modified == lua_finfo.mtime && cache_info->size == lua_finfo.size) || cache_info->modified == 0) { tryCache = 1; } cache_info->modified = lua_finfo.mtime; cache_info->size = lua_finfo.size; } else if (spec->codecache == AP_LUA_CACHE_NEVER) { if (cache_info->runs == 0) tryCache = 1; } cache_info->runs++; } if (tryCache == 0 && spec->scope != AP_LUA_SCOPE_ONCE) { int rc; ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, lifecycle_pool, APLOGNO(02332) "(re)loading lua file %s", spec->file); rc = luaL_loadfile(L, spec->file); if (rc != 0) { ap_log_perror(APLOG_MARK, APLOG_ERR, 0, lifecycle_pool, APLOGNO(02333) "Error loading %s: %s", spec->file, rc == LUA_ERRMEM ? "memory allocation error" : lua_tostring(L, 0)); return 0; } lua_pcall(L, 0, LUA_MULTRET, 0); } return L; }
/** * \private \memberof mapcache_cache_couchbase */ static void _mapcache_cache_couchbase_configuration_parse_xml(mapcache_context *ctx, ezxml_t node, mapcache_cache *cache, mapcache_cfg *config) { ezxml_t cur_node; apr_status_t rv; mapcache_cache_couchbase *dcache = (mapcache_cache_couchbase*)cache; int servercount = 0; for(cur_node = ezxml_child(node,"server"); cur_node; cur_node = cur_node->next) { servercount++; } if(!servercount) { ctx->set_error(ctx, 400, "couchbase cache %s has no <server>s configured", cache->name); return; } if(servercount > 1) { ctx->set_error(ctx, 400, "couchbase cache %s has more than 1 server configured", cache->name); return; } cur_node = ezxml_child(node, "server"); ezxml_t xhost = ezxml_child(cur_node, "host"); /* Host should contain server:port */ ezxml_t xusername = ezxml_child(cur_node, "username"); ezxml_t xpasswd = ezxml_child(cur_node, "password"); ezxml_t xbucket = ezxml_child(cur_node, "bucket"); if(!xhost || !xhost->txt || ! *xhost->txt) { ctx->set_error(ctx, 400, "cache %s: <server> with no <host>", cache->name); return; } else { dcache->host = apr_pstrdup(ctx->pool, xhost->txt); if (dcache->host == NULL) { ctx->set_error(ctx, 400, "cache %s: failed to allocate host string!", cache->name); return; } } if(xusername && xusername->txt && *xusername->txt) { dcache->username = apr_pstrdup(ctx->pool, xusername->txt); } if(xpasswd && xpasswd->txt && *xpasswd->txt) { dcache->password = apr_pstrdup(ctx->pool, xpasswd->txt); } if(xbucket && xbucket->txt && *xbucket->txt) { dcache->bucket = apr_pstrdup(ctx->pool, xbucket->txt); } dcache->ctx = ctx; rv = apr_reslist_create(&(dcache->connection_pool), 0 /* min */, 10 /* soft max */, 200 /* hard max */, 60*1000000 /*60 seconds, ttl*/, _couchbase_reslist_get_connection, /* resource constructor */ _couchbase_reslist_free_connection, /* resource destructor */ dcache, ctx->pool); if(rv != APR_SUCCESS) { ctx->set_error(ctx, 500, "failed to create couchbase connection pool"); return; } }
const char *luaex_cmd_Reslist(cmd_parms *cmd, void *dcfg, const char *resource, const char *script) { struct dir_config *conf = dcfg; const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT); module* lua_module = ml_find_module(cmd->server, "lua_module"); if (err != NULL) return err; if (conf->resource == NULL) { conf->resource = apr_hash_make(cmd->pool); } if (conf->L == NULL) { conf->L = luaL_newstate(); #ifdef AP_ENABLE_LUAJIT luaopen_jit(conf->L); #endif luaL_openlibs(conf->L); } if (apr_hash_get(conf->resource, resource, strlen(resource)) == NULL) { lua_State *L = conf->L; int err = luaL_loadfile(L, script); if (err == LUA_ERRFILE) return apr_psprintf(cmd->pool, "cannot open/read: %s. ", script); if (err == LUA_ERRSYNTAX) return apr_psprintf(cmd->pool, "syntax error during pre-compilation for: %s. ", script); if (err == LUA_ERRMEM) return apr_psprintf(cmd->pool, "memory allocation error for load: %s. ", script); if (err) return apr_psprintf(cmd->pool, "unknown error)(%d) for load: %s. ", err, script); err = lua_pcall(L, 0, LUA_MULTRET, 0); if (err == LUA_ERRRUN) return apr_psprintf(cmd->pool, "a runtime error. %s", lua_tostring(L, -1)); if (err == LUA_ERRMEM) return apr_psprintf(cmd->pool, "memory allocation error. %s", lua_tostring(L, -1)); if (err == LUA_ERRERR) return apr_psprintf(cmd->pool, "error while running the error handler function. %s", lua_tostring(L, -1)); if (err) return apr_psprintf(cmd->pool, "unknown error(%d:%s) for load: %s. ", err, lua_tostring(L, -1), script); { int min, smax, hmax, ttl; apr_reslist_t* reslist; reslist_cb_t* cb = apr_palloc(cmd->pool, sizeof(reslist_cb_t)); luaL_getmetatable(L, resource); if (lua_isnil(L, -1)) return apr_psprintf(cmd->pool, "%s not support %s object(metatable)", script, resource); cb->name = resource; lua_pop(L, 1); if (!lua_istable(L, -1)) return apr_psprintf(cmd->pool, "%s not return a table which makes a reslist for %s", script, resource); cb->L = conf->L; lua_getfield(L, -1, "constructor"); if (!lua_isfunction(L, -1)) return apr_psprintf(cmd->pool, "%s not have a table field(constructor) function", script); cb->constructor_ref = luaL_ref(L, LUA_REGISTRYINDEX); lua_getfield(L, -1, "destructor"); if (!lua_isfunction(L, -1)) return apr_psprintf(cmd->pool, "%s not have a table field(destructor) function", script); cb->destructor_ref = luaL_ref(L, LUA_REGISTRYINDEX); lua_getfield(L, -1, "min"); min = luaL_optint(L, -1, 0); lua_pop(L, 1); lua_getfield(L, -1, "smax"); smax = luaL_optint(L, -1, 16); lua_pop(L, 1); lua_getfield(L, -1, "hmax"); hmax = luaL_optint(L, -1, 16); lua_pop(L, 1); lua_getfield(L, -1, "ttl"); ttl = luaL_optint(L, -1, 0); lua_pop(L, 1); if (apr_reslist_create(&reslist, min, smax, hmax, ttl, ml_apr_reslist_constructor, ml_apr_reslist_destructor, cb, cmd->pool) == APR_SUCCESS) { apr_hash_set(conf->resource, resource, strlen(resource), reslist); } else return "apr_reslist_create failed"; } } if (conf->resource == NULL) return "Out of memory"; return NULL; }
static apr_status_t init_ftpd_dbi(apr_pool_t * p, apr_pool_t * plog, apr_pool_t * ptemp, server_rec * s) { apr_status_t rv = APR_SUCCESS; int rval; dbi_driver dbi_driver; void *data; apr_hash_index_t *idx; char *key; ftpd_dbi_config *val; apr_ssize_t len; const char *userdata_key = "mod_ftpd_dbi_init"; /* dbi_config *conf = ap_get_module_config(s->module_config, * &ftpd_dbi_module); */ apr_pool_userdata_get(&data, userdata_key, s->process->pool); ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, plog, "[mod_ftpd_dbi.c] init."); if (!data) { apr_pool_userdata_set((const void *) 1, userdata_key, apr_pool_cleanup_null, s->process->pool); return OK; } ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, p, "[mod_ftpd_dbi.c] Running DBI init Code"); if ((rval = dbi_initialize(dbi_global_config.driverdir)) > 0) { if (dbi_global_config.driverdir == NULL) { ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, plog, "[mod_ftpd_dbi.c] Initialization of libdbi found %d drivers in default driver directory", rval); } else { ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, plog, "[mod_ftpd_dbi.c] Initialization of libdbi found %d drivers in directory %s", rval, dbi_global_config.driverdir); } if (s->loglevel >= APLOG_DEBUG) { dbi_driver = NULL; while ((dbi_driver = dbi_driver_list(dbi_driver)) != NULL) { ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, plog, "[mod_ftpd_dbi.c] Driver '%s' was loaded.", dbi_driver_get_name(dbi_driver)); } } } else { /* An error was returned or libdbi found 0 drivers */ if (dbi_global_config.driverdir == NULL) { ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, plog, "[mod_ftpd_dbi.c] - Initlialization of libdbi with default driver directory failed"); } else { ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, plog, "[mod_ftpd_dbi.c] - Initlialization of libdbi with FtpDbiDriverDir %s failed", dbi_global_config.driverdir); } return !APR_SUCCESS; } /* loop the hashed config stuff... */ for (idx = apr_hash_first(p, ftpd_dbi_config_hash); idx; idx = apr_hash_next(idx)) { apr_hash_this(idx, (void *) &key, &len, (void *) &val); apr_reslist_create(&val->pool, val->rec.conn_min, /* hard minimum */ val->rec.conn_soft, /* soft maximum */ val->rec.conn_max, /* hard maximum */ val->rec.conn_ttl, /* Time to live -- dbi server might override/disconnect! */ safe_dbi_new_conn, /* Make a New Connection */ safe_dbi_kill_conn, /* Kill Old Connection */ (void *) &val->rec, p); apr_hash_set(ftpd_dbi_config_hash, key, APR_HASH_KEY_STRING, val); } apr_pool_cleanup_register(p, p, kill_dbi, apr_pool_cleanup_null); ap_add_version_component(p, "mod_ftpd_dbi/" MOD_FTPD_DBI_VERSION); return rv; }