From d1da45855c0f7d71bb13928f8028937d3fa062d9 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Wed, 13 Oct 2021 17:10:35 +0000 Subject: [PATCH] preloadNSS: Drop the dns query workaround We can actually just load nss ourselves and call in nss to configure it and we don't need to run a dummy query entirely to have nss load nss_dns as a side-effect. Signed-off-by: Arthur Gautier --- src/libmain/shared.cc | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 85f9f0d58..93775bed1 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -15,9 +15,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include @@ -121,21 +121,8 @@ static void preloadNSS() { 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. */ std::call_once(dns_resolve_flag, []() { - struct addrinfo *res = NULL; - - /* nss will only force the "local" (not through nscd) dns resolution if its on the LOCALDOMAIN. - We need the resolution to be done locally, as nscd socket will not be accessible in the - sandbox. */ - char * previous_env = getenv("LOCALDOMAIN"); - setenv("LOCALDOMAIN", "invalid", 1); - if (getaddrinfo("this.pre-initializes.the.dns.resolvers.invalid.", "http", NULL, &res) == 0) { - if (res) freeaddrinfo(res); - } - if (previous_env) { - setenv("LOCALDOMAIN", previous_env, 1); - } else { - unsetenv("LOCALDOMAIN"); - } + dlopen (LIBNSS_DNS_SO, RTLD_NOW); + __nss_configure_lookup ("hosts", "dns"); }); }