1From 38aef4b65a03ea13c2a9bdf02ce7987da83cfbe3 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Wed, 13 Feb 2019 09:51:14 -0800
4Subject: [PATCH] provide res_ninit and nclose APIs on non-glibc linux
5 platforms
6
7These APIs are not implemented on musl
8
9Upstream-Status: Pending
10Signed-off-by: Khem Raj <raj.khem@gmail.com>
11
12---
13 net/dns/dns_reloader.cc              |  3 +--
14 net/dns/host_resolver_system_task.cc |  6 ++----
15 net/dns/public/scoped_res_state.cc   | 14 +++-----------
16 3 files changed, 6 insertions(+), 17 deletions(-)
17
18diff --git a/net/dns/dns_reloader.cc b/net/dns/dns_reloader.cc
19index bfd2de11f9..fef7569c13 100644
20--- a/net/dns/dns_reloader.cc
21+++ b/net/dns/dns_reloader.cc
22@@ -6,8 +6,7 @@
23
24 #include "build/build_config.h"
25
26-#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_OPENBSD) && \
27-    !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_FUCHSIA)
28+#if defined(__GLIBC__)
29
30 #include <resolv.h>
31
32diff --git a/net/dns/host_resolver_system_task.cc b/net/dns/host_resolver_system_task.cc
33index c067da3e85..010719971c 100644
34--- a/net/dns/host_resolver_system_task.cc
35+++ b/net/dns/host_resolver_system_task.cc
36@@ -351,8 +351,7 @@ void HostResolverSystemTask::OnLookupComplete(const uint32_t attempt_number,
37 }
38
39 void EnsureSystemHostResolverCallReady() {
40-#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_OPENBSD) && \
41-    !BUILDFLAG(IS_ANDROID)
42+#if defined(__GLIBC__)
43   EnsureDnsReloaderInit();
44 #elif BUILDFLAG(IS_WIN)
45   EnsureWinsockInit();
46@@ -437,8 +436,7 @@ int SystemHostResolverCall(const std::string& host,
47   base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
48                                                 base::BlockingType::WILL_BLOCK);
49
50-#if BUILDFLAG(IS_POSIX) && \
51-    !(BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_ANDROID))
52+#if defined(__GLIBC__)
53   DnsReloaderMaybeReload();
54 #endif
55   auto [ai, err, os_error] = AddressInfo::Get(host, hints, nullptr, network);
56diff --git a/net/dns/public/scoped_res_state.cc b/net/dns/public/scoped_res_state.cc
57index 2743697bf6..36dc8adbf5 100644
58--- a/net/dns/public/scoped_res_state.cc
59+++ b/net/dns/public/scoped_res_state.cc
60@@ -13,7 +13,7 @@
61 namespace net {
62
63 ScopedResState::ScopedResState() {
64-#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA)
65+#if BUILDFLAG(IS_OPENBSD) || BUILDFLAG(IS_FUCHSIA) || defined(_GNU_SOURCE)
66   // Note: res_ninit in glibc always returns 0 and sets RES_INIT.
67   // res_init behaves the same way.
68   memset(&_res, 0, sizeof(_res));
69@@ -25,16 +25,8 @@ ScopedResState::ScopedResState() {
70 }
71
72 ScopedResState::~ScopedResState() {
73-#if !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA)
74-
75-  // Prefer res_ndestroy where available.
76-#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_FREEBSD)
77-  res_ndestroy(&res_);
78-#else
79-  res_nclose(&res_);
80-#endif  // BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_FREEBSD)
81-
82-#endif  // !BUILDFLAG(IS_OPENBSD) && !BUILDFLAG(IS_FUCHSIA)
83+  // musl res_init() doesn't actually do anything
84+  // no destruction is necessary as no memory has been allocated
85 }
86
87 bool ScopedResState::IsValid() const {
88