Ejemplo n.º 1
0
int mod_init(void **mod_ctx){
    int rc = MOD_OK;
    sysh_ctx_t ctx = NULL;
    char *initd_dir = NULL;

    *mod_ctx = NULL;
    
    if ( !(ctx = (sysh_ctx_t)malloc(sizeof(struct sysh_ctx))) ){
        rc = MOD_ERR_MEM;
        goto err;
    }
    ctx->initd_dir = NULL;

    initd_dir = getenv("WRTCTL_SYS_INITD_DIR");
    if ( !initd_dir )
        initd_dir = "/etc/init.d/";
    if ( !(ctx->initd_dir = strdup(initd_dir)) ){
        rc = MOD_ERR_MEM;
        goto err;
    }

    (*mod_ctx) = ctx;
    return rc;

err:
    if( ctx ) mod_destroy((void*)ctx);
    return rc;
}
Ejemplo n.º 2
0
void unload_modules(void) {
	module_t* mod = first_module;
	module_t* next;

	while(mod != NULL) {
		next = mod->mod_next;
		mod_destroy(mod);
		mod = next;
	}
}
Ejemplo n.º 3
0
int init_rl_table(unsigned int size)
{
	unsigned int i;

	rl_htable.maps = shm_malloc(sizeof(map_t) * size);
	if (!rl_htable.maps) {
		LM_ERR("no more shm memory\n");
		return -1;
	}

	memset(rl_htable.maps, 0, sizeof(map_t) * size);
	for (i = 0; i < size; i++) {
		rl_htable.maps[i] = map_create(AVLMAP_SHARED);
		if (!rl_htable.maps[i]) {
			LM_ERR("cannot create map index %d\n", i);
			goto error;
		}
		rl_htable.size++;
	}

	if (!rl_default_algo_s.s) {
		LM_ERR("Default algorithm was not specified\n");
		return -1;
	}
	/* resolve the default algorithm */
	rl_default_algo = get_rl_algo(rl_default_algo_s);
	if (rl_default_algo < 0) {
		LM_ERR("unknown algoritm <%.*s>\n", rl_default_algo_s.len,
				rl_default_algo_s.s);
		return -1;
	}
	LM_DBG("default algorithm is %.*s [ %d ]\n",
			rl_default_algo_s.len, rl_default_algo_s.s, rl_default_algo);

	/* if at least 25% of the size locks can't be allocated
	 * we return an error */
	for ( i = size; i > size / 4; i--) {
		rl_htable.locks = lock_set_alloc(i);
		if (!rl_htable.locks)
			continue;
		if (!lock_set_init(rl_htable.locks)) {
			lock_set_dealloc(rl_htable.locks);
			rl_htable.locks = 0;
			continue;
		}
		break;
	}

	if (!rl_htable.locks) {
		LM_ERR("unable to allocted at least %d locks for the hash table\n",
				size/4);
		goto error;
	}
	rl_htable.locks_no = i;

	LM_DBG("%d locks allocated for %d hashsize\n",
			rl_htable.locks_no, rl_htable.size);

	return 0;
error:
	mod_destroy();
	return -1;
}
Ejemplo n.º 4
0
module_t* mod_load(const char* path_name) {
	module_t* mod = mod_create();
	int* api_version;
	int* type;
	int err = 0;

	boolean_t flag = B_FALSE;

	assert(mod != NULL);

	logmsg(LOG_INFO, "Loading module %s ...", path_name);

	err = plat_mod_open(&mod->mod_library, path_name);

	if(err != 0) {
		logmsg(LOG_WARN, "Failed loading, platform-specific error code: %d", err);
		logerror();

		goto fail;
	}

	strcpy(mod->mod_path, path_name);

	/*Load module api version and name*/

	MOD_LOAD_SYMBOL(api_version, mod, "mod_api_version", flag);
	MOD_LOAD_SYMBOL(type, mod, "mod_type", flag);
	MOD_LOAD_SYMBOL(mod->mod_name, mod, "mod_name", flag);

	if(flag)
		goto fail;

	if(*type != mod_type) {
		logmsg(LOG_INFO, "Ignoring module - wrong type %d", *type);

		goto fail;
	}

	if(*api_version != MOD_API_VERSION) {
		logmsg(LOG_WARN, "Wrong api version %d", *api_version);

		goto fail;
	}

	if(mod_search(mod->mod_name) != NULL) {
		logmsg(LOG_WARN, "Module %s already exists", mod->mod_name);

		goto fail;
	}

	MOD_LOAD_SYMBOL(mod->mod_config, mod, "mod_config", flag);
	MOD_LOAD_SYMBOL(mod->mod_unconfig, mod, "mod_unconfig", flag);

	/*Call helper*/
	mod->mod_status = MOD_UNCONFIGURED;

	if(mod->mod_config(mod) != MOD_OK) {
		logmsg(LOG_INFO, "Failed to configure module %s (path: %s)", mod->mod_name, path_name);

		goto fail;
	}

	logmsg(LOG_INFO, "Loaded module %s (path: %s)", mod->mod_name, path_name);

	mod->mod_status = MOD_READY;
	mod_add(mod);

	return mod;

fail:
	if(err != 0)
		plat_mod_close(&mod->mod_library);

	logmsg(LOG_WARN, "Failed to load module %s!", path_name);

	mod_destroy(mod);

	return NULL;
}