mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-15 12:34:55 +00:00
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: a23af8f764
('glib-aux: avoid using inet_aton()')
This commit is contained in:
parent
4c48301594
commit
fed850b5b9
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue