From 8f2a5a0b40fc82126c691d5c30131d908772aab7 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 15 Mar 2013 15:30:25 -0700 Subject: Clean up internal libc logging. We only need one logging API, and I prefer the one that does no allocation and is thus safe to use in any context. Also use O_CLOEXEC when opening the /dev/log files. Move everything logging-related into one header file. Change-Id: Ic1e3ea8e9b910dc29df351bff6c0aa4db26fbb58 --- libc/netbsd/resolv/res_cache.c | 11 +++++------ libc/netbsd/resolv/res_send.c | 32 ++++++++++++++------------------ libc/netbsd/resolv/res_state.c | 4 ++-- 3 files changed, 21 insertions(+), 26 deletions(-) (limited to 'libc/netbsd') diff --git a/libc/netbsd/resolv/res_cache.c b/libc/netbsd/resolv/res_cache.c index 838e084e2..a2bc7ca44 100644 --- a/libc/netbsd/resolv/res_cache.c +++ b/libc/netbsd/resolv/res_cache.c @@ -170,9 +170,8 @@ #undef XLOG #if DEBUG -# include -# define XLOG(...) \ - __libc_android_log_print(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__) +# include "libc_logging.h" +# define XLOG(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__) #include #include @@ -708,9 +707,9 @@ static char* _dnsPacket_bprintQR(DnsPacket* packet, char* p, char* end) { #define QQ(x) { DNS_TYPE_##x, #x } - static const struct { + static const struct { const char* typeBytes; - const char* typeString; + const char* typeString; } qTypes[] = { QQ(A), QQ(PTR), QQ(MX), QQ(AAAA), QQ(ALL), @@ -1487,7 +1486,7 @@ _cache_lookup_p( Cache* cache, pnode = &node->hlink; } - return pnode; + return pnode; } /* Add a new entry to the hash table. 'lookup' must be the diff --git a/libc/netbsd/resolv/res_send.c b/libc/netbsd/resolv/res_send.c index f3ee53979..c6c863bfa 100644 --- a/libc/netbsd/resolv/res_send.c +++ b/libc/netbsd/resolv/res_send.c @@ -119,7 +119,7 @@ __RCSID("$NetBSD: res_send.c,v 1.9 2006/01/24 17:41:25 christos Exp $"); # include #endif -#include "logd.h" +#include "libc_logging.h" #ifndef DE_CONST #define DE_CONST(c,v) v = ((c) ? \ @@ -542,7 +542,7 @@ res_nsend(res_state statp, ns); if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", + __libc_format_log(ANDROID_LOG_DEBUG, "libc", "used send_vc %d\n", n); } @@ -554,15 +554,13 @@ res_nsend(res_state statp, } else { /* Use datagrams. */ if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", - "using send_dg\n"); + __libc_format_log(ANDROID_LOG_DEBUG, "libc", "using send_dg\n"); } n = send_dg(statp, buf, buflen, ans, anssiz, &terrno, ns, &v_circuit, &gotsomewhere); if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", - "used send_dg %d\n",n); + __libc_format_log(ANDROID_LOG_DEBUG, "libc", "used send_dg %d\n",n); } if (n < 0) @@ -570,7 +568,7 @@ res_nsend(res_state statp, if (n == 0) goto next_ns; if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", + __libc_format_log(ANDROID_LOG_DEBUG, "libc", "time=%d, %d\n",time(NULL), time(NULL)%2); } if (v_circuit) @@ -715,8 +713,7 @@ static int get_timeout(const res_state statp, const int ns) timeout = 1; } if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", - "using timeout of %d sec\n", timeout); + __libc_format_log(ANDROID_LOG_DEBUG, "libc", "using timeout of %d sec\n", timeout); } return timeout; @@ -738,7 +735,7 @@ send_vc(res_state statp, void *tmp; if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", "using send_vc\n"); + __libc_format_log(ANDROID_LOG_DEBUG, "libc", "using send_vc\n"); } nsap = get_nsaddr(statp, (size_t)ns); @@ -939,8 +936,7 @@ connect_with_timeout(int sock, const struct sockaddr *nsap, socklen_t salen, int timeout = evConsTime((long)sec, 0L); finish = evAddTime(now, timeout); if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", - " %d send_vc\n", sock); + __libc_format_log(ANDROID_LOG_DEBUG, "libc", " %d send_vc\n", sock); } res = retrying_select(sock, &rset, &wset, &finish); @@ -951,7 +947,7 @@ connect_with_timeout(int sock, const struct sockaddr *nsap, socklen_t salen, int done: fcntl(sock, F_SETFL, origflags); if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", + __libc_format_log(ANDROID_LOG_DEBUG, "libc", " %d connect_with_timeout returning %s\n", sock, res); } return res; @@ -967,7 +963,7 @@ retrying_select(const int sock, fd_set *readset, fd_set *writeset, const struct retry: if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", " %d retying_select\n", sock); + __libc_format_log(ANDROID_LOG_DEBUG, "libc", " %d retying_select\n", sock); } now = evNowTime(); @@ -987,7 +983,7 @@ retry: n = pselect(sock + 1, readset, writeset, NULL, &timeout, NULL); if (n == 0) { if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, " libc", + __libc_format_log(ANDROID_LOG_DEBUG, " libc", " %d retrying_select timeout\n", sock); } errno = ETIMEDOUT; @@ -997,7 +993,7 @@ retry: if (errno == EINTR) goto retry; if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", + __libc_format_log(ANDROID_LOG_DEBUG, "libc", " %d retrying_select got error %d\n",sock, n); } return n; @@ -1007,7 +1003,7 @@ retry: if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) { errno = error; if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", + __libc_format_log(ANDROID_LOG_DEBUG, "libc", " %d retrying_select dot error2 %d\n", sock, errno); } @@ -1015,7 +1011,7 @@ retry: } } if (DBG) { - __libc_android_log_print(ANDROID_LOG_DEBUG, "libc", + __libc_format_log(ANDROID_LOG_DEBUG, "libc", " %d retrying_select returning %d for %d\n",sock, n); } diff --git a/libc/netbsd/resolv/res_state.c b/libc/netbsd/resolv/res_state.c index e05846a93..3e1f67b82 100644 --- a/libc/netbsd/resolv/res_state.c +++ b/libc/netbsd/resolv/res_state.c @@ -42,9 +42,9 @@ #define DEBUG 0 #if DEBUG -# include +# include "libc_logging.h" # include /* for gettid() */ -# define D(...) __libc_android_log_print(ANDROID_LOG_DEBUG,"libc", __VA_ARGS__) +# define D(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc", __VA_ARGS__) #else # define D(...) do{}while(0) #endif -- cgit v1.2.3