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/include/resolv_static.h b/libc/dns/include/resolv_static.h
index 8f2a095..83a435a 100644
--- a/libc/dns/include/resolv_static.h
+++ b/libc/dns/include/resolv_static.h
@@ -1,7 +1,7 @@
-#ifndef _RESOLV_STATIC_H
-#define _RESOLV_STATIC_H
+#pragma once
#include <netdb.h>
+#include <sys/cdefs.h>
/* this structure contains all the variables that were declared
* 'static' in the original NetBSD resolver code.
@@ -15,18 +15,20 @@
#define MAXALIASES 35
#define MAXADDRS 35
-typedef struct res_static {
- char* h_addr_ptrs[MAXADDRS + 1];
- char* host_aliases[MAXALIASES];
- char hostbuf[8*1024];
- u_int32_t host_addr[16 / sizeof(u_int32_t)]; /* IPv4 or IPv6 */
- FILE* hostf;
- int stayopen;
- const char* servent_ptr;
- struct servent servent;
- struct hostent host;
-} *res_static;
+__BEGIN_DECLS
-extern res_static __res_get_static(void);
+struct res_static {
+ char* h_addr_ptrs[MAXADDRS + 1];
+ char* host_aliases[MAXALIASES];
+ char hostbuf[8 * 1024];
+ u_int32_t host_addr[16 / sizeof(u_int32_t)]; /* IPv4 or IPv6 */
+ FILE* hostf;
+ int stayopen;
+ const char* servent_ptr;
+ struct servent servent;
+ struct hostent host;
+};
-#endif /* _RESOLV_STATIC_H */
+struct res_static* __res_get_static(void);
+
+__END_DECLS