Beispiel #1
0
/*
 * (Try to) load the shared object `file'. Won't complain if it isn't a shared
 * object, but it will bitch about a shared object not having a
 * ``module_register'' symbol..
 */
static int plugin_load_file (char *file, uint32_t flags)
{
	lt_dlhandle dlh;
	void (*reg_handle) (void);

	lt_dlinit ();
	lt_dlerror (); /* clear errors */

#if LIBTOOL_VERSION == 2
	if (flags & PLUGIN_FLAGS_GLOBAL) {
		lt_dladvise advise;
		lt_dladvise_init(&advise);
		lt_dladvise_global(&advise);
		dlh = lt_dlopenadvise(file, advise);
		lt_dladvise_destroy(&advise);
	} else {
        	dlh = lt_dlopen (file);
	}
#else /* if LIBTOOL_VERSION == 1 */
	if (flags & PLUGIN_FLAGS_GLOBAL)
		WARNING ("plugin_load_file: The global flag is not supported, "
				"libtool 2 is required for this.");
	dlh = lt_dlopen (file);
#endif

	if (dlh == NULL)
	{
		char errbuf[1024] = "";

		ssnprintf (errbuf, sizeof (errbuf),
				"lt_dlopen (\"%s\") failed: %s. "
				"The most common cause for this problem are "
				"missing dependencies. Use ldd(1) to check "
				"the dependencies of the plugin "
				"/ shared object.",
				file, lt_dlerror ());

		ERROR ("%s", errbuf);
		/* Make sure this is printed to STDERR in any case, but also
		 * make sure it's printed only once. */
		if (list_log != NULL)
			fprintf (stderr, "ERROR: %s\n", errbuf);

		return (1);
	}

	if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
	{
		WARNING ("Couldn't find symbol \"module_register\" in \"%s\": %s\n",
				file, lt_dlerror ());
		lt_dlclose (dlh);
		return (-1);
	}

	(*reg_handle) ();

	return (0);
}
Beispiel #2
0
/*
 * (Try to) load the shared object `file'. Won't complain if it isn't a shared
 * object, but it will bitch about a shared object not having a
 * ``module_register'' symbol..
 */
static int plugin_load_file (char *file, uint32_t flags)
{
	lt_dlhandle dlh;
	void (*reg_handle) (void);

	DEBUG ("file = %s", file);

	lt_dlinit ();
	lt_dlerror (); /* clear errors */

#if LIBTOOL_VERSION == 2
	if (flags & PLUGIN_FLAGS_GLOBAL) {
		lt_dladvise advise;
		lt_dladvise_init(&advise);
		lt_dladvise_global(&advise);
		dlh = lt_dlopenadvise(file, advise);
		lt_dladvise_destroy(&advise);
	} else {
        	dlh = lt_dlopen (file);
	}
#else /* if LIBTOOL_VERSION == 1 */
	if (flags & PLUGIN_FLAGS_GLOBAL)
		ERROR ("plugin_load_file: The global flag is not supported, "
				"libtool 2 is required for this.");
	dlh = lt_dlopen (file);
#endif

	if (dlh == NULL)
	{
		const char *error = lt_dlerror ();

		ERROR ("lt_dlopen (%s) failed: %s", file, error);
		fprintf (stderr, "lt_dlopen (%s) failed: %s\n", file, error);
		return (1);
	}

	if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
	{
		WARNING ("Couldn't find symbol `module_register' in `%s': %s\n",
				file, lt_dlerror ());
		lt_dlclose (dlh);
		return (-1);
	}

	(*reg_handle) ();

	return (0);
}
Beispiel #3
0
/*
 * Load the configuration plugin from the given file.
 * If the configuration plugin structure is NULL then it is allocated.
 * This should normally be the case.
 */
int config_p_init(char *file) {
	char *buf = NULL;
	int len = 0;
	lt_dlhandle module = NULL;
	int (*config_init)(struct nv_config_p *);
	int stat = 0;
	int ret = 0;

	/* get reference to config plugin file */
	nv_log(NVLOG_INFO, "loading config plugin from %s", file);
	len = strlen(CONFIG_PATH)+strlen(file)+2;
	buf = nv_calloc(char, len);
	snprintf(buf, len, "%s/%s", CONFIG_PATH, file);
	module = lt_dlopen(buf);
	nv_free(buf);
	if (module == NULL) {
		nv_log(NVLOG_ERROR, "lt_dlopen(): %s", lt_dlerror());
		stat = -1;
		goto cleanup;
	}

	/* allocate memory for config plugin struct if necessary */
	if (nv_config_p == NULL) {
		nv_config_p = nv_calloc(struct nv_config_p, 1);
	}
Beispiel #4
0
/*
 * (Try to) load the shared object `file'. Won't complain if it isn't a shared
 * object, but it will bitch about a shared object not having a
 * ``module_register'' symbol..
 */
static int plugin_load_file (char *file)
{
	lt_dlhandle dlh;
	void (*reg_handle) (void);

	DEBUG ("file = %s", file);

	lt_dlinit ();
	lt_dlerror (); /* clear errors */

	if ((dlh = lt_dlopen (file)) == NULL)
	{
		const char *error = lt_dlerror ();

		ERROR ("lt_dlopen (%s) failed: %s", file, error);
		fprintf (stderr, "lt_dlopen (%s) failed: %s\n", file, error);
		return (1);
	}

	if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
	{
		WARNING ("Couldn't find symbol `module_register' in `%s': %s\n",
				file, lt_dlerror ());
		lt_dlclose (dlh);
		return (-1);
	}

	(*reg_handle) ();

	return (0);
}
Beispiel #5
0
EC_API ec_dlhandle EcDLOpen( const char *filename )
{
	lt_dlhandle dlhandle = NULL;

	dlhandle = lt_dlopen( filename );							/* for dlopen was: RTLD_LAZY | RTLD_GLOBAL */
	return (ec_dlhandle) dlhandle;
}
Beispiel #6
0
EmbracePlugin *embrace_plugin_new (const char *path)
{
	EmbracePlugin *ep;
	bool (*init)(EmbracePlugin *p);

	assert (path);

	if (!(ep = calloc (1, sizeof (EmbracePlugin))))
		return NULL;

	if (!(ep->handle = lt_dlopen (path))) {
		fprintf (stderr, "Cannot load plugin '%s': %s\n",
		         path, lt_dlerror ());
		embrace_plugin_free (ep);
		return NULL;
	}

	if (!(init = lt_dlsym (ep->handle, "embrace_plugin_init"))) {
		fprintf (stderr, "Cannot load plugin '%s': "
		         "cannot find init method!\n", path);
		embrace_plugin_free (ep);
		return NULL;
	}

	if (!(*init)(ep) || !ep->check) {
		fprintf (stderr, "Cannot load plugin '%s': "
		         "init method failed!\n", path);
		embrace_plugin_free (ep);
		return NULL;
	}

	return ep;
}
void PluginManager::start(){
  Logger* log = Logger::getLogger();

  std::string list = Settings::getSettings()->get("autoload_plugins");
  size_t pos_c = 0;
  size_t pos_e;
  if(list.length() > 0){
    while(pos_c != list.npos){
      pos_e = list.find(",", pos_c);
      load(list.substr(pos_c, pos_e));
      pos_c = pos_e;
    }
  }else{
    log->info("No automatically loaded plugins were defined in the "
        "configuation, add \"autoload_plugins = <comma list of plugins>\" to conf "
        "to have them loaded.");
  }

  /* Initalise the ltdl module. */
  LTDL_SET_PRELOADED_SYMBOLS();
  if(lt_dlinit() != 0){
    // FIXME: Should raise an error here.!
    log->error("Failed to load initalise the loader %s", lt_dlerror());
	stop();
  }

  /* Need to load ourselves before we can load other modules. */
  lt_dlhandle nlib = lt_dlopen(NULL);
  if(nlib == NULL){
    log->error("Failed to load ourselves because %s.", lt_dlerror());
	stop();
  }

}
Beispiel #8
0
//---------------------------------------------------------------------------
void MGL_EXPORT mgl_parser_load(HMPR pr, const char *so_name)
{
	if(!pr->AllowDllCall)	return;
#if MGL_HAVE_LTDL
	lt_dlhandle so = lt_dlopen(so_name);
	if(!so)	return;
	const mglCommand *cmd = (const mglCommand *)lt_dlsym(so,"mgl_cmd_extra");
	if(!cmd)	return;

	int i, mp, mc, exist=true;
	// determine the number of symbols
	for(i=0;pr->Cmd[i].name[0];i++){};	mp = i;
	for(i=0;cmd[i].name[0];i++)
		if(!pr->FindCommand(cmd[i].name))	exist=false;
	if(exist)	{	lt_dlclose(so);	return;	}	// all commands already presents
	else	pr->DllOpened.push_back(so);
	mc = i;
	mglCommand *buf = new mglCommand[mp+mc+1];
	memcpy(buf, pr->Cmd, mp*sizeof(mglCommand));
	memcpy(buf+mp, cmd, (mc+1)*sizeof(mglCommand));
	qsort(buf, mp+mc, sizeof(mglCommand), mgl_cmd_cmp);
	if(pr->Cmd!=mgls_base_cmd)	delete []pr->Cmd;
	pr->Cmd = buf;
#endif
}
/*
 * Load a module - this will load the shared object, call
 * C_Initialize, and get the list of function pointers
 */
void *
C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs)
{
	sc_pkcs11_module_t *mod;
	CK_RV (*c_get_function_list)(CK_FUNCTION_LIST_PTR_PTR);
	int rv;

	lt_dlinit();

	mod = (sc_pkcs11_module_t *) calloc(1, sizeof(*mod));
	mod->_magic = MAGIC;

	if (mspec == NULL)
		mspec = PKCS11_DEFAULT_MODULE_NAME;
	mod->handle = lt_dlopen(mspec);
	if (mod->handle == NULL) {
#if 0
		fprintf(stderr, "lt_dlopen failed: %s\n", lt_dlerror());
#endif
		goto failed;
	}

	/* Get the list of function pointers */
	c_get_function_list = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR))
				lt_dlsym(mod->handle, "C_GetFunctionList");
	if (!c_get_function_list)
		goto failed;
	rv = c_get_function_list(funcs);
	if (rv == CKR_OK)
		return (void *) mod;

failed:
	C_UnloadModule((void *) mod);
	return NULL;
}
int oph_ioserver_setup(const char *server_type, oph_ioserver_handler **handle)
{
  if (!handle){
    pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_NULL_HANDLE);
  	logging_server(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_COMMON_LOG, OPH_IOSERVER_LOG_NULL_HANDLE);    
    return OPH_IOSERVER_NULL_HANDLE;
  }

  oph_ioserver_handler *internal_handle = (oph_ioserver_handler *)malloc(sizeof(oph_ioserver_handler));

  internal_handle->server_type = NULL;
  internal_handle->server_subtype = NULL;
  internal_handle->lib = NULL;
  internal_handle->dlh = NULL;

  //Set storage server type 
  if(oph_parse_server_name (server_type, &internal_handle->server_type, &internal_handle->server_subtype)){
  	pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_SERVER_PARSE_ERROR);
  	logging_server(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_COMMON_LOG, OPH_IOSERVER_LOG_SERVER_PARSE_ERROR);    
    return OPH_IOSERVER_INVALID_PARAM;
  }

  //If already executed don't procede further
  if (internal_handle->dlh)  
    return OPH_IOSERVER_SUCCESS;

  //LTDL_SET_PRELOADED_SYMBOLS();
  if(lt_dlinit () != 0)
  {
	  pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_DLINIT_ERROR, lt_dlerror());
  	logging_server(LOG_ERROR, __FILE__, __LINE__, internal_handle->server_type,  OPH_IOSERVER_LOG_DLINIT_ERROR, lt_dlerror());    
    return OPH_IOSERVER_DLOPEN_ERR;
  }

  if (oph_find_server_plugin (internal_handle->server_type, &internal_handle->lib)){
	  pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_LIB_NOT_FOUND);
  	logging_server(LOG_ERROR, __FILE__, __LINE__, internal_handle->server_type, OPH_IOSERVER_LOG_LIB_NOT_FOUND);    
    return OPH_IOSERVER_LIB_NOT_FOUND;
  }

  if (!(internal_handle->dlh = (lt_dlhandle) lt_dlopen (internal_handle->lib)))
  {
	  pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_DLOPEN_ERROR, lt_dlerror());
  	logging_server(LOG_ERROR, __FILE__, __LINE__, internal_handle->server_type,  OPH_IOSERVER_LOG_DLOPEN_ERROR, lt_dlerror());    
    return OPH_IOSERVER_DLOPEN_ERR;
  }

  char func_name[OPH_IOSERVER_BUFLEN] = {'\0'};
  snprintf(func_name, OPH_IOSERVER_BUFLEN, OPH_IOSERVER_SETUP_FUNC, internal_handle->server_type);

  if (!(_SERVER_setup = (int (*)(oph_ioserver_handler *)) lt_dlsym (internal_handle->dlh, func_name))){
	  pmesg(LOG_ERROR, __FILE__, __LINE__, OPH_IOSERVER_LOG_LOAD_FUNC_ERROR, lt_dlerror());
  	logging_server(LOG_ERROR, __FILE__, __LINE__, internal_handle->server_type,  OPH_IOSERVER_LOG_LOAD_FUNC_ERROR, lt_dlerror());   
    return OPH_IOSERVER_DLSYM_ERR;
  }

  *handle = internal_handle; 
  return _SERVER_setup (*handle);
}
Beispiel #11
0
void loadobj(string pathname)
{
    char *err;

    dprintf(1,"loadobj: %s\n",pathname);
    dl_handle = lt_dlopen(pathname); 
    err = lt_dlerror();
    if (err != NULL) error("loadobj: error from dlopen: %s",err);
}
Beispiel #12
0
int netmatch_filter_ctor(struct netmatch_filter *netmatch, char const *libname)
{
    netmatch->libname = objalloc_strdup(libname);
    if (! netmatch->libname) {
        goto err0;
    }

    netmatch->handle = lt_dlopen(libname);
    if (! netmatch->handle) {
        SLOG(LOG_CRIT, "Cannot load netmatch shared object %s: %s", libname, lt_dlerror());
        goto err1;
    }
    (void)file_unlink(libname);

    netmatch->match_fun = lt_dlsym(netmatch->handle, "match");
    if (! netmatch->match_fun) {
        SLOG(LOG_CRIT, "Cannot find match function in netmatch shared object %s", libname);
        goto err2;
    }

    unsigned const *nb_regs_ptr = lt_dlsym(netmatch->handle, "nb_registers");
    if (! nb_regs_ptr) {
        SLOG(LOG_CRIT, "Cannot find nb_registers symbol in netmatch shared object %s", libname);
        goto err2;
    }

    netmatch->nb_registers = *nb_regs_ptr;
    if (netmatch->nb_registers > 0) {
        netmatch->regfile = objalloc_nice(netmatch->nb_registers * sizeof(*netmatch->regfile), "netmatches");
        if (! netmatch->regfile) goto err3;
        memset(netmatch->regfile, 0, netmatch->nb_registers * sizeof(*netmatch->regfile));
    } else {
        netmatch->regfile = NULL;
    }

    return 0;
err3:
    if (netmatch->regfile) {
        objfree(netmatch->regfile);
        netmatch->regfile = NULL;
    }
err2:
    if (netmatch->handle) {
        (void)lt_dlclose(netmatch->handle);
        netmatch->handle = NULL;
    }
err1:
    if (netmatch->libname) {
        objfree(netmatch->libname);
        netmatch->libname = NULL;
    }
err0:
    return -1;
}
Beispiel #13
0
int main( int argc, char *argv[] )
{
  void * dummy;

  lt_dlinit();
  dummy= lt_dlopen("dummy.so");

  if (dummy) lt_dlclose(dummy);

  return(0);
}
Beispiel #14
0
static int plibltpdl_open(const char *fname, bool use_ext, bool private_namespace,
                          pmix_pdl_handle_t **handle, char **err_msg)
{
    assert(handle);

    *handle = NULL;
    if (NULL != err_msg) {
        *err_msg = NULL;
    }

    lt_dlhandle local_handle;

#if PMIX_DL_LIBLTDL_HAVE_LT_DLADVISE
    pmix_pdl_plibltpdl_component_t *c = &mca_pdl_plibltpdl_component;

    if (use_ext && private_namespace) {
        local_handle = lt_dlopenadvise(fname, c->advise_private_ext);
    } else if (use_ext && !private_namespace) {
        local_handle = lt_dlopenadvise(fname, c->advise_public_ext);
    } else if (!use_ext && private_namespace) {
        local_handle = lt_dlopenadvise(fname, c->advise_private_noext);
    } else if (!use_ext && !private_namespace) {
        local_handle = lt_dlopenadvise(fname, c->advise_public_noext);
    }
#else
    if (use_ext) {
        local_handle = lt_dlopenext(fname);
    } else {
        local_handle = lt_dlopen(fname);
    }
#endif

    if (NULL != local_handle) {
        *handle = calloc(1, sizeof(pmix_pdl_handle_t));
        (*handle)->ltpdl_handle = local_handle;

#if PMIX_ENABLE_DEBUG
        if( NULL != fname ) {
            (*handle)->filename = strdup(fname);
        }
        else {
            (*handle)->filename = strdup("(null)");
        }
#endif

        return PMIX_SUCCESS;
    }

    if (NULL != err_msg) {
        *err_msg = (char*) lt_dlerror();
    }
    return PMIX_ERROR;
}
//function that gets information of each plugin
static int splt_p_open_get_plugins_data(splt_state *state)
{
  splt_plugins *pl = state->plug;
  int error = SPLT_OK;

  int i = 0;
  for (i = 0;i < pl->number_of_plugins_found;i++)
  {
    pl->data[i].plugin_handle = lt_dlopen(pl->data[i].plugin_filename);
    //error
    if (! pl->data[i].plugin_handle)
    {
      splt_u_print_debug("Error loading the plugin",0,pl->data[i].plugin_filename);
    }
    else
    {
      //get pointers to functions from the plugins
      //-this function must only be called once and here 
      *(void **) (&pl->data[i].func->check_plugin_is_for_file) =
        lt_dlsym(pl->data[i].plugin_handle, "splt_pl_check_plugin_is_for_file");
      *(void **) (&pl->data[i].func->search_syncerrors) =
        lt_dlsym(pl->data[i].plugin_handle, "splt_pl_search_syncerrors");
      *(void **) (&pl->data[i].func->dewrap) =
        lt_dlsym(pl->data[i].plugin_handle, "splt_pl_dewrap");
      *(void **) (&pl->data[i].func->simple_split) =
        lt_dlsym(pl->data[i].plugin_handle, "splt_pl_simple_split");
      *(void **) (&pl->data[i].func->split) =
        lt_dlsym(pl->data[i].plugin_handle, "splt_pl_split");
      *(void **) (&pl->data[i].func->init) =
        lt_dlsym(pl->data[i].plugin_handle, "splt_pl_init");
      *(void **) (&pl->data[i].func->end) =
        lt_dlsym(pl->data[i].plugin_handle, "splt_pl_end");
      *(void **) (&pl->data[i].func->scan_silence) =
        lt_dlsym(pl->data[i].plugin_handle, "splt_pl_scan_silence");
      *(void **) (&pl->data[i].func->set_original_tags) =
        lt_dlsym(pl->data[i].plugin_handle, "splt_pl_set_original_tags");
      *(void **) (&pl->data[i].func->set_plugin_info) =
        lt_dlsym(pl->data[i].plugin_handle, "splt_pl_set_plugin_info");
      if (pl->data[i].func->set_plugin_info != NULL)
      {
        pl->data[i].func->set_plugin_info(&pl->data[i].info,&error);
      }
      else
      {
      }
    }
  }

  return error;
}
Beispiel #16
0
void *xdlopen(const char *module)
{     void *h = NULL;
      if (lt_dlinit() != 0)
      {  lib_err_msg(lt_dlerror());
         goto done;
      }
      h = lt_dlopen(module);
      if (h == NULL)
      {  lib_err_msg(lt_dlerror());
         if (lt_dlexit() != 0)
            xerror("xdlopen: %s\n", lt_dlerror());
      }
done: return h;
}
Beispiel #17
0
void modena_function_load_library(modena_function_t* self)
{
    PyObject *pFunctionName =
        PyObject_GetAttrString(self->pFunction, "functionName");
    if(!pFunctionName){ Modena_PyErr_Print(); }

    PyObject *pLibraryName =
        PyObject_GetAttrString(self->pFunction, "libraryName");
    if(!pLibraryName){ Modena_PyErr_Print(); }

    self->handle = lt_dlopen(PyString_AsString(pLibraryName));

    if(!self->handle)
    {
        fprintf
        (
           stderr,
           "lt_dlopen: Could not open library %s\nlt_dlopen: %s\n",
           PyString_AsString(pLibraryName),
           lt_dlerror()
        );
        exit(1);
    }

    self->function = lt_dlsym(self->handle, PyString_AsString(pFunctionName));
    if(!self->function)
    {
        fprintf
        (
            stderr,
            "lt_dlsym: Could not find function %s in library %s\n"
            "lt_dlsym: %s",
            PyString_AsString(pFunctionName),
            PyString_AsString(pLibraryName),
            lt_dlerror()
        );
        lt_dlclose(self->handle);
        exit(1);
    }

    Py_DECREF(pFunctionName);
    Py_DECREF(pLibraryName);

    PyObject *pParameters =
        PyObject_GetAttrString(self->pFunction, "parameters");
    if(!pParameters){ Modena_PyErr_Print(); }
    self->parameters_size = PyObject_Size(pParameters);
    Py_DECREF(pParameters);
}
Beispiel #18
0
void *xdlopen(const char *module)
{     /* open dynamically linked library */
      void *h = NULL;
      if (lt_dlinit() != 0)
      {  put_err_msg(lt_dlerror());
         goto done;
      }
      h = lt_dlopen(module);
      if (h == NULL)
      {  put_err_msg(lt_dlerror());
         if (lt_dlexit() != 0)
            xerror("xdlopen: %s\n", lt_dlerror());
      }
done: return h;
}
Beispiel #19
0
/* Open all the preloaded modules from the named originator, executing
   a callback for each one.  If ORIGINATOR is NULL, then call FUNC for
   each preloaded module from the program itself.  */
int
lt_dlpreload_open (const char *originator, lt_dlpreload_callback_func *func)
{
  symlist_chain *list;
  int		 errors = 0;
  int		 found  = 0;

  /* For each symlist in the chain...  */
  for (list = preloaded_symlists; list; list = list->next)
    {
      /* ...that was preloaded by the requesting ORIGINATOR... */
      if ((originator && streq (list->symlist->name, originator))
          || (!originator && streq (list->symlist->name, "@PROGRAM@")))
	{
	  const lt_dlsymlist *symbol;
	  unsigned int idx = 0;

	  ++found;

	  /* ...load the symbols per source compilation unit:
	     (we preincrement the index to skip over the originator entry)  */
	  while ((symbol = &list->symlist[++idx])->name != 0)
	    {
	      if ((symbol->address == 0)
		  && (strneq (symbol->name, "@PROGRAM@")))
		{
		  lt_dlhandle handle = lt_dlopen (symbol->name);
		  if (handle == 0)
		    {
		      ++errors;
		    }
		  else
		    {
		      errors += (*func) (handle);
		    }
		}
	    }
	}
    }

  if (!found)
    {
      LT__SETERROR(CANNOT_OPEN);
      ++errors;
    }

  return errors;
}
Beispiel #20
0
int main( int argc, char *argv[] )
{
	void	*hDLL;
	void	(*pFunc)();
	const char	*pError;

	if ( argc < 2  )
	{
		printf( szSyntax );
		exit( 1 );
	}

    /*
     * initialize libtool
     */

    if ( lt_dlinit() )
	{
		printf( "ERROR: Failed to lt_dlinit()\n" );
		exit( 1 );
	}

    hDLL = lt_dlopen( argv[1] );
	if ( !hDLL )
	{
		printf( "[dltest] ERROR dlopen: %s\n", lt_dlerror() );
		exit( 1 );
	}
	printf( "SUCCESS: Loaded %s\n", argv[1] );
	if ( argc > 2 )
	{
		pFunc = (void (*)()) lt_dlsym( hDLL, argv[2] );
/* PAH - lt_dlerror() is not a good indicator of success    */
/*		if ( (pError = lt_dlerror()) != NULL )              */
		if ( !pFunc )
		{
            if ( (pError = lt_dlerror()) != NULL )
			    printf( "ERROR: %s\n Could not find %s\n", pError, argv[2] );
            else
			    printf( "ERROR: Could not find %s\n", argv[2] );
			exit( 1 );
		}
		printf( "SUCCESS: Found %s\n", argv[2] );
	}
	lt_dlclose( hDLL );

	return ( 0 );
}
Beispiel #21
0
static int 
slapi_int_load_plugin(
	Slapi_PBlock	*pPlugin,
	const char	*path,
	const char	*initfunc, 
	int		doInit,
	SLAPI_FUNC	*pInitFunc,
	lt_dlhandle	*pLdHandle ) 
{
	int		rc = LDAP_SUCCESS;
	SLAPI_FUNC	fpInitFunc = NULL;

	assert( pLdHandle != NULL );

	if ( lt_dlinit() ) {
		return LDAP_LOCAL_ERROR;
	}

	/* load in the module */
	*pLdHandle = lt_dlopen( path );
	if ( *pLdHandle == NULL ) {
		fprintf( stderr, "failed to load plugin %s: %s\n",
			 path, lt_dlerror() );
		return LDAP_LOCAL_ERROR;
	}

	fpInitFunc = (SLAPI_FUNC)lt_dlsym( *pLdHandle, initfunc );
	if ( fpInitFunc == NULL ) {
		fprintf( stderr, "failed to find symbol %s in plugin %s: %s\n",
			 initfunc, path, lt_dlerror() );
		lt_dlclose( *pLdHandle );
		return LDAP_LOCAL_ERROR;
	}

	if ( doInit ) {
		rc = ( *fpInitFunc )( pPlugin );
		if ( rc != LDAP_SUCCESS ) {
			lt_dlclose( *pLdHandle );
		}

	} else {
		*pInitFunc = fpInitFunc;
	}

	return rc;
}
Beispiel #22
0
int main () {
    cout << "begin main" << endl;
    lt_dlhandle _dl_c;
    NEW_C new_c;
    DEL_C del_c;
    c *_c;

    lt_dlinit ();

    _dl_c = lt_dlopen ("./c.so");
    if (! _dl_c) {
        cout << "lt_dlopen ./c.so failed" << endl;
        return -1;
    }

    new_c = (NEW_C) lt_dlsym (_dl_c, "new_c");
    if (! new_c) { 
        cout << "lt_dlsym failed: " << lt_dlerror () << endl;
        return -2;
    }

    del_c = (DEL_C) lt_dlsym (_dl_c, "del_c");
    if (! del_c) {
        cout << "lt_dlsym failed: " << lt_dlerror () << endl;
        return -3;
    }

    new_c (&_c, 5);

    _c->print_x ();

    cout << "_c->x = 10" << endl;
    _c->x = 10;

    _c->print_x ();

    del_c (_c);

    lt_dlclose (_dl_c);
    lt_dlexit ();

    cout << "end main" << endl;
    return 0;
}
Beispiel #23
0
static void arts_backend_ref()
{
	if(backend.refcnt == 0)
	{
    	lt_dlinit();
		backend.handle = lt_dlopen(ARTSC_BACKEND);

		if(backend.handle)
		{
			backend.init = (backend_init_ptr)
				lt_dlsym(backend.handle, "arts_backend_init");
			backend.suspend = (backend_suspend_ptr)
				lt_dlsym(backend.handle, "arts_backend_suspend");
			backend.suspended = (backend_suspended_ptr)
				lt_dlsym(backend.handle, "arts_backend_suspended");
			backend.free = (backend_free_ptr)
				lt_dlsym(backend.handle, "arts_backend_free");
			backend.play_stream = (backend_play_stream_ptr)
				lt_dlsym(backend.handle, "arts_backend_play_stream");
			backend.record_stream = (backend_record_stream_ptr)
				lt_dlsym(backend.handle, "arts_backend_record_stream");
			backend.close_stream = (backend_close_stream_ptr)
				lt_dlsym(backend.handle, "arts_backend_close_stream");
			backend.write = (backend_write_ptr)
				lt_dlsym(backend.handle, "arts_backend_write");
			backend.read = (backend_read_ptr)
				lt_dlsym(backend.handle, "arts_backend_read");
			backend.stream_set = (backend_stream_set_ptr)
				lt_dlsym(backend.handle, "arts_backend_stream_set");
			backend.stream_get = (backend_stream_get_ptr)
				lt_dlsym(backend.handle, "arts_backend_stream_get");
		}

		if(backend.handle && backend.init && backend.free && backend.play_stream
			&& backend.record_stream && backend.close_stream && backend.write
			&& backend.read && backend.stream_set && backend.stream_get
			&& backend.suspend)
			backend.available = 1;
		else
			backend.available = 0;
	}
	backend.refcnt++;
}
Beispiel #24
0
static const char *dlink(const char *dlopen_file_spec) {
	pa_dlinit();

	lt_dlhandle handle=lt_dlopen(dlopen_file_spec);

	if(!handle){
		if(const char* result=lt_dlerror())
			return result;
		return "can not open the dynamic link module";
	}

	GLINK(memcached);
	DLINK(memcached_create);
	DLINK(memcached_free);
	DLINK(memcached_strerror);

	DLINK(memcached_server_push);
	DLINK(memcached_servers_parse);
	DLINK(memcached_version);

	DLINK(memcached_flush);
	DLINK(memcached_quit);

	DLINK(memcached_get);
	DLINK(memcached_delete);
	DLINK(memcached_mget);
	DLINK(memcached_set);
	DLINK(memcached_add);

	DLINK(memcached_fetch_result);
	DLINK(memcached_result_create);
	DLINK(memcached_result_free);

	DLINK(memcached_result_key_value);
	DLINK(memcached_result_value);
	DLINK(memcached_result_key_length);
	DLINK(memcached_result_length);
	DLINK(memcached_result_flags);

	return 0;
}
bool datasource_cache::register_datasource(std::string const& str)
{
    bool success = false;
    try
    {
        lt_dlhandle module = lt_dlopen(str.c_str());
        if (module)
        {
            // http://www.mr-edd.co.uk/blog/supressing_gcc_warnings
#ifdef __GNUC__
            __extension__
#endif
                datasource_name* ds_name =
                reinterpret_cast<datasource_name*>(lt_dlsym(module, "datasource_name"));
            if (ds_name && insert(ds_name(),module))
            {
                MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Registered=" << ds_name();

                success = true;
            }
            else if (!ds_name)
            {
                MAPNIK_LOG_ERROR(datasource_cache)
                        << "Problem loading plugin library '"
                        << str << "' (plugin is lacking compatible interface)";
            }
        }
        else
        {
            MAPNIK_LOG_ERROR(datasource_cache)
                    << "Problem loading plugin library: " << str
                    << " (dlopen failed - plugin likely has an unsatisfied dependency or incompatible ABI)";
        }
    }
    catch (...) {
            MAPNIK_LOG_ERROR(datasource_cache)
                    << "Exception caught while loading plugin library: " << str;
    }
    return success;
}
Beispiel #26
0
/*
 * Get the named functions from the user interface
 * library. If no library is configured, or if the
 * libray doesn't define the named symbol, fall back
 * to the default function
 */
static int sc_ui_get_func(sc_context_t *ctx, const char *name, void **ret)
{
	*ret = NULL;
	if (!sc_ui_lib_handle && !sc_ui_lib_loaded) {
		const char	*lib_name = NULL;
		scconf_block	*blk;
		int		i;

		/* Prevent recursion */
		sc_ui_lib_loaded = 1;

		for (i = 0; (blk = ctx->conf_blocks[i]); i++) {
			lib_name = scconf_get_str(blk,
				       	"user_interface",
					NULL);
			if (lib_name)
				break;
		}

		if (!lib_name)
			return 0;

		sc_ui_lib_handle = lt_dlopen(lib_name);
		if (!sc_ui_lib_handle) {
			sc_error(ctx,
				"Unable to open user interface library '%s': %s\n",
				lib_name, lt_dlerror());
			return SC_ERROR_INTERNAL;
		}
	}

	if (sc_ui_lib_handle == NULL)
		return 0;

	*ret = lt_dlsym(sc_ui_lib_handle, name);

	return *ret ? SC_SUCCESS : SC_ERROR_UNKNOWN;
}
Beispiel #27
0
  PosibErr<Speller *> get_speller_class(Config * config)
  {
    String name = config->retrieve("module");
    assert(name == "default");
    return libaspell_speller_default_LTX_new_speller_class(0);
#if 0
    unsigned int i; 
    for (i = 0; i != aspell_speller_funs_size; ++i) {
      if (strcmp(name.c_str(), aspell_speller_funs[i].name) == 0) {
	return (*aspell_speller_funs[i].fun)(config, 0);
      }
    }
  
#ifdef USE_LTDL
    int s = lt_dlinit();
    assert(s == 0);
    String libname;
    libname  = LIBDIR "/libaspell_";
    libname += name;
    libname += ".la";
    lt_dlhandle h = lt_dlopen (libname.c_str());
    if (h == 0)
      return (new CanHaveErrorImpl())
	->set_error(cant_load_module, name.c_str());
    lt_ptr_t fun = lt_dlsym (h, "new_aspell_speller_class");
    assert (fun != 0);
    CanHaveError * m = (*(NewSpellerClass)(fun))(config, h);
    assert (m != 0);
    if (m->error_number() != 0)
      free_lt_handle(h);
    return m;
#else
    return (new CanHaveErrorImpl())
      ->set_error(cant_load_module, name.c_str());
#endif
#endif
  }
Beispiel #28
0
/* Load Module name */
int module_open(char *path, char *name) {
  char file[BUFFER_LEN];
  int (*module_loader)(struct module_entry_t *);
  struct module_entry_t *module;
  void *handle;

  memset(file, '\0', BUFFER_LEN);
  snprintf(file, BUFFER_LEN, "%s/%s", path, name);

  handle = lt_dlopen(file);

  if(!handle) {
    do_rawlog(LT_ERR, "Error Loading Module: %s | %s ", file, lt_dlerror());
    return 0;
  }

  /* Some OSes may need symbols to be prefixed with _.. Will need to look into autoconfig code for this */
  module_loader = MODULE_FUNCRET(handle, "module_load");

  if(!module_loader) {
    do_rawlog(LT_ERR, "Error Loading Module: Could not call module_load | %s", file);
    return 0;
  }

  /* Add the module to the linked list */
  module = module_entry_add(name);
  if(module == NULL) {
    return 0;
  }
  module->handle = handle;
  module->load = module_loader;
  module->unload = MODULE_FUNCRET(handle, "module_unload");
  
  /* Grab info and version from module & put it in */
  /* Success.. Call the module */
  return module_loader(module);
}
Beispiel #29
0
/* load a particular module */
int neb_load_module(nebmodule *mod) {
	int (*initfunc)(int, char *, void *);
	int *module_version_ptr = NULL;
	int result = OK;


	if (mod == NULL || mod->filename == NULL)
		return ERROR;

	/* don't reopen the module */
	if (mod->is_currently_loaded == TRUE)
		return OK;

	/* don't load modules unless they should be loaded */
	if (mod->should_be_loaded == FALSE)
		return ERROR;

	/**********
	   Using dlopen() is great, but a real danger as-is.  The problem with loaded modules is that if you overwrite the original file (e.g. using 'mv'),
	   you do not alter the inode of the original file.  Since the original file/module is memory-mapped in some fashion, Icinga will segfault the next
	   time an event broker call is directed to one of the module's callback functions.  This is extremely problematic when it comes to upgrading NEB
	   modules while Icinga is running.  A workaround is to (1) 'mv' the original/loaded module file to another name (on the same filesystem)
	   and (2) copy the new module file to the location of the original one (using the original filename).  In this scenario, dlopen() will keep referencing
	   the original file/inode for callbacks.  This is not an ideal solution.   A better one is to delete the module file once it is loaded by dlopen().
	   This prevents other processed from unintentially overwriting the original file, which would cause Icinga to crash.  However, if we delete the file
	   before anyone else can muck with it, things should be good.  'lsof' shows that a deleted file is still referenced by the kernel and callback
	   functions continue to work once the module has been loaded.  Long story, but this took quite a while to figure out, as there isn't much
	   of anything I could find on the subject other than some sketchy info on similar problems on HP-UX.  Hopefully this will save future coders some time.
	   So... the trick is to (1) copy the module to a temp file, (2) dlopen() the temp file, and (3) immediately delete the temp file.
	************/

	/* 2010-01-05 MF: Patch taken from OMD into Icinga Core
		   OMD: Do not make a copy of the module, but directly load it. This prevents problems with a tmpfs which
	   is mounted as user. OMD users surely have no problems with modules overwritten by 'cp in runtime. Anyway,
	   the usual way to install files is 'install', which removes and recreates the file (just as tar, rpm and
	   many other installation-tools do). */

	/* load the module (use the temp copy we just made) */
#ifdef USE_LTDL
	mod->module_handle = lt_dlopen(mod->filename);
#else
	mod->module_handle = (void *)dlopen(mod->filename, RTLD_NOW | RTLD_GLOBAL);
#endif
	if (mod->module_handle == NULL) {

#ifdef USE_LTDL
		logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Could not load module '%s' -> %s\n", mod->filename, lt_dlerror());
#else
		logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Could not load module '%s' -> %s\n", mod->filename, dlerror());
#endif

		return ERROR;
	}

	/* find module API version */
#ifdef USE_LTDL
	module_version_ptr = (int *)lt_dlsym(mod->module_handle, "__neb_api_version");
#else
	module_version_ptr = (int *)dlsym(mod->module_handle, "__neb_api_version");
#endif

	/* mark the module as being loaded */
	mod->is_currently_loaded = TRUE;

	/* check the module API version */
	if (module_version_ptr == NULL || ((*module_version_ptr) != CURRENT_NEB_API_VERSION)) {

		logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Module '%s' is using an old or unspecified version of the event broker API.  Module will be unloaded.\n", mod->filename);

		neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_API_VERSION);

		return ERROR;
	}

	/* locate the initialization function */
#ifdef USE_LTDL
	mod->init_func = lt_dlsym(mod->module_handle, "nebmodule_init");
#else
	mod->init_func = (void *)dlsym(mod->module_handle, "nebmodule_init");
#endif

	/* if the init function could not be located, unload the module */
	if (mod->init_func == NULL) {

		logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Could not locate nebmodule_init() in module '%s'.  Module will be unloaded.\n", mod->filename);

		neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_NO_INIT);

		return ERROR;
	}

	/* run the module's init function */
	initfunc = mod->init_func;
	result = (*initfunc)(NEBMODULE_NORMAL_LOAD, mod->args, mod->module_handle);

	/* if the init function returned an error, unload the module */
	if (result != OK) {

		logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Function nebmodule_init() in module '%s' returned an error.  Module will be unloaded.\n", mod->filename);

		neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_BAD_INIT);

		return ERROR;
	}

	logit(NSLOG_INFO_MESSAGE, FALSE, "Event broker module '%s' initialized successfully.\n", mod->filename);

	/* locate the de-initialization function (may or may not be present) */
#ifdef USE_LTDL
	mod->deinit_func = lt_dlsym(mod->module_handle, "nebmodule_deinit");
#else
	mod->deinit_func = (void *)dlsym(mod->module_handle, "nebmodule_deinit");
#endif

	log_debug_info(DEBUGL_EVENTBROKER, 0, "Module '%s' loaded with return code of '%d'\n", mod->filename, result);
	if (mod->deinit_func != NULL)
		log_debug_info(DEBUGL_EVENTBROKER, 0, "nebmodule_deinit() found\n");

	return OK;
}
Beispiel #30
0
sidl_bool
impl_sidl_DLL_loadLibrary(
  /* in */ sidl_DLL self,
  /* in */ const char* uri,
  /* in */ sidl_bool loadGlobally,
  /* in */ sidl_bool loadLazy,
  /* out */ sidl_BaseInterface *_ex)
{
  *_ex = 0;
  {
  /* DO-NOT-DELETE splicer.begin(sidl.DLL.loadLibrary) */
  struct sidl_DLL__data *data = sidl_DLL__get_data(self);

  int         ok      = FALSE;
  lt_dlhandle handle  = NULL;
  char*       dllfile = NULL;
  char*       dllname = NULL;

  if (data->d_library_handle) {
    impl_sidl_DLL_unloadLibrary(self,_ex);
  }

  if (sidl_String_equals(uri, "main:")) {
    dllfile = NULL;
    dllname = sidl_String_strdup(uri);
#if !defined(PIC) && defined(SIDL_PURE_STATIC_RUNTIME)
    data->d_isGlobal = TRUE;
    data->d_isLazy = FALSE;
    data->d_library_handle = NULL;
    data->d_library_name = dllname;
    return TRUE;
#endif

  } else if (sidl_String_startsWith(uri, "lib:")) {
    char* dll = sidl_String_substring(uri, 4);
    dllfile = sidl_String_concat3("lib", dll, ".la");
    dllname = sidl_String_strdup(uri);
    sidl_String_free(dll);

  } else if (sidl_String_startsWith(uri, "file:")) {
    dllfile = sidl_String_substring(uri, 5);
    dllname = sidl_String_strdup(uri);

#ifdef HAVE_LIBWWW
  } else if (sidl_String_startsWith(uri, "ftp:")) {
    dllfile = url_to_local_file(uri);
    dllname = sidl_String_strdup(uri);

  } else if (sidl_String_startsWith(uri, "http:")) {
    dllfile = url_to_local_file(uri);
    dllname = sidl_String_strdup(uri);
#endif

  } else {
    dllfile = sidl_String_strdup(uri);
    dllname = sidl_String_concat2("file:", uri);
  }

  if (s_sidl_debug_dlopen) showLoading(dllfile);
  check_lt_initialized();
#if defined(PIC) || !defined(SIDL_PURE_STATIC_RUNTIME)
  handle = lt_dlopen(dllfile, loadGlobally, loadLazy);
#else
  handle = NULL;
#endif
  if (s_sidl_debug_dlopen) showLoadResult((void *)handle);
  sidl_String_free(dllfile);

  if (handle) {
    ok = TRUE;
    data->d_library_handle = handle;
    data->d_library_name   = dllname;
    data->d_isLazy = loadLazy;
    data->d_isGlobal = loadGlobally;
  } else {
    ok = FALSE;
    sidl_String_free(dllname);
  }

  return ok;
  /* DO-NOT-DELETE splicer.end(sidl.DLL.loadLibrary) */
  }
}