Logo Search packages:      
Sourcecode: tablix2 version File versions  Download package

module* module_load ( char *  name,
moduleoption opt 
)

Loads a module. After the module is loaded, module_init() function is called.

Parameters:
name File name of the module (example: "timeplace.so").
opt Linked list of options for this module.
Returns:
Pointer to the module structure of the loaded module or NULL on error.

Definition at line 641 of file modsup.c.

References debug(), error(), module_t::handle, modulelist_new(), modulelist_t::modules, module_t::name, module_t::next, and option_int().

Referenced by parser_modules().

                                                   {
      module *dest;
      char pathname[1024];
      init_f init;
      int n;

      assert(name!=NULL);
      assert(opt!=NULL);
      assert(option_int(opt,"weight")>=0);
      assert(option_int(opt,"mandatory")==0||option_int(opt,"mandatory")==1);

      if(mod_list==NULL) {
            mod_list=modulelist_new();
            if(mod_list==NULL) return NULL;
      }

      dest=malloc(sizeof(*dest));
      if(dest==NULL) return(NULL);

      snprintf(pathname, 1024, "%s/%s", HAVE_MODULE_PATH, name);
      debug(_("Loading module %s"), pathname);
      dest->handle=dlopen(pathname, RTLD_NOW);
      if(!dest->handle) {
            msg_send("modsup", MSG_ERROR, dlerror());
            free(dest);
            return(NULL);
      }

      init=dlsym(dest->handle,"module_init");
      if(!init) {
            msg_send("modsup", MSG_ERROR, dlerror());
            free(dest);
            return(NULL);
      }

      n=(*init)(opt);
      if(n) {
            error(_("Initialization for module %s failed"), name);
            dlclose(dest->handle);
            free(dest);
            return(NULL);
      }

      dest->name=strdup(name);

      dest->next=mod_list->modules;
      mod_list->modules=dest;
      return(dest);
}


Generated by  Doxygen 1.6.0   Back to index