diff options
| author | Jack O'Connor <oconnor663@gmail.com> | 2017-10-01 17:42:18 -0400 |
|---|---|---|
| committer | Jack O'Connor <oconnor663@gmail.com> | 2017-10-05 17:53:10 -0400 |
| commit | 9602fe1509f2d6ae274a42f61ca5b5cf0c3b9a6b (patch) | |
| tree | 7ac92b74dcc5190a6a8d6c267e328fca41f6c4a7 /src/libstd/sys_common | |
| parent | 4531131bf328e1372663310bfd45cd354db511ce (diff) | |
| download | rust-9602fe1509f2d6ae274a42f61ca5b5cf0c3b9a6b.tar.gz rust-9602fe1509f2d6ae274a42f61ca5b5cf0c3b9a6b.zip | |
replace libc::res_init with res_init_if_glibc_before_2_26
The previous workaround for gibc's res_init bug is not thread-safe on other implementations of libc, and it can cause crashes. Use a runtime check to make sure we only call res_init when we need to, which is also when it's safe. See https://github.com/rust-lang/rust/issues/43592.
Diffstat (limited to 'src/libstd/sys_common')
| -rw-r--r-- | src/libstd/sys_common/net.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index 19dc841b9b5..c76b0bcf1c9 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -175,10 +175,15 @@ pub fn lookup_host(host: &str) -> io::Result<LookupHost> { }, #[cfg(unix)] Err(e) => { - // The lookup failure could be caused by using a stale /etc/resolv.conf. - // See https://github.com/rust-lang/rust/issues/41570. - // We therefore force a reload of the nameserver information. - c::res_init(); + // If we're running glibc prior to version 2.26, the lookup + // failure could be caused by caching a stale /etc/resolv.conf. + // We need to call libc::res_init() to clear the cache. But we + // shouldn't call it in on any other platform, because other + // res_init implementations aren't thread-safe. See + // https://github.com/rust-lang/rust/issues/41570 and + // https://github.com/rust-lang/rust/issues/43592. + use sys::net::res_init_if_glibc_before_2_26; + let _ = res_init_if_glibc_before_2_26(); Err(e) }, // the cfg is needed here to avoid an "unreachable pattern" warning |
