From ef7bffe6fae9c11a3962ba17ac14d2c494677a09 Mon Sep 17 00:00:00 2001 From: Brad House Date: Wed, 12 Jun 2024 15:09:59 -0400 Subject: [PATCH] MacOS Legacy: simplify, don't forget change monitoring --- src/lib/ares_event_configchg.c | 37 ++++++++++++++++++++++++---------- src/lib/ares_sysconfig_mac.c | 14 ------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/lib/ares_event_configchg.c b/src/lib/ares_event_configchg.c index b170ee5e..e2872ca1 100644 --- a/src/lib/ares_event_configchg.c +++ b/src/lib/ares_event_configchg.c @@ -329,11 +329,17 @@ static void ares_event_configchg_cb(ares_event_thread_t *e, ares_socket_t fd, ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, ares_event_thread_t *e) { - ares_status_t status = ARES_SUCCESS; - void *handle = NULL; - const char *(*pdns_configuration_notify_key)(void) = NULL; - const char *notify_key = NULL; - int flags; + ares_status_t status = ARES_SUCCESS; + void *handle = NULL; + const char *(*pdns_configuration_notify_key)(void) = NULL; + const char *notify_key = NULL; + int flags; + size_t i; + const char *searchlibs[] = { + "/usr/lib/libSystem.dylib", + "/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration", + NULL + }; *configchg = ares_malloc_zero(sizeof(**configchg)); if (*configchg == NULL) { @@ -341,13 +347,22 @@ ares_status_t ares_event_configchg_init(ares_event_configchg_t **configchg, } /* Load symbol as it isn't normally public */ - handle = dlopen("/usr/lib/libSystem.dylib", RTLD_LAZY | RTLD_NOLOAD); - if (handle == NULL) { - status = ARES_ESERVFAIL; - goto done; - } + for (i=0; searchlibs[i] != NULL; i++) { + handle = dlopen(searchlibs[i], RTLD_LAZY); + if (handle == NULL) { + /* Fail, loop! */ + continue; + } - pdns_configuration_notify_key = dlsym(handle, "dns_configuration_notify_key"); + pdns_configuration_notify_key = dlsym(handle, "dns_configuration_notify_key"); + if (pdns_configuration_notify_key != NULL) { + break; + } + + /* Fail, loop! */ + dlclose(handle); + handle = NULL; + } if (pdns_configuration_notify_key == NULL) { status = ARES_ESERVFAIL; diff --git a/src/lib/ares_sysconfig_mac.c b/src/lib/ares_sysconfig_mac.c index f6bfe123..8d751293 100644 --- a/src/lib/ares_sysconfig_mac.c +++ b/src/lib/ares_sysconfig_mac.c @@ -85,9 +85,7 @@ static ares_status_t dnsinfo_init(dnsinfo_t **dnsinfo_out) size_t i; const char *searchlibs[] = { "/usr/lib/libSystem.dylib", - "SystemConfiguration.framework/SystemConfiguration", "/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration", - "/System/Library/Frameworks/SystemConfiguration.framework/Versions/Current/SystemConfiguration", NULL }; @@ -114,21 +112,9 @@ static ares_status_t dnsinfo_init(dnsinfo_t **dnsinfo_out) dnsinfo->dns_configuration_copy = dlsym(dnsinfo->handle, "dns_configuration_copy"); - if (dnsinfo->dns_configuration_copy == NULL) { - /* Might be needed for PPC ABI */ - dnsinfo->dns_configuration_copy = - dlsym(dnsinfo->handle, "_dns_configuration_copy"); - } - dnsinfo->dns_configuration_free = dlsym(dnsinfo->handle, "dns_configuration_free"); - if (dnsinfo->dns_configuration_free == NULL) { - /* Might be needed for PPC ABI */ - dnsinfo->dns_configuration_free = - dlsym(dnsinfo->handle, "_dns_configuration_free"); - } - if (dnsinfo->dns_configuration_copy != NULL && dnsinfo->dns_configuration_free != NULL) { break;