Make res_init() work again.
Change 75830fb836621ebbcf68155e466983eb231f9ca1 to fix _nres
initialization to be thread safe accidentally introduced a behavior
change whereby res_init() became a no-op. It also failed to remove all
direct accesses to _nres.
Move the file over to C++ so we can let RAII ensure we're always holding
a lock while using the global state, make all callers access the global
state via this class, and restore the previous behavior of res_init().
Test: atest DnsResolverTest
Bug: 166235340
Change-Id: Ib390a7eac063bc0ff5eeba755e8c74ef1383004e
diff --git a/libc/dns/resolv/res_state.c b/libc/dns/resolv/res_state.c
index 94124ff..d1f5c24 100644
--- a/libc/dns/resolv/res_state.c
+++ b/libc/dns/resolv/res_state.c
@@ -68,7 +68,7 @@
}
static void
-_res_static_done( res_static rs )
+_res_static_done(struct res_static* rs)
{
/* fortunately, there is nothing to do here, since the
* points in h_addr_ptrs and host_aliases should all
@@ -135,25 +135,6 @@
return rt;
}
-__LIBC_HIDDEN__
-struct __res_state _nres;
-
-#if 0
-struct resolv_cache*
-__get_res_cache(void)
-{
- _res_thread* rt = _res_thread_get();
-
- if (!rt)
- return NULL;
-
- if (!rt->_cache) {
- rt->_cache = _resolv_cache_create();
- }
- return rt->_cache;
-}
-#endif
-
int*
__get_h_errno(void)
{
@@ -177,9 +158,7 @@
/* nothing to do */
}
-res_static
-__res_get_static(void)
-{
+struct res_static* __res_get_static(void) {
_res_thread* rt = _res_thread_get();
return rt ? rt->_rstatic : NULL;