summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-05-10 18:56:51 +0200
committerThomas Haller <thaller@redhat.com>2023-05-10 18:58:49 +0200
commitfed850b5b9e70a65e0aa4527c90332c478e3427f (patch)
treec15f1a89c22034b8b92ba6705d071bc264deac8c
parent4c48301594591a92a123b68fa8f9e1c129ce65ae (diff)
downloadNetworkManager-fed850b5b9e70a65e0aa4527c90332c478e3427f.tar.gz
glib-aux: use GModule instead of dlopen() in _inet_aton()
Using dlopen() requires us to link with libdl (at least with some libc). That is cumbersome and was not done by all users of libnm-glib-aux, thereby causing a linker error. The code path is only used via nm_assert(). Use GModule instead. Fixes: a23af8f76469 ('glib-aux: avoid using inet_aton()')
-rw-r--r--src/libnm-glib-aux/nm-inet-utils.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/libnm-glib-aux/nm-inet-utils.c b/src/libnm-glib-aux/nm-inet-utils.c
index 87fe3ce050..2ee73ad5e7 100644
--- a/src/libnm-glib-aux/nm-inet-utils.c
+++ b/src/libnm-glib-aux/nm-inet-utils.c
@@ -279,7 +279,6 @@ _inet_aton(const char *text, in_addr_t *out_addr)
* the ABI checker's complain, dlopen() the symbol. This is not used for
* production.
*/
- static gpointer mod_handle = NULL;
static gpointer fcn_sym = NULL;
static gsize initialized = 0;
int (*fcn)(const char *text, struct in_addr *out_addr);
@@ -287,11 +286,14 @@ _inet_aton(const char *text, in_addr_t *out_addr)
in_addr_t a;
if (g_once_init_enter(&initialized)) {
- mod_handle = dlopen(NULL, RTLD_LAZY);
- if (mod_handle) {
- fcn_sym = dlsym(mod_handle, "inet_aton");
- if (!fcn_sym)
- dlclose(g_steal_pointer(&mod_handle));
+ GModule *module;
+
+ module = g_module_open(NULL, G_MODULE_BIND_LAZY);
+ if (module) {
+ if (!g_module_symbol(module, "inet_aton", &fcn_sym))
+ g_module_close(module);
+ else
+ g_module_make_resident(module);
}
g_once_init_leave(&initialized, 1);
}
@@ -299,8 +301,6 @@ _inet_aton(const char *text, in_addr_t *out_addr)
if (!fcn_sym)
return -ENOSYS;
- g_assert(mod_handle);
-
fcn = fcn_sym;
r = fcn(text, (gpointer) &a);