/*! Unload all plugins: call exit function and close shared handle * @param[in] h Clicon handle */ int clixon_plugin_exit(clicon_handle h) { clixon_plugin *cp; plgexit_t *exitfn; int i; char *error; for (i = 0; i < _clixon_nplugins; i++) { cp = &_clixon_plugins[i]; if ((exitfn = cp->cp_api.ca_exit) == NULL) continue; if (exitfn(h) < 0) { clicon_debug(1, "plugin_exit() failed"); return -1; } if (dlclose(cp->cp_handle) != 0) { error = (char*)dlerror(); clicon_err(OE_PLUGIN, errno, "dlclose: %s", error ? error : "Unknown error"); } } if (_clixon_plugins){ free(_clixon_plugins); _clixon_plugins = NULL; } _clixon_nplugins = 0; return 0; }
/* * Unload a plugin */ static int plugin_unload(clicon_handle h, void *handle) { int retval = 0; char *error; plgexit_t *exitfn; /* Call exit function is it exists */ exitfn = dlsym(handle, "plugin_exit"); if (dlerror() == NULL) exitfn(h); dlerror(); /* Clear any existing error */ if (dlclose(handle) != 0) { error = (char*)dlerror(); clicon_err(OE_PLUGIN, errno, "dlclose: %s\n", error ? error : "Unknown error"); /* Just report */ } return retval; }