preloadNSS: detect glibc

Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
This commit is contained in:
Arthur Gautier 2021-10-14 21:43:07 +00:00
parent d1da45855c
commit 85717eff15

View file

@ -15,9 +15,12 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <features.h>
#ifdef __GLIBC__
#include <gnu/lib-names.h> #include <gnu/lib-names.h>
#include <nss.h> #include <nss.h>
#include <dlfcn.h> #include <dlfcn.h>
#endif
#include <openssl/crypto.h> #include <openssl/crypto.h>
@ -121,8 +124,10 @@ static void preloadNSS() {
been loaded in the parent. So we force a lookup of an invalid domain to force the NSS machinery to been loaded in the parent. So we force a lookup of an invalid domain to force the NSS machinery to
load its lookup libraries in the parent before any child gets a chance to. */ load its lookup libraries in the parent before any child gets a chance to. */
std::call_once(dns_resolve_flag, []() { std::call_once(dns_resolve_flag, []() {
#ifdef __GLIBC__
dlopen (LIBNSS_DNS_SO, RTLD_NOW); dlopen (LIBNSS_DNS_SO, RTLD_NOW);
__nss_configure_lookup ("hosts", "dns"); __nss_configure_lookup ("hosts", "dns");
#endif
}); });
} }