/* close (unload) a particular module */ int neb_unload_module(nebmodule *mod, int flags, int reason) { int (*deinitfunc)(int, int); int result = OK; if(mod == NULL) return ERROR; log_debug_info(DEBUGL_EVENTBROKER, 0, "Attempting to unload module '%s': flags=%d, reason=%d\n", mod->filename, flags, reason); /* remove the module's demand-loaded file */ if(daemon_dumps_core == TRUE && mod->dl_file) { (void)unlink(mod->dl_file); my_free(mod->dl_file); } /* call the de-initialization function if available (and the module was initialized) */ if(mod->deinit_func && reason != NEBMODULE_ERROR_BAD_INIT) { deinitfunc = mod->deinit_func; /* module can opt to not be unloaded */ result = (*deinitfunc)(flags, reason); /* if module doesn't want to be unloaded, exit with error (unless its being forced) */ if(result != OK && !(flags & NEBMODULE_FORCE_UNLOAD)) return ERROR; } /* deregister all of the module's callbacks */ neb_deregister_module_callbacks(mod); if(mod->core_module == FALSE) { /* unload the module */ result = dlclose(mod->module_handle); if (result != 0) { logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Could not unload module '%s' -> %s\n", mod->filename, dlerror()); return ERROR; } } /* mark the module as being unloaded */ mod->is_currently_loaded = FALSE; log_debug_info(DEBUGL_EVENTBROKER, 0, "Module '%s' unloaded successfully.\n", mod->filename); logit(NSLOG_INFO_MESSAGE, FALSE, "Event broker module '%s' deinitialized successfully.\n", mod->filename); return OK; }
/* close (unload) a particular module */ int neb_unload_module(nebmodule *mod, int flags, int reason) { int (*deinitfunc)(int, int); int result = OK; if (mod == NULL) return ERROR; log_debug_info(DEBUGL_EVENTBROKER, 0, "Attempting to unload module '%s': flags=%d, reason=%d\n", mod->filename, flags, reason); /* call the de-initialization function if available (and the module was initialized) */ if (mod->deinit_func && reason != NEBMODULE_ERROR_BAD_INIT) { deinitfunc = mod->deinit_func; /* module can opt to not be unloaded */ result = (*deinitfunc)(flags, reason); /* if module doesn't want to be unloaded, exit with error (unless its being forced) */ if (result != OK && !(flags & NEBMODULE_FORCE_UNLOAD)) return ERROR; } /* deregister all of the module's callbacks */ neb_deregister_module_callbacks(mod); /* unload the module */ #ifdef USE_LTDL result = lt_dlclose(mod->module_handle); #else result = dlclose(mod->module_handle); #endif /* mark the module as being unloaded */ mod->is_currently_loaded = FALSE; log_debug_info(DEBUGL_EVENTBROKER, 0, "Module '%s' unloaded successfully.\n", mod->filename); logit(NSLOG_INFO_MESSAGE, FALSE, "Event broker module '%s' deinitialized successfully.\n", mod->filename); return OK; }
int nebmodule_deinit(int flags, int reason) { neb_deregister_module_callbacks(nagmq_handle); if(config) json_decref(config); return 0; }