From 4c908337a5b50157390b7efaf08594a797e206b1 Mon Sep 17 00:00:00 2001 From: klzgrad Date: Sat, 30 Nov 2019 22:21:18 +0800 Subject: [PATCH] dns: Support Musl --- src/net/dns/dns_reloader.cc | 14 +++++++++++++- src/net/dns/public/scoped_res_state.cc | 6 +++--- src/net/dns/public/scoped_res_state.h | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/net/dns/dns_reloader.cc b/src/net/dns/dns_reloader.cc index 363eb14dc0..cc7d36f545 100644 --- a/src/net/dns/dns_reloader.cc +++ b/src/net/dns/dns_reloader.cc @@ -88,20 +88,32 @@ class DnsReloader : public NetworkChangeNotifier::DNSObserver { if (!reload_state) { auto new_reload_state = std::make_unique(); new_reload_state->resolver_generation = resolver_generation_; +#ifdef __MUSL__ + res_init(); +#else res_ninit(&_res); +#endif tls_reload_state_.Set(std::move(new_reload_state)); } else if (reload_state->resolver_generation != resolver_generation_) { reload_state->resolver_generation = resolver_generation_; // It is safe to call res_nclose here since we know res_ninit will have // been called above. +#ifdef __MUSL__ + res_init(); +#else res_nclose(&_res); res_ninit(&_res); +#endif } } private: struct ReloadState { - ~ReloadState() { res_nclose(&_res); } + ~ReloadState() { +#ifndef __MUSL__ + res_nclose(&_res); +#endif + } int resolver_generation; }; diff --git a/src/net/dns/public/scoped_res_state.cc b/src/net/dns/public/scoped_res_state.cc index 2743697bf6..f8bef3e377 100644 --- a/src/net/dns/public/scoped_res_state.cc +++ b/src/net/dns/public/scoped_res_state.cc @@ -13,7 +13,7 @@ namespace net { ScopedResState::ScopedResState() { -#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA) || defined(__MUSL__) // Note: res_ninit in glibc always returns 0 and sets RES_INIT. // res_init behaves the same way. memset(&_res, 0, sizeof(_res)); @@ -25,7 +25,7 @@ ScopedResState::ScopedResState() { } ScopedResState::~ScopedResState() { -#if !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA) +#if !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA) && !defined(__MUSL__) // Prefer res_ndestroy where available. #if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_FREEBSD) @@ -43,7 +43,7 @@ bool ScopedResState::IsValid() const { const struct __res_state& ScopedResState::state() const { DCHECK(IsValid()); -#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA) +#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA) || defined(__MUSL__) return _res; #else return res_; diff --git a/src/net/dns/public/scoped_res_state.h b/src/net/dns/public/scoped_res_state.h index a1c97c3d6f..20547da63b 100644 --- a/src/net/dns/public/scoped_res_state.h +++ b/src/net/dns/public/scoped_res_state.h @@ -32,7 +32,7 @@ class NET_EXPORT ScopedResState { virtual const struct __res_state& state() const; private: -#if !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA) +#if !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA) && !defined(__MUSL__) struct __res_state res_; #endif // !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA)