/** * Remove the cache lock, if present. * * First, try to close the file handle, whose delete-on-close should * kill the file. Otherwise, just delete the file by name. * * If no lock name has yet been calculated, do the calculation of the * lock name first before trying to delete the file. * * If an optional bucket brigade is passed, the lock will only be * removed if the bucket brigade contains an EOS bucket. */ apr_status_t cache_remove_lock(cache_server_conf *conf, cache_request_rec *cache, request_rec *r, apr_bucket_brigade *bb) { void *dummy; const char *lockname; if (!conf || !conf->lock || !conf->lockpath) { /* no locks configured, leave */ return APR_SUCCESS; } if (bb) { apr_bucket *e; int eos_found = 0; for (e = APR_BRIGADE_FIRST(bb); e != APR_BRIGADE_SENTINEL(bb); e = APR_BUCKET_NEXT(e)) { if (APR_BUCKET_IS_EOS(e)) { eos_found = 1; break; } } if (!eos_found) { /* no eos found in brigade, don't delete anything just yet, * we are not done. */ return APR_SUCCESS; } } apr_pool_userdata_get(&dummy, CACHE_LOCKFILE_KEY, r->pool); if (dummy) { return apr_file_close((apr_file_t *)dummy); } apr_pool_userdata_get(&dummy, CACHE_LOCKNAME_KEY, r->pool); lockname = (const char *)dummy; if (!lockname) { char dir[5]; /* create the key if it doesn't exist */ if (!cache->key) { cache_generate_key(r, r->pool, &cache->key); } /* create a hashed filename from the key, and save it for later */ lockname = ap_cache_generate_name(r->pool, 0, 0, cache->key); /* lock files represent discrete just-went-stale URLs "in flight", so * we support a simple two level directory structure, more is overkill. */ dir[0] = '/'; dir[1] = lockname[0]; dir[2] = '/'; dir[3] = lockname[1]; dir[4] = 0; lockname = apr_pstrcat(r->pool, conf->lockpath, dir, "/", lockname, NULL); } return apr_file_remove(lockname, r->pool); }
int ml_session_save(lua_State* L) { if (ap_session_save) { apr_status_t status; session_rec *sess; request_rec *r = CHECK_REQUEST_OBJECT(1); status = apr_pool_userdata_get((void**)&sess, "ml_session", r->pool); if (status == APR_SUCCESS) { if (sess != NULL) { status = ap_session_save(r, sess); if (status == APR_SUCCESS) { lua_pushboolean(L, 1); return 1; } return ml_push_status(L, status); } lua_pushboolean(L, 0); return 1; } return ml_push_status(L, status); } return 0; }
int modperl_restart_count(void) { void *data; apr_pool_userdata_get(&data, MP_RESTART_COUNT_KEY, modperl_global_get_server_rec()->process->pool); return data ? *(int *)data : 0; }
/* Set up startup-time initialization */ static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { void *data; const char *userdata_key = "llzr_init"; llzr_config *conf = ap_get_module_config(parms->server->module_config, &llzr_module); conf->redisconn = redisConnect(conf->redis_host, conf->redis_port); if (conf->redisconn == NULL || conf->redisconn->err) { if (conf->redisconn) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "Redis error encountered %s", conf->redisconn->errstr); redisFree(c); } else { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "Unable to connect to redis server"); } /* We don't want to kill our site if Redis goes down, but we would be susceptible to attack */ } apr_pool_userdata_get(&data, userdata_key, s->process->pool); if (!data) { apr_pool_userdata_set((const void *)1, userdata_key,apr_pool_cleanup_null, s->process->pool); return OK; } /* Lets get details from the MPM */ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, MODULE_NAME " " MODULE_VERSION " started"); ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit); ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit); return OK; }
static int amagent_init(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { /* main process init */ int status; apr_status_t rv = APR_SUCCESS; void *data; #define AMAGENT_INIT_ONCE "AMAGENT_INIT_ONCE" apr_pool_userdata_get(&data, AMAGENT_INIT_ONCE, s->process->pool); if (!data) { /* module has already been initialized */ apr_pool_userdata_set((const void *) 1, AMAGENT_INIT_ONCE, apr_pool_cleanup_null, s->process->pool); return rv; } apr_pool_cleanup_register(pconf, s, amagent_cleanup, apr_pool_cleanup_null); ap_add_version_component(pconf, MODINFO); LOG_S(APLOG_DEBUG, s, "amagent_init() %d", getpid()); #ifndef _WIN32 status = am_init(); if (status != AM_SUCCESS) { rv = APR_EINIT; LOG_S(APLOG_ERR, s, "amagent_init() status: %s", am_strerror(status)); } #endif return rv; }
/* run in post config hook ( we are parent process and we are uid 0) */ static int ruid_init (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { UNUSED(p); UNUSED(plog); UNUSED(ptemp); void *data; const char *userdata_key = "ruid2_init"; /* keep capabilities after setuid */ prctl(PR_SET_KEEPCAPS,1); /* initialize_module() will be called twice, and if it's a DSO * then all static data from the first call will be lost. Only * set up our static data on the second call. */ apr_pool_userdata_get(&data, userdata_key, s->process->pool); if (!data) { apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool); } else { ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, MODULE_NAME "/" MODULE_VERSION " enabled"); /* MaxRequestsPerChild MUST be 1 to enable drop capability mode */ if (ap_max_requests_per_child == 1) { ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, MODULE_NAME " is in drop capability mode"); cap_mode = RUID_CAP_MODE_DROP; } } return OK; }
ZEKE_HIDDEN struct zktool_vxid_pool *zktool_vxid_factory(apr_pool_t *pool) { struct zktool_vxid_pool *vp = NULL; apr_status_t st; st = apr_pool_userdata_get((void**)&vp,"LIBZEKE:zktool_vxid",pool); if(st != APR_SUCCESS || !vp) { vp = apr_palloc(pool,VXID_SIZEOF(*vp)); assert(vp != NULL); vp->magic = ZKTOOL_VXID_MAGIC; vp->p = pool; VXID(vp).base = &vxid_base; VXID(vp).chunk = &vxid_chunk; #ifdef ZEKE_USE_THREADS vp->busy = 0; vp->waiter = 0; assert(apr_thread_mutex_create(&vp->mutex,APR_THREAD_MUTEX_DEFAULT,pool) == APR_SUCCESS); assert(apr_thread_cond_create(&vp->cond,pool) == APR_SUCCESS); #endif assert(apr_pool_userdata_setn(vp,"LIBZEKE:zktool_vxid",NULL,pool) == APR_SUCCESS); } zktool_vxid_get(vp); return vp; }
static int php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { void *data = NULL; const char *userdata_key = "apache2hook_post_config"; /* Apache will load, unload and then reload a DSO module. This * prevents us from starting PHP until the second load. */ apr_pool_userdata_get(&data, userdata_key, s->process->pool); if (data == NULL) { /* We must use set() here and *not* setn(), otherwise the * static string pointed to by userdata_key will be mapped * to a different location when the DSO is reloaded and the * pointers won't match, causing get() to return NULL when * we expected it to return non-NULL. */ apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool); return OK; } /* Set up our overridden path. */ if (apache2_php_ini_path_override) { apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override; } #ifdef ZTS tsrm_startup(1, 1, 0, NULL); (void)ts_resource(0); ZEND_TSRMLS_CACHE_UPDATE; #endif sapi_startup(&apache2_sapi_module); apache2_sapi_module.startup(&apache2_sapi_module); apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null); php_apache_add_version(pconf); return OK; }
/* * connect to Redis server */ static redisContext * oidc_cache_redis_connect(request_rec *r, oidc_cache_cfg_redis_t *context) { /* see if we already have a connection by looking it up in the process context */ redisContext *ctx = NULL; apr_pool_userdata_get((void **) &ctx, OIDC_CACHE_REDIS_CONTEXT, r->server->process->pool); if (ctx == NULL) { /* no connection, connect to the configured Redis server */ ctx = redisConnect(context->host_str, context->port); /* check for errors */ if ((ctx == NULL) || (ctx->err != 0)) { oidc_error(r, "failed to connect to Redis server (%s:%d): '%s'", context->host_str, context->port, ctx->errstr); return NULL; } /* store the connection in the process context */ apr_pool_userdata_set(ctx, OIDC_CACHE_REDIS_CONTEXT, (apr_status_t (*)(void *)) redisFree, r->server->process->pool); /* log the connection */ oidc_debug(r, "successfully connected to Redis server (%s:%d)", context->host_str, context->port); } return ctx; }
static int svc_simulator_256b_post_config( apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *svr_rec) { apr_status_t status = APR_SUCCESS; void *data = NULL; const char *userdata_key = "svc_simulator_256b_init"; svc_simulator_256b_config_rec_t *conf = (svc_simulator_256b_config_rec_t *)ap_get_module_config( svr_rec->module_config, &svc_simulator_256b_module); /* svc_simulator_256b_post_config() will be called twice. Don't bother * going through all of the initialization on the first call * because it will just be thrown away.*/ ap_add_version_component(pconf, SVC_SIMULATOR_HTTP_HEADER_SERVER_SVC_SIMULATOR); apr_pool_userdata_get(&data, userdata_key, svr_rec->process->pool); if(!data) { apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, svr_rec->process->pool); return OK; } return OK; }
/** * Crypto decoding for the session. * * @param r The request pointer. * @param z A pointer to where the session will be written. */ static apr_status_t session_crypto_decode(request_rec * r, session_rec * z) { char *encoded = NULL; apr_status_t res; const apr_crypto_t *f = NULL; session_crypto_dir_conf *dconf = ap_get_module_config(r->per_dir_config, &session_crypto_module); if ((dconf->passphrases_set) && z->encoded && *z->encoded) { apr_pool_userdata_get((void **)&f, CRYPTO_KEY, r->server->process->pconf); res = decrypt_string(r, f, dconf, z->encoded, &encoded); if (res != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, res, r, APLOGNO(01842) "decrypt session failed, wrong passphrase?"); return res; } z->encoded = encoded; } return OK; }
static int dosdetector_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { void *user_data; apr_pool_userdata_get(&user_data, USER_DATA_KEY, s->process->pool); if (user_data == NULL) { apr_pool_userdata_set((const void *)(1), USER_DATA_KEY, apr_pool_cleanup_null, s->process->pool); return OK; } apr_status_t rv = create_shm(s, p); if(rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, "failed to create shared memory"); return HTTP_INTERNAL_SERVER_ERROR; } apr_pool_cleanup_register(p, NULL, cleanup_shm, apr_pool_cleanup_null); rv = ap_global_mutex_create(&lock, NULL, mutex_id, NULL, s, p, 0); if(rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, "failed to create global mutex"); return HTTP_INTERNAL_SERVER_ERROR; } #ifdef _DEBUG const char *mutex_name = apr_global_mutex_name(lock); DEBUGLOG("mutex name is %s", mutex_name); const char *mutex_filename = apr_global_mutex_lockfile(lock); DEBUGLOG("mutex filename is %s", mutex_filename); #endif apr_pool_cleanup_register(p, NULL, cleanup_mutex, apr_pool_cleanup_null); return OK; }
void ssl_scache_init(server_rec *s, apr_pool_t *p) { SSLModConfigRec *mc = myModConfig(s); /* * Warn the user that he should use the session cache. * But we can operate without it, of course. */ if (mc->nSessionCacheMode == SSL_SCMODE_UNSET) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "Init: Session Cache is not configured " "[hint: SSLSessionCache]"); mc->nSessionCacheMode = SSL_SCMODE_NONE; return; } if (mc->nSessionCacheMode == SSL_SCMODE_DBM) ssl_scache_dbm_init(s, p); else if ((mc->nSessionCacheMode == SSL_SCMODE_SHMHT) || (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)) { void *data; const char *userdata_key = "ssl_scache_init"; apr_pool_userdata_get(&data, userdata_key, s->process->pool); if (!data) { apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool); return; } if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT) ssl_scache_shmht_init(s, p); else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB) ssl_scache_shmcb_init(s, p); } }
SWITCH_DECLARE(void *) switch_core_memory_pool_get_data(switch_memory_pool_t *pool, const char *key) { void *data = NULL; apr_pool_userdata_get(&data, key, pool); return data; }
static void post_pool_clear(abts_case *tc, void *data) { apr_status_t rv; void *retdata; rv = apr_pool_userdata_get(&retdata, "DOESNTEXIST", pool); ABTS_INT_EQUAL(tc, rv, APR_SUCCESS); ABTS_PTR_EQUAL(tc, retdata, NULL); }
static int req_mime_types(lua_State *L) { request_rec *r = CHECK_REQUEST_OBJECT(1); apr_pool_t *p = r->connection->base_server->process->pool; const char* resource_name = luaL_checkstring(L, 2); int set = lua_isnoneornil(L, 3) ? 0 : lua_toboolean(L, 3); apr_hash_t *mimes = NULL; apr_status_t rc = apr_pool_userdata_get((void**)&mimes, "mod_luaex", p); const char* fn, *ext, *fntmp; const char* type = NULL; if (rc == APR_SUCCESS && mimes) { if ((fn = ap_strrchr_c(resource_name, '/')) == NULL) { fn = resource_name; } else { ++fn; } /* Always drop the path leading up to the file name. */ /* The exception list keeps track of those filename components that * are not associated with extensions indicating metadata. * The base name is always the first exception (i.e., "txt.html" has * a basename of "txt" even though it might look like an extension). * Leading dots are considered to be part of the base name (a file named * ".png" is likely not a png file but just a hidden file called png). */ fntmp = fn; while (*fntmp == '.') fntmp++; fntmp = ap_strchr_c(fntmp, '.'); if (fntmp) { fn = fntmp + 1; ext = apr_pstrdup(r->pool, fn); } else { ext = apr_pstrdup(r->pool, fn); fn += strlen(fn); } if (set && (type = apr_hash_get(mimes, ext, APR_HASH_KEY_STRING)) != NULL) { ap_set_content_type(r, (char*) type); } } if (type) lua_pushstring(L, type); else lua_pushnil(L); return 1; }
/* * shm init. it should be called in ap_hook_post_config phase * code partially from mod_auth_digest.c */ static int shm_init(apr_pool_t *p, server_rec *s) { apr_status_t ret; void *data; const char *userdata_key = "akismet_dummy_key"; /* initialize_module() will be called twice, and if it's a DSO * then all static data from the first call will be lost. Only * set up our static data on the second call. */ apr_pool_userdata_get(&data, userdata_key, s->process->pool); if (!data) { apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool); return OK; /* This would be the first time through */ } if ( ret = apr_shm_create(&api_cache_shm, API_CACHE_SHM_SIZE, api_cache_shm_file, p) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, ret, s, "Failed to create shared segment file '%s'", api_cache_shm_file ); return HTTP_INTERNAL_SERVER_ERROR; } if (ret = apr_global_mutex_create(&global_lock, global_lock_file, APR_LOCK_DEFAULT, p) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, ret, s, "Failed to create global mutex file '%s'", global_lock_file); return HTTP_INTERNAL_SERVER_ERROR; } #ifdef AP_NEED_SET_MUTEX_PERMS if( ret = unixd_set_global_mutex_perms(global_lock) != APR_SUCCESS ) { ap_log_perror(APLOG_MARK, APLOG_CRIT, ret, p, "%s:Failed to set mutex permission. " "please check out parent process's privileges!"); return HTTP_INTERNAL_SERVER_ERROR; } #endif key_verified_infos = apr_shm_baseaddr_get(api_cache_shm); if (!key_verified_infos) { ap_log_error(APLOG_MARK, APLOG_CRIT, -1, s, "failed to allocate shared memory" ); return HTTP_INTERNAL_SERVER_ERROR; } /* Clear all key_verified_info */ int i; for (i = 0; i < NUM_BUCKETS; i++) { key_verified_infos[i].status = -1; memset(key_verified_infos[i].key, 0, 1024); } /* Register a cleanup function */ apr_pool_cleanup_register(p, NULL, cleanup_shm_resources, apr_pool_cleanup_null); return OK; }
static void get_userdata(abts_case *tc, void *data) { apr_status_t rv; void *retdata; rv = apr_pool_userdata_get(&retdata, "TEST", pool); ABTS_INT_EQUAL(tc, rv, APR_SUCCESS); ABTS_STR_EQUAL(tc, retdata, testdata); }
/* * This callback is called when the parent initialized. * Note that this can happen multiple times. */ static int but_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { void *data; const char *userdata_key = "but_init_module"; apr_status_t status; /* * The following checks if this routine has been called before. * This is necessary because the parent process gets initialized * a couple of times as the server starts up, and we don't want * to create any more mutexes and shared memory segments than * we're actually going to use. */ apr_pool_userdata_get(&data, userdata_key, s->process->pool); if (!data) { apr_pool_userdata_set((const void *) 1, userdata_key, apr_pool_cleanup_null, s->process->pool); return OK; } /* Create the shared memory segments. */ status = but_shm_initialize(pconf, plog, ptemp, s); if (status != APR_SUCCESS) { ERRLOG_SRV_CRIT("Failed to initialize session SHM."); return HTTP_INTERNAL_SERVER_ERROR; } status = but_shm_initialize_cookiestore(pconf, plog, ptemp, s); if (status != APR_SUCCESS) { ERRLOG_SRV_CRIT("Failed to initialize cookiestore SHM."); return HTTP_INTERNAL_SERVER_ERROR; } /* Create the module mutex. */ /* * Create another unique filename to lock upon. Note that * depending on OS and locking mechanism of choice, the file * may or may not be actually created. */ status = apr_global_mutex_create(&but_mutex, tmpnam(NULL), APR_LOCK_DEFAULT, pconf); if (status != APR_SUCCESS) { ERRLOG_SRV_CRIT("Failed to create mutex."); return HTTP_INTERNAL_SERVER_ERROR; } #ifdef MOD_BUT_SET_MUTEX_PERMS status = unixd_set_global_mutex_perms(but_mutex); if (status != APR_SUCCESS) { ERRLOG_SRV_CRIT("Failed to set mutex permissions."); return HTTP_INTERNAL_SERVER_ERROR; } #endif /* MOD_BUT_SET_MUTEX_PERMS */ return OK; }
int tee_grab_stats(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { if (!global_stats) { // Getting pointer to global stats from pool userdata. See create_stats. apr_pool_userdata_get((void *) &global_stats, STATUS_USERDATA_KEY, s->process->pool); ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, "tee: Graceful restart, grabbing previous data (pid %d)", getpid()); } return OK; }
apr_status_t proc_kill_gracefully(fcgid_procnode *procnode, server_rec *main_server) { HANDLE *finish_event = NULL; apr_pool_userdata_get((void **) &finish_event, FINISH_EVENT_DATA_NAME, procnode->proc_pool); if (finish_event != NULL) SetEvent(*finish_event); return APR_SUCCESS; }
int ml_socache_lookup(lua_State*L) { const request_rec* r = CHECK_REQUEST_OBJECT(1); server_rec *s = r->server; apr_pool_t *pool = s->process->pool; //store provider in pool const char *provider_id = luaL_checkstring(L, 2); apr_time_t timeout = luaL_optint(L, 3, 30 * 60); const char *provider_name = luaL_optstring(L, 4, AP_SOCACHE_DEFAULT_PROVIDER); const char *provider_arg = luaL_optstring(L, 5, NULL); ml_socache *c = NULL; apr_status_t status = APR_SUCCESS; char socache_key[128]; struct ap_socache_hints hints = {0}; hints.avg_id_len = 64; hints.avg_obj_size = 1024; hints.expiry_interval = timeout; apr_snprintf(socache_key, 128, "%s_%s_%s", provider_id, provider_name, AP_SOCACHE_PROVIDER_GROUP); status = apr_pool_userdata_get((void**)&c, socache_key, pool); if ( status == APR_SUCCESS ) { if (c == NULL) { const char* err; c = lua_newuserdata(L, sizeof(ml_socache)); c->_provider = ap_lookup_provider(AP_SOCACHE_PROVIDER_GROUP, provider_name, AP_SOCACHE_PROVIDER_VERSION); err = c->_provider->create(&c->_instance, provider_arg, pool, pool); if (err) { luaL_error(L, err); } c->_provider->init(c->_instance, provider_id, &hints, s, pool); c->_server = s; c->_timeout = timeout * APR_USEC_PER_SEC; c->_maxdatalen = 1024; apr_pool_userdata_set(c, socache_key, apr_pool_cleanup_null, pool); } c->_pool = r->pool; lua_boxpointer(L, c); luaL_getmetatable(L, "mod_luaex.socache"); lua_setmetatable(L, -2); } else { char err[APR_PATH_MAX]; apr_strerror(status, err, APR_PATH_MAX); luaL_error(L, err); } return 1; }
static apr_bucket_brigade* get_bb(request_rec* r) { apr_bucket_brigade *bb = NULL; int s = apr_pool_userdata_get((void**)&bb, "bb", r->pool); if (s == 0) { if (bb == NULL) { bb = apr_brigade_create(r->pool, r->connection->bucket_alloc); apr_pool_userdata_set(bb, "bb", NULL, r->pool); } } return bb; }
/* Dynamically shared modules are loaded twice by apache! * Then we set a dummy information in the server's pool's * userdata*/ static int __rainx_is_first_call(server_rec *server) { const char *userdata_key = "rainx_hook_post_config"; void *data; apr_pool_userdata_get(&data, userdata_key, server->process->pool); if (!data) { apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, server->process->pool); return 1; } return 0; }
void serf_ssl_client_cert_password_set( serf_ssl_context_t *context, serf_ssl_need_cert_password_t callback, void *data, void *cache_pool) { context->cert_pw_callback = callback; context->cert_pw_userdata = data; context->cert_pw_cache_pool = cache_pool; if (context->cert_pw_cache_pool) { apr_pool_userdata_get((void**)&context->cert_pw_success, "serf:ssl:certpw", cache_pool); } }
static int process_security_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { void *data; const char *userdata_key = "process_security_init"; prctl(PR_SET_KEEPCAPS,1); apr_pool_userdata_get(&data, userdata_key, s->process->pool); if (!data) apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool); else ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, MODULE_NAME "/" MODULE_VERSION " mechanism enabled"); return OK; }
/* make sure the shared memory is cleaned */ static int initialize_cleanup(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { void *data; const char *userdata_key = "mod_sharedmem_init"; apr_pool_userdata_get(&data, userdata_key, s->process->pool); if (!data) { apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool); return OK; } sharedmem_initialize_cleanup(p); return OK; }
static int psgi_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { dTHX; const void *key; char *file; SV *app; apr_hash_index_t *hi; void *data; const char *userdata_key = "psgi_post_config"; psgi_apps_t *psgi_apps = NULL; apr_status_t rc; 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; } ap_add_version_component(pconf, apr_psprintf(pconf, "mod_psgi/%s", MOD_PSGI_VERSION)); mutex_name = apr_psprintf(pconf, "/tmp/psgi_mutex.%ld", (long int) getpid()); rc = apr_global_mutex_create(&psgi_mutex, (const char *) mutex_name, APR_LOCK_DEFAULT, pconf); if (rc != APR_SUCCESS) { return DECLINED; } rc = apr_global_mutex_lock(psgi_mutex); if (rc != APR_SUCCESS) { return DECLINED; } /* shared name to store apps */ shm_name = apr_pstrdup(pconf, "/tmp/psgi_shm"); rc = apr_shm_attach(&psgi_shm, (const char *) shm_name, pconf); if (rc != APR_SUCCESS) { rc = apr_shm_create(&psgi_shm, sizeof(psgi_apps_t), (const char *) shm_name, pconf); } if (rc == APR_SUCCESS) { psgi_apps = (psgi_apps_t *)apr_shm_baseaddr_get(psgi_shm); psgi_apps->apps = apr_hash_make(pconf); } apr_global_mutex_unlock(psgi_mutex); return OK; }
SSLModConfigRec *ssl_config_global_create(server_rec *s) { apr_pool_t *pool = s->process->pool; SSLModConfigRec *mc; void *vmc; apr_pool_userdata_get(&vmc, SSL_MOD_CONFIG_KEY, pool); if (vmc) { return vmc; /* reused for lifetime of the server */ } /* * allocate an own subpool which survives server restarts */ mc = (SSLModConfigRec *)apr_palloc(pool, sizeof(*mc)); mc->pPool = pool; mc->bFixed = FALSE; /* * initialize per-module configuration */ mc->nSessionCacheMode = SSL_SCMODE_UNSET; mc->szSessionCacheDataFile = NULL; mc->nSessionCacheDataSize = 0; mc->pSessionCacheDataMM = NULL; mc->pSessionCacheDataRMM = NULL; mc->tSessionCacheDataTable = NULL; mc->nMutexMode = SSL_MUTEXMODE_UNSET; mc->nMutexMech = APR_LOCK_DEFAULT; mc->szMutexFile = NULL; mc->pMutex = NULL; mc->aRandSeed = apr_array_make(pool, 4, sizeof(ssl_randseed_t)); mc->tVHostKeys = apr_hash_make(pool); mc->tPrivateKey = apr_hash_make(pool); mc->tPublicCert = apr_hash_make(pool); #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT) mc->szCryptoDevice = NULL; #endif memset(mc->pTmpKeys, 0, sizeof(mc->pTmpKeys)); apr_pool_userdata_set(mc, SSL_MOD_CONFIG_KEY, apr_pool_cleanup_null, pool); return mc; }
static int mod_mruby_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { apr_status_t status = apr_thread_mutex_create(&mod_mruby_mutex, APR_THREAD_MUTEX_DEFAULT, p); TRACER; if(status != APR_SUCCESS){ ap_log_error(APLOG_MARK , APLOG_ERR , 0 , ap_server_conf , APLOGNO(05001) "%s ERROR %s: Error creating thread mutex." , MODULE_NAME , __func__ ); return DECLINED; } void *data = NULL; const char *userdata_key = "mruby_init"; ap_log_error(APLOG_MARK , APLOG_INFO , 0 , ap_server_conf , APLOGNO(05002) "%s %s: main process / thread (pid=%d) initialized." , MODULE_NAME , __func__ , getpid() ); apr_pool_userdata_get(&data, userdata_key, p); if (!data) apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, p); ap_log_error(APLOG_MARK , APLOG_NOTICE , 0 , ap_server_conf , APLOGNO(05003) "%s %s: %s / %s mechanism enabled." , MODULE_NAME , __func__ , MODULE_NAME , MODULE_VERSION ); return DECLINED; }