mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-05 00:55:24 +00:00
Use libuv's shared library handling capabilities
While libltdl is a feature-rich library, BIND 9 code only uses its basic capabilities, which are also provided by libuv and which BIND 9 already uses for other purposes. As libuv's cross-platform shared library handling interface is modeled after the POSIX dlopen() interface, converting code using the latter to the former is simple. Replace libltdl function calls with their libuv counterparts, refactoring the code as necessary. Remove all use of libltdl from the BIND 9 source tree.
This commit is contained in:
committed by
Michał Kępień
parent
e2436159ab
commit
37b9511ce1
@@ -12,9 +12,9 @@
|
||||
/*! \file */
|
||||
|
||||
#include <errno.h>
|
||||
#include <ltdl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include <isc/errno.h>
|
||||
#include <isc/list.h>
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
struct ns_plugin {
|
||||
isc_mem_t *mctx;
|
||||
void *handle;
|
||||
uv_lib_t handle;
|
||||
void *inst;
|
||||
char *modpath;
|
||||
ns_plugin_check_t *check_func;
|
||||
@@ -91,16 +91,17 @@ ns_plugin_expandpath(const char *src, char *dst, size_t dstsize) {
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
load_symbol(void *handle, const char *modpath, const char *symbol_name,
|
||||
load_symbol(uv_lib_t *handle, const char *modpath, const char *symbol_name,
|
||||
void **symbolp) {
|
||||
void *symbol = NULL;
|
||||
int r;
|
||||
|
||||
REQUIRE(handle != NULL);
|
||||
REQUIRE(symbolp != NULL && *symbolp == NULL);
|
||||
|
||||
symbol = lt_dlsym(handle, symbol_name);
|
||||
if (symbol == NULL) {
|
||||
const char *errmsg = lt_dlerror();
|
||||
r = uv_dlsym(handle, symbol_name, &symbol);
|
||||
if (r != 0) {
|
||||
const char *errmsg = uv_dlerror(handle);
|
||||
if (errmsg == NULL) {
|
||||
errmsg = "returned function pointer is NULL";
|
||||
}
|
||||
@@ -126,6 +127,7 @@ load_plugin(isc_mem_t *mctx, const char *modpath, ns_plugin_t **pluginp) {
|
||||
ns_plugin_t *plugin = NULL;
|
||||
ns_plugin_version_t *version_func = NULL;
|
||||
int version;
|
||||
int r;
|
||||
|
||||
REQUIRE(pluginp != NULL && *pluginp == NULL);
|
||||
|
||||
@@ -137,13 +139,9 @@ load_plugin(isc_mem_t *mctx, const char *modpath, ns_plugin_t **pluginp) {
|
||||
|
||||
ISC_LINK_INIT(plugin, link);
|
||||
|
||||
if (lt_dlinit() != 0) {
|
||||
CHECK(ISC_R_FAILURE);
|
||||
}
|
||||
|
||||
plugin->handle = lt_dlopen(modpath);
|
||||
if (plugin->handle == NULL) {
|
||||
const char *errmsg = lt_dlerror();
|
||||
r = uv_dlopen(modpath, &plugin->handle);
|
||||
if (r != 0) {
|
||||
const char *errmsg = uv_dlerror(&plugin->handle);
|
||||
if (errmsg == NULL) {
|
||||
errmsg = "unknown error";
|
||||
}
|
||||
@@ -154,7 +152,7 @@ load_plugin(isc_mem_t *mctx, const char *modpath, ns_plugin_t **pluginp) {
|
||||
CHECK(ISC_R_FAILURE);
|
||||
}
|
||||
|
||||
CHECK(load_symbol(plugin->handle, modpath, "plugin_version",
|
||||
CHECK(load_symbol(&plugin->handle, modpath, "plugin_version",
|
||||
(void **)&version_func));
|
||||
|
||||
version = version_func();
|
||||
@@ -168,11 +166,11 @@ load_plugin(isc_mem_t *mctx, const char *modpath, ns_plugin_t **pluginp) {
|
||||
CHECK(ISC_R_FAILURE);
|
||||
}
|
||||
|
||||
CHECK(load_symbol(plugin->handle, modpath, "plugin_check",
|
||||
CHECK(load_symbol(&plugin->handle, modpath, "plugin_check",
|
||||
(void **)&plugin->check_func));
|
||||
CHECK(load_symbol(plugin->handle, modpath, "plugin_register",
|
||||
CHECK(load_symbol(&plugin->handle, modpath, "plugin_register",
|
||||
(void **)&plugin->register_func));
|
||||
CHECK(load_symbol(plugin->handle, modpath, "plugin_destroy",
|
||||
CHECK(load_symbol(&plugin->handle, modpath, "plugin_destroy",
|
||||
(void **)&plugin->destroy_func));
|
||||
|
||||
*pluginp = plugin;
|
||||
@@ -207,9 +205,7 @@ unload_plugin(ns_plugin_t **pluginp) {
|
||||
plugin->destroy_func(&plugin->inst);
|
||||
}
|
||||
|
||||
if (plugin->handle != NULL) {
|
||||
(void)lt_dlclose(plugin->handle);
|
||||
}
|
||||
uv_dlclose(&plugin->handle);
|
||||
isc_mem_free(plugin->mctx, plugin->modpath);
|
||||
isc_mem_putanddetach(&plugin->mctx, plugin, sizeof(*plugin));
|
||||
}
|
||||
|
Reference in New Issue
Block a user