Example #1
0
static int __ts_load_module(struct tsdev *ts, const char *module, const char *params, int raw)
{
	struct tslib_module_info *info;
	void *handle;
	int ret;

#ifdef DEBUG
	printf ("Loading module %s\n", module);
#endif

	info = __ts_load_module_static(ts, module, params);
	if (!info)
		info = __ts_load_module_shared(ts, module, params);
	if (!info)
		return -1;

	if (raw)
		ret = __ts_attach_raw(ts, info);
	else
		ret = __ts_attach(ts, info);

	if (ret) {
#ifdef DEBUG
		fprintf (stderr, "Can't attach %s\n", module);
#endif
		handle = info->handle;
		info->ops->fini(info);
		if (handle)
			dlclose(handle);
	}

	return ret;
}
int __ts_load_module(struct tsdev *ts, const char *module, const char *params, int raw)
{
	struct tslib_module_info * (*init)(struct tsdev *, const char *);
	struct tslib_module_info *info;
	char fn[1024];
	void *handle;
	int ret;
	char *plugin_directory=NULL;

	if( (plugin_directory = getenv("TSLIB_PLUGINDIR")) != NULL ) {
		//fn = alloca(sizeof(plugin_directory) + strlen(module) + 4);
		strcpy(fn,plugin_directory);
	} else {
		//fn = alloca(sizeof(PLUGIN_DIR) + strlen(module) + 4);
		strcpy(fn, PLUGIN_DIR);
	}

	strcat(fn, "/");
	strcat(fn, module);
	strcat(fn, ".so");

#ifdef DEBUG
	printf ("Loading module %s\n", fn);
#endif
	handle = dlopen(fn, RTLD_NOW);
	if (!handle)
		return -1;

	init = dlsym(handle, "mod_init");
	if (!init) {
		dlclose(handle);
		return -1;
	}

	info = init(ts, params);
	if (!info) {
		dlclose(handle);
		return -1;
	}

	info->handle = handle;

	if (raw) {
		ret = __ts_attach_raw(ts, info);
	} else {
		ret = __ts_attach(ts, info);
	}
	if (ret) {
		info->ops->fini(info);
		dlclose(handle);
	}

	return ret;
}
Example #3
0
static int
ts_load_module(struct tsdev *ts, int i, int raw)
{
	struct tslib_module_info *info;
	int  ret = 0;
		
	info = (mod_init[i])(ts, ts_par[i]);
	if (!info) {
		return -1;
	}

	if (raw) {
		ret = __ts_attach_raw(ts, info);
	} else {
		ret = __ts_attach(ts, info);
	}

	if (ret) {
		info->ops->fini(info);
	}

	return ret;
}