PUBLIC int mprUnloadModule(MprModule *mp) { mprDebug("mpr", 5, "Unloading native module %s from %s", mp->name, mp->path); if (mprStopModule(mp) < 0) { return MPR_ERR_NOT_READY; } #if ME_COMPILER_HAS_DYN_LOAD if (mp->flags & MPR_MODULE_LOADED) { if (mprUnloadNativeModule(mp) != 0) { mprLog("error mpr", 0, "Cannot unload module %s", mp->name); } } #endif mprRemoveItem(MPR->moduleService->modules, mp); return 0; }
int mprUnloadModule(MprModule *mp) { mprLog(6, "Unloading native module %s from %s", mp->name, mp->path); if (mprStopModule(mp) < 0) { return MPR_ERR_NOT_READY; } #if BIT_HAS_DYN_LOAD if (mp->handle) { if (mprUnloadNativeModule(mp) != 0) { mprError("Can't unload module %s", mp->name); } mp->handle = 0; } #endif mprRemoveItem(MPR->moduleService->modules, mp); return 0; }
PUBLIC int mprLoadNativeModule(MprModule *mp) { MprModuleEntry fn; void *handle; assert(mp); /* Search the image incase the module has been statically linked */ #ifdef RTLD_DEFAULT handle = RTLD_DEFAULT; #else #ifdef RTLD_MAIN_ONLY handle = RTLD_MAIN_ONLY; #else handle = 0; #endif #endif if (!mp->entry || !dlsym(handle, mp->entry)) { #if ME_STATIC mprLog("error mpr", 0, "Cannot load module %s, product built static", mp->name); return MPR_ERR_BAD_STATE; #else MprPath info; char *at; if ((at = mprSearchForModule(mp->path)) == 0) { mprLog("error mpr", 0, "Cannot find module \"%s\", cwd: \"%s\", search path \"%s\"", mp->path, mprGetCurrentPath(), mprGetModuleSearchPath()); return MPR_ERR_CANT_ACCESS; } mp->path = at; mprGetPathInfo(mp->path, &info); mp->modified = info.mtime; mprLog("info mpr", 5, "Loading native module %s", mprGetPathBase(mp->path)); if ((handle = dlopen(mp->path, RTLD_LAZY | RTLD_GLOBAL)) == 0) { mprLog("error mpr", 0, "Cannot load module %s, reason: \"%s\"", mp->path, dlerror()); return MPR_ERR_CANT_OPEN; } mp->handle = handle; mp->flags |= MPR_MODULE_LOADED; #endif /* !ME_STATIC */ } else if (mp->entry) { mprLog("info mpr", 4, "Activating native module %s", mp->name); } if (mp->entry) { if ((fn = (MprModuleEntry) dlsym(handle, mp->entry)) != 0) { if ((fn)(mp->moduleData, mp) < 0) { mprLog("error mpr", 0, "Initialization for module %s failed", mp->name); mprUnloadNativeModule(mp); return MPR_ERR_CANT_INITIALIZE; } } else { mprLog("error mpr", 0, "Cannot load module %s, reason: cannot find function \"%s\"", mp->path, mp->entry); mprUnloadNativeModule(mp); return MPR_ERR_CANT_READ; } } return 0; }