Skip to content

Commit

Permalink
dns: Support Musl
Browse files Browse the repository at this point in the history
  • Loading branch information
klzgrad committed Nov 5, 2023
1 parent 9c9d625 commit 5590410
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/net/dns/dns_reloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,32 @@ class DnsReloader : public NetworkChangeNotifier::DNSObserver {
if (!reload_state) {
auto new_reload_state = std::make_unique<ReloadState>();
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;
};
Expand Down
6 changes: 3 additions & 3 deletions src/net/dns/public/scoped_res_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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)
Expand All @@ -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_;
Expand Down
2 changes: 1 addition & 1 deletion src/net/dns/public/scoped_res_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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)

Expand Down

0 comments on commit 5590410

Please sign in to comment.