librpz_t *librpz = NULL;
librpz_emsg_t librpz_lib_open_emsg;
-static void *librpz_handle = NULL;
+static uv_lib_t librpz_handle;
#define RPSDB_MAGIC ISC_MAGIC('R', 'P', 'Z', 'F')
#define VALID_RPSDB(rpsdb) ((rpsdb)->common.impmagic == RPSDB_MAGIC)
INSIST(clist == NULL);
INSIST(librpz == NULL);
- INSIST(librpz_handle == NULL);
/*
* Notice if librpz is available.
#if DNSRPS_LIB_OPEN == 2
if (librpz != NULL) {
- INSIST(librpz_handle != NULL);
- if (dlclose(librpz_handle) != 0) {
- isc_log_write(DNS_LOGCATEGORY_RPZ, DNS_LOGMODULE_RBTDB,
- DNS_RPZ_ERROR_LEVEL,
- "dnsrps: dlclose(): %s", dlerror());
- }
- librpz_handle = NULL;
- librpz = NULL;
+ librpz_lib_close(&librpz, &librpz_handle);
}
#endif
}
#include <stdbool.h>
#include <stdio.h>
#include <sys/types.h>
+#include <uv.h>
/*
* Allow either ordinary or dlopen() linking.
* @return address of interface structure or NULL on failure
*/
static inline librpz_t *
-librpz_lib_open(librpz_emsg_t *emsg, void **dl_handle, const char *path) {
- void *handle;
- librpz_t *new_librpz;
+librpz_lib_open(librpz_emsg_t *emsg, uv_lib_t *lib, const char *path) {
+ librpz_t *new_librpz = NULL;
+ int r;
emsg->c[0] = '\0';
- /*
- * Close a previously opened handle on librpz.so.
- */
- if (dl_handle != NULL && *dl_handle != NULL) {
- if (dlclose(*dl_handle) != 0) {
- snprintf(emsg->c, sizeof(librpz_emsg_t),
- "dlopen(NULL): %s", dlerror());
- return (NULL);
- }
- *dl_handle = NULL;
- }
-
- /*
- * First try the main executable of the process in case it was
- * linked to librpz.
- * Do not worry if we cannot search the main executable of the process.
- */
- handle = dlopen(NULL, RTLD_NOW | RTLD_LOCAL);
- if (handle != NULL) {
- new_librpz = dlsym(handle, LIBRPZ_DEF_STR);
- if (new_librpz != NULL) {
- if (dl_handle != NULL) {
- *dl_handle = handle;
- handle = NULL;
- }
- return (new_librpz);
- }
- if (dlclose(handle) != 0) {
- snprintf(emsg->c, sizeof(librpz_emsg_t),
- "dlsym(NULL, " LIBRPZ_DEF_STR "): %s",
- dlerror());
- return (NULL);
- }
- }
-
if (path == NULL || path[0] == '\0') {
snprintf(emsg->c, sizeof(librpz_emsg_t),
- "librpz not linked and no dlopen() path provided");
+ "path to librpz not provided");
return (NULL);
}
- handle = dlopen(path, RTLD_NOW | RTLD_LOCAL);
- if (handle == NULL) {
- snprintf(emsg->c, sizeof(librpz_emsg_t), "dlopen(%s): %s", path,
- dlerror());
+ r = uv_dlopen(path, lib);
+ if (r != 0) {
+ const char *errmsg = uv_dlerror(lib);
+ if (errmsg == NULL) {
+ errmsg = "unknown error";
+ }
+ snprintf(emsg->c, sizeof(librpz_emsg_t), "uv_dlopen(%s): %s",
+ path, errmsg);
+ uv_dlclose(lib);
return (NULL);
}
- new_librpz = dlsym(handle, LIBRPZ_DEF_STR);
- if (new_librpz != NULL) {
- if (dl_handle != NULL) {
- *dl_handle = handle;
- handle = NULL;
+ r = uv_dlsym(lib, LIBRPZ_DEF_STR, (void **)&new_librpz);
+ if (r != 0) {
+ const char *errmsg = uv_dlerror(lib);
+ if (errmsg == NULL) {
+ errmsg = "returned function pointer is NULL";
}
- return (new_librpz);
+ uv_dlclose(lib);
+ snprintf(emsg->c, sizeof(librpz_emsg_t),
+ "dlsym(%s, " LIBRPZ_DEF_STR "): %s", path, errmsg);
+ return (NULL);
}
- snprintf(emsg->c, sizeof(librpz_emsg_t),
- "dlsym(%s, " LIBRPZ_DEF_STR "): %s", path, dlerror());
- dlclose(handle);
- return (NULL);
+
+ return (new_librpz);
+}
+
+static inline void
+librpz_lib_close(librpz_t **rpz, uv_lib_t *lib) {
+ *rpz = NULL;
+ uv_dlclose(lib);
}
#elif defined(LIBRPZ_LIB_OPEN)
/*