resolv: Switch to android-base/logging.h
This moves us away from async_safe_format_log() so we can drop the
last remaining dependency on internal bionic headers.
The debug logging code has bitrotten for a very long time and didn't
even compile any more, and when it finally did I noticed that
dump_answer() was trying to create a temporary file in /data on each
cache insert! Plenty of room for future improvements.
Test: m netd_integration_test
Test: build with kVerboseLogging=true in all modules and check logcat
Change-Id: I5d8c4b207f1477e75476b06b863a7d1723664407
diff --git a/resolv/res_state.cpp b/resolv/res_state.cpp
index 91e9044..df1528c 100644
--- a/resolv/res_state.cpp
+++ b/resolv/res_state.cpp
@@ -25,6 +25,9 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
+#define LOG_TAG "res_state"
+
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <netdb.h>
@@ -32,22 +35,13 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
+#include <unistd.h> /* for gettid() */
+
+#include <android-base/logging.h>
+
#include "resolv_cache.h"
#include "resolv_private.h"
-/* Set to 1 to enable debug traces */
-#define DEBUG 0
-
-#if DEBUG
-#include <async_safe/log.h>
-#include <unistd.h> /* for gettid() */
-#define D(...) async_safe_format_log(ANDROID_LOG_DEBUG, "libc", __VA_ARGS__)
-#else
-#define D(...) \
- do { \
- } while (0)
-#endif
-
typedef struct {
int _h_errno;
// TODO: Have one __res_state per network so we don't have to repopulate frequently.
@@ -80,7 +74,7 @@
static void _res_thread_free(void* _rt) {
_res_thread* rt = (_res_thread*) _rt;
- D("%s: rt=%p for thread=%d", __FUNCTION__, rt, gettid());
+ LOG(VERBOSE) << __func__ << ": rt=" << rt << " for thread=" << gettid();
_res_static_done(rt->_rstatic);
res_ndestroy(rt->_nres);
@@ -106,16 +100,16 @@
return NULL;
}
pthread_setspecific(_res_key, rt);
- D("%s: tid=%d Created new DNS state rt=%p", __FUNCTION__, gettid(), rt);
/* Reset the state, note that res_ninit() can now properly reset
* an existing state without leaking memory.
*/
- D("%s: tid=%d, rt=%p, setting DNS state (options RES_INIT=%d)", __FUNCTION__, gettid(), rt,
- (rt->_nres->options & RES_INIT) != 0);
+ LOG(VERBOSE) << __func__ << ": tid=" << gettid() << ", rt=" << rt
+ << " setting DNS state (options=" << rt->_nres->options << ")";
if (res_ninit(rt->_nres) < 0) {
/* This should not happen */
- D("%s: tid=%d rt=%p, woot, res_ninit() returned < 0", __FUNCTION__, gettid(), rt);
+ LOG(VERBOSE) << __func__ << ": tid=" << gettid() << " rt=" << rt
+ << ", res_ninit() returned < 0";
_res_thread_free(rt);
pthread_setspecific(_res_key, NULL);
return NULL;