From fe372531cf786d2e204b35421b105887c1fd1d8c 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_config_service_linux.cc | 7 +++++++ src/net/dns/dns_config_service_posix.cc | 2 +- src/net/dns/dns_reloader.cc | 14 +++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/net/dns/dns_config_service_linux.cc b/src/net/dns/dns_config_service_linux.cc index f29c5e8d97..7a600116a3 100644 --- a/src/net/dns/dns_config_service_linux.cc +++ b/src/net/dns/dns_config_service_linux.cc @@ -489,17 +489,24 @@ DnsConfigServiceLinux::ResolvReader::GetResState() { auto res = std::make_unique(); memset(res.get(), 0, sizeof(struct __res_state)); +#if defined(__UCLIBC__) + if (res_init() != 0) + return nullptr; +#else if (res_ninit(res.get()) != 0) { CloseResState(res.get()); return nullptr; } +#endif return res; } void DnsConfigServiceLinux::ResolvReader::CloseResState( struct __res_state* res) { +#if !defined(__UCLIBC__) res_nclose(res); +#endif } DnsConfigServiceLinux::DnsConfigServiceLinux() diff --git a/src/net/dns/dns_config_service_posix.cc b/src/net/dns/dns_config_service_posix.cc index 2de14574f1..07a732ccca 100644 --- a/src/net/dns/dns_config_service_posix.cc +++ b/src/net/dns/dns_config_service_posix.cc @@ -93,7 +93,7 @@ absl::optional ReadDnsConfig() { absl::optional dns_config; // TODO(fuchsia): Use res_ninit() when it's implemented on Fuchsia. -#if defined(OS_OPENBSD) || defined(OS_FUCHSIA) +#if defined(OS_OPENBSD) || defined(OS_FUCHSIA) || defined(__UCLIBC__) // Note: res_ninit in glibc always returns 0 and sets RES_INIT. // res_init behaves the same way. memset(&_res, 0, sizeof(_res)); diff --git a/src/net/dns/dns_reloader.cc b/src/net/dns/dns_reloader.cc index 0672e711af..a126fd5618 100644 --- a/src/net/dns/dns_reloader.cc +++ b/src/net/dns/dns_reloader.cc @@ -60,20 +60,32 @@ class DnsReloader : public NetworkChangeNotifier::DNSObserver { if (!reload_state) { auto new_reload_state = std::make_unique(); new_reload_state->resolver_generation = resolver_generation_; +#ifndef __UCLIBC__ res_ninit(&_res); +#else + res_init(); +#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. +#ifndef __UCLIBC__ res_nclose(&_res); res_ninit(&_res); +#else + res_init(); +#endif } } private: struct ReloadState { - ~ReloadState() { res_nclose(&_res); } + ~ReloadState() { +#ifndef __UCLIBC__ + res_nclose(&_res); +#endif + } int resolver_generation; };