NSAPI_PUBLIC cache_t * cache_create(unsigned int cache_max, unsigned int hash_size, public_cache_functions_t *fnlist) { cache_t *newentry; unsigned int index; SOLARIS_PROBE(cache_create_start, "cache"); NS_ASSERT(cache_max > 0); NS_ASSERT(hash_size > 0); NS_ASSERT(fnlist); if ( (newentry = (cache_t *)PERM_MALLOC(sizeof(cache_t))) == NULL) { ereport(LOG_FAILURE, XP_GetAdminStr(DBT_insufficientMemoryToCreateHashTa_)); SOLARIS_PROBE(cache_create_end, "cache"); return NULL; } #ifdef CACHE_DEBUG newentry->magic = CACHE_MAGIC; #endif newentry->cache_size = 0; newentry->hash_size = hash_size; newentry->max_size = cache_max; newentry->insert_ok = 0; newentry->insert_fail = 0; newentry->deletes = 0; newentry->cache_hits = 0; newentry->cache_lookups = 0; newentry->lock = crit_init(); newentry->virtual_fn = fnlist; if ( (newentry->table = (cache_entry_t **) PERM_MALLOC((sizeof(cache_entry_t *)) * (newentry->hash_size))) == NULL) { ereport(LOG_FAILURE, XP_GetAdminStr(DBT_insufficientMemoryToCreateHashTa_1)); SOLARIS_PROBE(cache_create_end, "cache"); return NULL; } for (index=0; index<newentry->hash_size; index++) newentry->table[index] = NULL; newentry->mru_head = newentry->lru_head = NULL; #ifdef IRIX newentry->fast_mode = 0; newentry->garbage_list_head = NULL; newentry->gc_time = 0; #endif if (!cache_crit) cache_crit = crit_init(); crit_enter(cache_crit); newentry->next = cache_list; cache_list = newentry; crit_exit(cache_crit); SOLARIS_PROBE(cache_create_end, "cache"); return newentry; }
/* Allocate a mutex */ TSRM_API MUTEX_T tsrm_mutex_alloc(void) { MUTEX_T mutexp; #ifdef TSRM_WIN32 mutexp = malloc(sizeof(CRITICAL_SECTION)); InitializeCriticalSection(mutexp); #elif defined(GNUPTH) mutexp = (MUTEX_T) malloc(sizeof(*mutexp)); pth_mutex_init(mutexp); #elif defined(PTHREADS) mutexp = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(mutexp,NULL); #elif defined(NSAPI) mutexp = crit_init(); #elif defined(PI3WEB) mutexp = PIPlatform_allocLocalMutex(); #elif defined(TSRM_ST) mutexp = st_mutex_new(); #elif defined(BETHREADS) mutexp = (beos_ben*)malloc(sizeof(beos_ben)); mutexp->ben = 0; mutexp->sem = create_sem(1, "PHP sempahore"); #endif #ifdef THR_DEBUG printf("Mutex created thread: %d\n",mythreadid()); #endif return( mutexp ); }
NSAPI_PUBLIC ACLListHandle_t * ACL_ParseString( NSErr_t *errp, char *buffer ) { ACLListHandle_t *handle = NULL; int eid = 0; int rv = 0; const char *errmsg; ACL_InitAttr2Index(); if ( acl_parse_crit == NULL ) acl_parse_crit = crit_init(); crit_enter( acl_parse_crit ); if ( acl_InitScanner( errp, NULL, buffer ) < 0 ) { rv = ACLERRNOMEM; eid = ACLERR1920; nserrGenerate(errp, rv, eid, ACL_Program, 0); } else { handle = ACL_ListNew(errp); if ( handle == NULL ) { rv = ACLERRNOMEM; eid = ACLERR1920; nserrGenerate(errp, rv, eid, ACL_Program, 0); } else if ( acl_PushListHandle( handle ) < 0 ) { rv = ACLERRNOMEM; eid = ACLERR1920; nserrGenerate(errp, rv, eid, ACL_Program, 0); } else if ( acl_Parse() ) { rv = ACLERRPARSE; eid = ACLERR1780; } if ( acl_EndScanner() < 0 ) { rv = ACLERROPEN; eid = ACLERR1500; errmsg = system_errmsg(); nserrGenerate(errp, rv, eid, ACL_Program, 2, "buffer", errmsg); } } if ( rv || eid ) { ACL_ListDestroy(errp, handle); handle = NULL; } crit_exit( acl_parse_crit ); return(handle); }
NSAPI_PUBLIC FSMUTEX fsmutex_init(char *name, int number, int flags) { fsmutex_s *ret = (fsmutex_s *) PERM_MALLOC(sizeof(fsmutex_s)); ret->flags = flags; if(_fsmutex_create(ret, name, number) == -1) { PERM_FREE(ret); return NULL; } #ifdef THREAD_ANY if(flags & FSMUTEX_NEEDCRIT) ret->crit = crit_init(); #endif return (FSMUTEX) ret; }
/** ************************************************************************** * Internal initialization. Always called, from lib/httpdaemon/WebServer.cpp * */ void reqlimit_init_crits() { reqlimit_crit = crit_init(); anon_bucket.count = 0; anon_bucket.time = time(NULL); anon_bucket.state = REQ_NOACTION; anon_bucket.conc = 0; hashtable = PL_NewHashTable(0, PL_HashString, PL_CompareStrings, PL_CompareValues, NULL, NULL); next_timeout = time(NULL) + purge_timeout; // Initializes a "slot" for our reqlimit_conc_done() function. See // call to request_set_data() in check_request_limits() for more. req_cleanup = request_alloc_slot(&reqlimit_conc_done); assert(req_cleanup != -1); }
WA_recursiveLock WA_createLock(const char *name) { NSAPIThreadRecursiveLock *lock; lock = WOMALLOC(sizeof(NSAPIThreadRecursiveLock)); if (lock) { lock->crit = crit_init(); lock->condvar = condvar_init(lock->crit); lock->lockCount = 0; lock->lockingThread = NULL; if (name) lock->name = name; else lock->name = unnamedLock; } if (!lock) WOLog(WO_ERR, "WA_createLock() failed for lock %s", name ? name : unnamedLock); return lock; }
NSAPI_PUBLIC int web_agent_init(pblock *param, Session *sn, Request *rq) { am_status_t status; int nsapi_status = REQ_PROCEED; char *temp_buf = NULL; char *agent_bootstrap_file = NULL; char *agent_config_file = NULL; initLock = crit_init(); temp_buf = pblock_findval(DSAME_CONF_DIR, param); if (temp_buf != NULL) { agent_bootstrap_file = system_malloc(strlen(temp_buf) + sizeof(AGENT_BOOTSTRAP_FILE)); agent_config_file = system_malloc(strlen(temp_buf) + sizeof(AGENT_CONFIG_FILE)); if (agent_bootstrap_file != NULL) { strcpy(agent_bootstrap_file, temp_buf); strcat(agent_bootstrap_file, AGENT_BOOTSTRAP_FILE); } else { log_error(LOG_FAILURE, "URL Access Agent: ", sn, rq, "web_agent_init() unable to allocate memory for bootstrap " "file name", DSAME_CONF_DIR); nsapi_status = REQ_ABORTED; } if (agent_config_file != NULL) { strcpy(agent_config_file, temp_buf); strcat(agent_config_file, AGENT_CONFIG_FILE); } else { log_error(LOG_FAILURE, "URL Access Agent: ", sn, rq, "web_agent_init() unable to allocate memory for local config " "file name", DSAME_CONF_DIR); nsapi_status = REQ_ABORTED; } status = am_properties_create(&agent_props.agent_bootstrap_props); if(status == AM_SUCCESS) { status = am_properties_load(agent_props.agent_bootstrap_props, agent_bootstrap_file); if(status == AM_SUCCESS) { //this is where the agent config info is passed from filter code //to amsdk. Not sure why agent_props is required. status = am_web_init(agent_bootstrap_file, agent_config_file); system_free(agent_bootstrap_file); system_free(agent_config_file); if (AM_SUCCESS != status) { log_error(LOG_FAILURE, "URL Access Agent: ", sn, rq, "Initialization of the agent failed: " "status = %s (%d)", am_status_to_string(status), status); nsapi_status = REQ_ABORTED; } } else { log_error(LOG_FAILURE, "web_agent_init():", sn, rq, "Error while creating properties object= %s", am_status_to_string(status)); nsapi_status = REQ_ABORTED; } } else { log_error(LOG_FAILURE, "web_agent_init():", sn, rq, "Error while creating properties object= %s", am_status_to_string(status)); nsapi_status = REQ_ABORTED; } } else { log_error(LOG_FAILURE, "URL Access Agent: ", sn, rq, "web_agent_init() %s variable not defined in magnus.conf", DSAME_CONF_DIR); nsapi_status = REQ_ABORTED; } if(nsapi_status == REQ_PROCEED) { daemon_atrestart(&agent_cleanup, NULL); } return nsapi_status; }