Commit a141430e authored by Nick Mathewson's avatar Nick Mathewson 🐻
Browse files

Rename log() to tor_log() for logging

This is meant to avoid conflict with the built-in log() function in
math.h.  It resolves ticket 7599.  First reported by dhill.

This was generated with the following perl script:

 #!/usr/bin/perl -w -i -p

 s/\blog\(LOG_(ERR|WARN|NOTICE|INFO|DEBUG)\s*,\s*/log_\L$1\(/g;

 s/\blog\(/tor_log\(/g;
parent abb5519d
...@@ -1270,14 +1270,14 @@ get_interface_addresses_raw(int severity) ...@@ -1270,14 +1270,14 @@ get_interface_addresses_raw(int severity)
/* This interface, AFAICT, only supports AF_INET addresses */ /* This interface, AFAICT, only supports AF_INET addresses */
fd = socket(AF_INET, SOCK_DGRAM, 0); fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) { if (fd < 0) {
log(severity, LD_NET, "socket failed: %s", strerror(errno)); tor_log(severity, LD_NET, "socket failed: %s", strerror(errno));
goto done; goto done;
} }
/* Guess how much space we need. */ /* Guess how much space we need. */
ifc.ifc_len = sz = 15*1024; ifc.ifc_len = sz = 15*1024;
ifc.ifc_ifcu.ifcu_req = tor_malloc(sz); ifc.ifc_ifcu.ifcu_req = tor_malloc(sz);
if (ioctl(fd, SIOCGIFCONF, &ifc) < 0) { if (ioctl(fd, SIOCGIFCONF, &ifc) < 0) {
log(severity, LD_NET, "ioctl failed: %s", strerror(errno)); tor_log(severity, LD_NET, "ioctl failed: %s", strerror(errno));
close(fd); close(fd);
goto done; goto done;
} }
......
...@@ -76,19 +76,19 @@ libevent_logging_callback(int severity, const char *msg) ...@@ -76,19 +76,19 @@ libevent_logging_callback(int severity, const char *msg)
} }
switch (severity) { switch (severity) {
case _EVENT_LOG_DEBUG: case _EVENT_LOG_DEBUG:
log(LOG_DEBUG, LD_NOCB|LD_NET, "Message from libevent: %s", buf); log_debug(LD_NOCB|LD_NET, "Message from libevent: %s", buf);
break; break;
case _EVENT_LOG_MSG: case _EVENT_LOG_MSG:
log(LOG_INFO, LD_NOCB|LD_NET, "Message from libevent: %s", buf); log_info(LD_NOCB|LD_NET, "Message from libevent: %s", buf);
break; break;
case _EVENT_LOG_WARN: case _EVENT_LOG_WARN:
log(LOG_WARN, LD_NOCB|LD_GENERAL, "Warning from libevent: %s", buf); log_warn(LD_NOCB|LD_GENERAL, "Warning from libevent: %s", buf);
break; break;
case _EVENT_LOG_ERR: case _EVENT_LOG_ERR:
log(LOG_ERR, LD_NOCB|LD_GENERAL, "Error from libevent: %s", buf); log_err(LD_NOCB|LD_GENERAL, "Error from libevent: %s", buf);
break; break;
default: default:
log(LOG_WARN, LD_NOCB|LD_GENERAL, "Message [%d] from libevent: %s", log_warn(LD_NOCB|LD_GENERAL, "Message [%d] from libevent: %s",
severity, buf); severity, buf);
break; break;
} }
...@@ -261,13 +261,13 @@ tor_libevent_initialize(tor_libevent_cfg *torcfg) ...@@ -261,13 +261,13 @@ tor_libevent_initialize(tor_libevent_cfg *torcfg)
#if defined(HAVE_EVENT_GET_VERSION) && defined(HAVE_EVENT_GET_METHOD) #if defined(HAVE_EVENT_GET_VERSION) && defined(HAVE_EVENT_GET_METHOD)
/* Making this a NOTICE for now so we can link bugs to a libevent versions /* Making this a NOTICE for now so we can link bugs to a libevent versions
* or methods better. */ * or methods better. */
log(LOG_INFO, LD_GENERAL, log_info(LD_GENERAL,
"Initialized libevent version %s using method %s. Good.", "Initialized libevent version %s using method %s. Good.",
event_get_version(), tor_libevent_get_method()); event_get_version(), tor_libevent_get_method());
#else #else
log(LOG_NOTICE, LD_GENERAL, log_notice(LD_GENERAL,
"Initialized old libevent (version 1.0b or earlier)."); "Initialized old libevent (version 1.0b or earlier).");
log(LOG_WARN, LD_GENERAL, log_warn(LD_GENERAL,
"You have a *VERY* old version of libevent. It is likely to be buggy; " "You have a *VERY* old version of libevent. It is likely to be buggy; "
"please build Tor with a more recent version."); "please build Tor with a more recent version.");
#endif #endif
...@@ -440,7 +440,7 @@ tor_check_libevent_header_compatibility(void) ...@@ -440,7 +440,7 @@ tor_check_libevent_header_compatibility(void)
verybad = compat1 != compat2; verybad = compat1 != compat2;
log(verybad ? LOG_WARN : LOG_NOTICE, tor_log(verybad ? LOG_WARN : LOG_NOTICE,
LD_GENERAL, "We were compiled with headers from version %s " LD_GENERAL, "We were compiled with headers from version %s "
"of Libevent, but we're using a Libevent library that says it's " "of Libevent, but we're using a Libevent library that says it's "
"version %s.", HEADER_VERSION, event_get_version()); "version %s.", HEADER_VERSION, event_get_version());
......
...@@ -151,10 +151,10 @@ crypto_log_errors(int severity, const char *doing) ...@@ -151,10 +151,10 @@ crypto_log_errors(int severity, const char *doing)
if (!lib) lib = "(null)"; if (!lib) lib = "(null)";
if (!func) func = "(null)"; if (!func) func = "(null)";
if (doing) { if (doing) {
log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)", tor_log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)",
doing, msg, lib, func); doing, msg, lib, func);
} else { } else {
log(severity, LD_CRYPTO, "crypto error: %s (in %s:%s)", msg, lib, func); tor_log(severity, LD_CRYPTO, "crypto error: %s (in %s:%s)", msg, lib, func);
} }
} }
} }
...@@ -168,10 +168,10 @@ log_engine(const char *fn, ENGINE *e) ...@@ -168,10 +168,10 @@ log_engine(const char *fn, ENGINE *e)
const char *name, *id; const char *name, *id;
name = ENGINE_get_name(e); name = ENGINE_get_name(e);
id = ENGINE_get_id(e); id = ENGINE_get_id(e);
log(LOG_NOTICE, LD_CRYPTO, "Using OpenSSL engine %s [%s] for %s", log_notice(LD_CRYPTO, "Using OpenSSL engine %s [%s] for %s",
name?name:"?", id?id:"?", fn); name?name:"?", id?id:"?", fn);
} else { } else {
log(LOG_INFO, LD_CRYPTO, "Using default implementation for %s", fn); log_info(LD_CRYPTO, "Using default implementation for %s", fn);
} }
} }
#endif #endif
......
...@@ -321,7 +321,7 @@ tor_process_monitor_poll_cb(evutil_socket_t unused1, short unused2, ...@@ -321,7 +321,7 @@ tor_process_monitor_poll_cb(evutil_socket_t unused1, short unused2,
its_dead_jim = its_dead_jim && (errno == ESRCH); its_dead_jim = its_dead_jim && (errno == ESRCH);
#endif #endif
log(its_dead_jim ? LOG_NOTICE : LOG_INFO, tor_log(its_dead_jim ? LOG_NOTICE : LOG_INFO,
procmon->log_domain, "Monitored process "PID_T_FORMAT" is %s.", procmon->log_domain, "Monitored process "PID_T_FORMAT" is %s.",
procmon->pid, procmon->pid,
its_dead_jim ? "dead" : "still alive"); its_dead_jim ? "dead" : "still alive");
......
...@@ -153,7 +153,7 @@ void set_log_time_granularity(int granularity_msec); ...@@ -153,7 +153,7 @@ void set_log_time_granularity(int granularity_msec);
void tor_log(int severity, log_domain_mask_t domain, const char *format, ...) void tor_log(int severity, log_domain_mask_t domain, const char *format, ...)
CHECK_PRINTF(3,4); CHECK_PRINTF(3,4);
#define log tor_log /* hack it so we don't conflict with log() as much */ #define log tor_log /* hack it so we don't conflict with tor_log() as much */
#if defined(__GNUC__) || defined(RUNNING_DOXYGEN) #if defined(__GNUC__) || defined(RUNNING_DOXYGEN)
extern int log_global_min_severity_; extern int log_global_min_severity_;
......
...@@ -334,11 +334,11 @@ tor_tls_log_one_error(tor_tls_t *tls, unsigned long err, ...@@ -334,11 +334,11 @@ tor_tls_log_one_error(tor_tls_t *tls, unsigned long err,
if (!lib) lib = "(null)"; if (!lib) lib = "(null)";
if (!func) func = "(null)"; if (!func) func = "(null)";
if (doing) { if (doing) {
log(severity, domain, "TLS error while %s%s%s: %s (in %s:%s:%s)", tor_log(severity, domain, "TLS error while %s%s%s: %s (in %s:%s:%s)",
doing, addr?" with ":"", addr?addr:"", doing, addr?" with ":"", addr?addr:"",
msg, lib, func, state); msg, lib, func, state);
} else { } else {
log(severity, domain, "TLS error%s%s: %s (in %s:%s:%s)", tor_log(severity, domain, "TLS error%s%s: %s (in %s:%s:%s)",
addr?" with ":"", addr?addr:"", addr?" with ":"", addr?addr:"",
msg, lib, func, state); msg, lib, func, state);
} }
...@@ -427,12 +427,12 @@ tor_tls_get_error(tor_tls_t *tls, int r, int extra, ...@@ -427,12 +427,12 @@ tor_tls_get_error(tor_tls_t *tls, int r, int extra,
if (extra&CATCH_SYSCALL) if (extra&CATCH_SYSCALL)
return TOR_TLS_SYSCALL_; return TOR_TLS_SYSCALL_;
if (r == 0) { if (r == 0) {
log(severity, LD_NET, "TLS error: unexpected close while %s (%s)", tor_log(severity, LD_NET, "TLS error: unexpected close while %s (%s)",
doing, SSL_state_string_long(tls->ssl)); doing, SSL_state_string_long(tls->ssl));
tor_error = TOR_TLS_ERROR_IO; tor_error = TOR_TLS_ERROR_IO;
} else { } else {
int e = tor_socket_errno(tls->socket); int e = tor_socket_errno(tls->socket);
log(severity, LD_NET, tor_log(severity, LD_NET,
"TLS error: <syscall error while %s> (errno=%d: %s; state=%s)", "TLS error: <syscall error while %s> (errno=%d: %s; state=%s)",
doing, e, tor_socket_strerror(e), doing, e, tor_socket_strerror(e),
SSL_state_string_long(tls->ssl)); SSL_state_string_long(tls->ssl));
...@@ -443,7 +443,7 @@ tor_tls_get_error(tor_tls_t *tls, int r, int extra, ...@@ -443,7 +443,7 @@ tor_tls_get_error(tor_tls_t *tls, int r, int extra,
case SSL_ERROR_ZERO_RETURN: case SSL_ERROR_ZERO_RETURN:
if (extra&CATCH_ZERO) if (extra&CATCH_ZERO)
return TOR_TLS_ZERORETURN_; return TOR_TLS_ZERORETURN_;
log(severity, LD_NET, "TLS connection closed while %s in state %s", tor_log(severity, LD_NET, "TLS connection closed while %s in state %s",
doing, SSL_state_string_long(tls->ssl)); doing, SSL_state_string_long(tls->ssl));
tls_log_errors(tls, severity, domain, doing); tls_log_errors(tls, severity, domain, doing);
return TOR_TLS_CLOSE; return TOR_TLS_CLOSE;
...@@ -1224,7 +1224,7 @@ tor_tls_context_new(crypto_pk_t *identity, unsigned int key_lifetime, ...@@ -1224,7 +1224,7 @@ tor_tls_context_new(crypto_pk_t *identity, unsigned int key_lifetime,
authcert = tor_tls_create_certificate(rsa_auth, identity, nickname, nn2, authcert = tor_tls_create_certificate(rsa_auth, identity, nickname, nn2,
key_lifetime); key_lifetime);
if (!cert || !idcert || !authcert) { if (!cert || !idcert || !authcert) {
log(LOG_WARN, LD_CRYPTO, "Error creating certificate"); log_warn(LD_CRYPTO, "Error creating certificate");
goto error; goto error;
} }
} }
...@@ -2272,7 +2272,7 @@ tor_tls_shutdown(tor_tls_t *tls) ...@@ -2272,7 +2272,7 @@ tor_tls_shutdown(tor_tls_t *tls)
*/ */
if (tls->state == TOR_TLS_ST_GOTCLOSE || if (tls->state == TOR_TLS_ST_GOTCLOSE ||
tls->state == TOR_TLS_ST_SENTCLOSE) { tls->state == TOR_TLS_ST_SENTCLOSE) {
log(LOG_WARN, LD_NET, log_warn(LD_NET,
"TLS returned \"half-closed\" value while already half-closed"); "TLS returned \"half-closed\" value while already half-closed");
return TOR_TLS_ERROR_MISC; return TOR_TLS_ERROR_MISC;
} }
...@@ -2322,7 +2322,7 @@ log_cert_lifetime(int severity, const X509 *cert, const char *problem) ...@@ -2322,7 +2322,7 @@ log_cert_lifetime(int severity, const X509 *cert, const char *problem)
struct tm tm; struct tm tm;
if (problem) if (problem)
log(severity, LD_GENERAL, tor_log(severity, LD_GENERAL,
"Certificate %s. Either their clock is set wrong, or your clock " "Certificate %s. Either their clock is set wrong, or your clock "
"is wrong.", "is wrong.",
problem); problem);
...@@ -2347,7 +2347,7 @@ log_cert_lifetime(int severity, const X509 *cert, const char *problem) ...@@ -2347,7 +2347,7 @@ log_cert_lifetime(int severity, const X509 *cert, const char *problem)
strftime(mytime, 32, "%b %d %H:%M:%S %Y UTC", tor_gmtime_r(&now, &tm)); strftime(mytime, 32, "%b %d %H:%M:%S %Y UTC", tor_gmtime_r(&now, &tm));
log(severity, LD_GENERAL, tor_log(severity, LD_GENERAL,
"(certificate lifetime runs from %s through %s. Your time is %s.)", "(certificate lifetime runs from %s through %s. Your time is %s.)",
s1,s2,mytime); s1,s2,mytime);
...@@ -2568,7 +2568,7 @@ check_no_tls_errors_(const char *fname, int line) ...@@ -2568,7 +2568,7 @@ check_no_tls_errors_(const char *fname, int line)
{ {
if (ERR_peek_error() == 0) if (ERR_peek_error() == 0)
return; return;
log(LOG_WARN, LD_CRYPTO, "Unhandled OpenSSL errors found at %s:%d: ", log_warn(LD_CRYPTO, "Unhandled OpenSSL errors found at %s:%d: ",
tor_fix_source_file(fname), line); tor_fix_source_file(fname), line);
tls_log_errors(NULL, LOG_WARN, LD_NET, NULL); tls_log_errors(NULL, LOG_WARN, LD_NET, NULL);
} }
......
...@@ -324,12 +324,12 @@ tor_log_mallinfo(int severity) ...@@ -324,12 +324,12 @@ tor_log_mallinfo(int severity)
/** /**
* Returns the natural logarithm of d base 2. We define this wrapper here so * Returns the natural logarithm of d base 2. We define this wrapper here so
* as to make it easier not to conflict with Tor's log() macro. * as to make it easier not to conflict with Tor's tor_log() macro.
*/ */
double double
tor_mathlog(double d) tor_mathlog(double d)
{ {
return log(d); return tor_log(d);
} }
/** Return the long integer closest to <b>d</b>. We define this wrapper /** Return the long integer closest to <b>d</b>. We define this wrapper
......
...@@ -534,7 +534,7 @@ nameserver_probe_failed(struct nameserver *const ns) { ...@@ -534,7 +534,7 @@ nameserver_probe_failed(struct nameserver *const ns) {
ns->failed_times++; ns->failed_times++;
if (add_timeout_event(ns, (struct timeval *) timeout) < 0) { if (add_timeout_event(ns, (struct timeval *) timeout) < 0) {
log(EVDNS_LOG_WARN, tor_log(EVDNS_LOG_WARN,
"Error from libevent when adding timer event for %s", "Error from libevent when adding timer event for %s",
debug_ntop((struct sockaddr *)&ns->address)); debug_ntop((struct sockaddr *)&ns->address));
/* ???? Do more? */ /* ???? Do more? */
...@@ -550,19 +550,19 @@ nameserver_failed(struct nameserver *const ns, const char *msg) { ...@@ -550,19 +550,19 @@ nameserver_failed(struct nameserver *const ns, const char *msg) {
/* then don't do anything */ /* then don't do anything */
if (!ns->state) return; if (!ns->state) return;
log(EVDNS_LOG_WARN, "Nameserver %s has failed: %s", tor_log(EVDNS_LOG_WARN, "Nameserver %s has failed: %s",
debug_ntop((struct sockaddr *)&ns->address), msg); debug_ntop((struct sockaddr *)&ns->address), msg);
global_good_nameservers--; global_good_nameservers--;
assert(global_good_nameservers >= 0); assert(global_good_nameservers >= 0);
if (global_good_nameservers == 0) { if (global_good_nameservers == 0) {
log(EVDNS_LOG_WARN, "All nameservers have failed"); tor_log(EVDNS_LOG_WARN, "All nameservers have failed");
} }
ns->state = 0; ns->state = 0;
ns->failed_times = 1; ns->failed_times = 1;
if (add_timeout_event(ns, (struct timeval *) &global_nameserver_timeouts[0]) < 0) { if (add_timeout_event(ns, (struct timeval *) &global_nameserver_timeouts[0]) < 0) {
log(EVDNS_LOG_WARN, tor_log(EVDNS_LOG_WARN,
"Error from libevent when adding timer event for %s", "Error from libevent when adding timer event for %s",
debug_ntop((struct sockaddr *)&ns->address)); debug_ntop((struct sockaddr *)&ns->address));
/* ???? Do more? */ /* ???? Do more? */
...@@ -593,7 +593,7 @@ nameserver_failed(struct nameserver *const ns, const char *msg) { ...@@ -593,7 +593,7 @@ nameserver_failed(struct nameserver *const ns, const char *msg) {
static void static void
nameserver_up(struct nameserver *const ns) { nameserver_up(struct nameserver *const ns) {
if (ns->state) return; if (ns->state) return;
log(EVDNS_LOG_WARN, "Nameserver %s is back up", tor_log(EVDNS_LOG_WARN, "Nameserver %s is back up",
debug_ntop((struct sockaddr *)&ns->address)); debug_ntop((struct sockaddr *)&ns->address));
del_timeout_event(ns); del_timeout_event(ns);
ns->state = 1; ns->state = 1;
...@@ -624,7 +624,7 @@ request_finished(struct evdns_request *const req, struct evdns_request **head) { ...@@ -624,7 +624,7 @@ request_finished(struct evdns_request *const req, struct evdns_request **head) {
} }
} }
log(EVDNS_LOG_DEBUG, "Removing timeout for request %lx", tor_log(EVDNS_LOG_DEBUG, "Removing timeout for request %lx",
(unsigned long) req); (unsigned long) req);
del_timeout_event(req); del_timeout_event(req);
...@@ -776,7 +776,7 @@ reply_handle(struct evdns_request *const req, u16 flags, u32 ttl, struct reply * ...@@ -776,7 +776,7 @@ reply_handle(struct evdns_request *const req, u16 flags, u32 ttl, struct reply *
* confusing." Treat this as a timeout, not a failure. * confusing." Treat this as a timeout, not a failure.
*/ */
/*XXXX refactor the parts of */ /*XXXX refactor the parts of */
log(EVDNS_LOG_DEBUG, "Got a SERVERFAILED from nameserver %s; " tor_log(EVDNS_LOG_DEBUG, "Got a SERVERFAILED from nameserver %s; "
"will allow the request to time out.", "will allow the request to time out.",
debug_ntop((struct sockaddr *)&req->ns->address)); debug_ntop((struct sockaddr *)&req->ns->address));
break; break;
...@@ -1268,7 +1268,7 @@ nameserver_read(struct nameserver *ns) { ...@@ -1268,7 +1268,7 @@ nameserver_read(struct nameserver *ns) {
} }
/* XXX Match port too? */ /* XXX Match port too? */
if (!sockaddr_eq(sa, (struct sockaddr*)&ns->address, 0)) { if (!sockaddr_eq(sa, (struct sockaddr*)&ns->address, 0)) {
log(EVDNS_LOG_WARN, tor_log(EVDNS_LOG_WARN,
"Address mismatch on received DNS packet. Address was %s", "Address mismatch on received DNS packet. Address was %s",
debug_ntop(sa)); debug_ntop(sa));
return; return;
...@@ -1294,7 +1294,7 @@ server_port_read(struct evdns_server_port *s) { ...@@ -1294,7 +1294,7 @@ server_port_read(struct evdns_server_port *s) {
if (r < 0) { if (r < 0) {
int err = last_error(s->socket); int err = last_error(s->socket);
if (error_is_eagain(err)) return; if (error_is_eagain(err)) return;
log(EVDNS_LOG_WARN, "Error %s (%d) while reading request.", tor_log(EVDNS_LOG_WARN, "Error %s (%d) while reading request.",
tor_socket_strerror(err), err); tor_socket_strerror(err), err);
return; return;
} }
...@@ -1314,7 +1314,7 @@ server_port_flush(struct evdns_server_port *port) ...@@ -1314,7 +1314,7 @@ server_port_flush(struct evdns_server_port *port)
int err = last_error(port->socket); int err = last_error(port->socket);
if (error_is_eagain(err)) if (error_is_eagain(err))
return; return;
log(EVDNS_LOG_WARN, "Error %s (%d) while writing response to port; dropping", tor_socket_strerror(err), err); tor_log(EVDNS_LOG_WARN, "Error %s (%d) while writing response to port; dropping", tor_socket_strerror(err), err);
} }
if (server_request_free(req)) { if (server_request_free(req)) {
/* we released the last reference to req->port. */ /* we released the last reference to req->port. */
...@@ -1331,7 +1331,7 @@ server_port_flush(struct evdns_server_port *port) ...@@ -1331,7 +1331,7 @@ server_port_flush(struct evdns_server_port *port)
event_set(&port->event, port->socket, EV_READ | EV_PERSIST, event_set(&port->event, port->socket, EV_READ | EV_PERSIST,
server_port_ready_callback, port); server_port_ready_callback, port);
if (event_add(&port->event, NULL) < 0) { if (event_add(&port->event, NULL) < 0) {
log(EVDNS_LOG_WARN, "Error from libevent when adding event for DNS server."); tor_log(EVDNS_LOG_WARN, "Error from libevent when adding event for DNS server.");
/* ???? Do more? */ /* ???? Do more? */
} }
} }
...@@ -1349,7 +1349,7 @@ nameserver_write_waiting(struct nameserver *ns, char waiting) { ...@@ -1349,7 +1349,7 @@ nameserver_write_waiting(struct nameserver *ns, char waiting) {
event_set(&ns->event, ns->socket, EV_READ | (waiting ? EV_WRITE : 0) | EV_PERSIST, event_set(&ns->event, ns->socket, EV_READ | (waiting ? EV_WRITE : 0) | EV_PERSIST,
nameserver_ready_callback, ns); nameserver_ready_callback, ns);
if (event_add(&ns->event, NULL) < 0) { if (event_add(&ns->event, NULL) < 0) {
log(EVDNS_LOG_WARN, "Error from libevent when adding event for %s", tor_log(EVDNS_LOG_WARN, "Error from libevent when adding event for %s",
debug_ntop((struct sockaddr *)&ns->address)); debug_ntop((struct sockaddr *)&ns->address));
/* ???? Do more? */ /* ???? Do more? */
} }
...@@ -1859,7 +1859,7 @@ evdns_server_request_respond(struct evdns_server_request *_req, int err) ...@@ -1859,7 +1859,7 @@ evdns_server_request_respond(struct evdns_server_request *_req, int err)
event_set(&port->event, port->socket, (port->closing?0:EV_READ) | EV_WRITE | EV_PERSIST, server_port_ready_callback, port); event_set(&port->event, port->socket, (port->closing?0:EV_READ) | EV_WRITE | EV_PERSIST, server_port_ready_callback, port);
if (event_add(&port->event, NULL) < 0) { if (event_add(&port->event, NULL) < 0) {
log(EVDNS_LOG_WARN, "Error from libevent when adding event for DNS server"); tor_log(EVDNS_LOG_WARN, "Error from libevent when adding event for DNS server");
} }
} }
...@@ -1995,7 +1995,7 @@ evdns_request_timeout_callback(int fd, short events, void *arg) { ...@@ -1995,7 +1995,7 @@ evdns_request_timeout_callback(int fd, short events, void *arg) {
(void) fd; (void) fd;
(void) events; (void) events;
log(EVDNS_LOG_DEBUG, "Request %lx timed out", (unsigned long) arg); tor_log(EVDNS_LOG_DEBUG, "Request %lx timed out", (unsigned long) arg);
req->ns->timedout++; req->ns->timedout++;
if (req->ns->timedout > global_max_nameserver_timeout) { if (req->ns->timedout > global_max_nameserver_timeout) {
...@@ -2074,11 +2074,11 @@ evdns_request_transmit(struct evdns_request *req) { ...@@ -2074,11 +2074,11 @@ evdns_request_transmit(struct evdns_request *req) {
* and make us retransmit the request anyway. */ * and make us retransmit the request anyway. */
default: default:
/* transmitted; we need to check for timeout. */ /* transmitted; we need to check for timeout. */
log(EVDNS_LOG_DEBUG, tor_log(EVDNS_LOG_DEBUG,
"Setting timeout for request %lx", (unsigned long) req); "Setting timeout for request %lx", (unsigned long) req);
if (add_timeout_event(req, &global_timeout) < 0) { if (add_timeout_event(req, &global_timeout) < 0) {
log(EVDNS_LOG_WARN, tor_log(EVDNS_LOG_WARN,
"Error from libevent when adding timer for request %lx", "Error from libevent when adding timer for request %lx",
(unsigned long) req); (unsigned long) req);
/* ???? Do more? */ /* ???? Do more? */
...@@ -2126,7 +2126,7 @@ nameserver_send_probe(struct nameserver *const ns) { ...@@ -2126,7 +2126,7 @@ nameserver_send_probe(struct nameserver *const ns) {
addr = mm_malloc(sizeof(struct sockaddr_storage)); addr = mm_malloc(sizeof(struct sockaddr_storage));
memcpy(addr, &ns->address, sizeof(struct sockaddr_storage)); memcpy(addr, &ns->address, sizeof(struct sockaddr_storage));
log(EVDNS_LOG_DEBUG, "Sending probe to %s", debug_ntop((struct sockaddr *)&ns->address)); tor_log(EVDNS_LOG_DEBUG, "Sending probe to %s", debug_ntop((struct sockaddr *)&ns->address));
req = request_new(TYPE_A, "www.google.com", DNS_QUERY_NO_SEARCH, nameserver_probe_callback, addr); req = request_new(TYPE_A, "www.google.com", DNS_QUERY_NO_SEARCH, nameserver_probe_callback, addr);
if (!req) { if (!req) {
...@@ -2282,14 +2282,14 @@ _evdns_nameserver_add_impl(const struct sockaddr *address, ...@@ -2282,14 +2282,14 @@ _evdns_nameserver_add_impl(const struct sockaddr *address,
if (server) { if (server) {
do { do {
if (sockaddr_eq(address, (struct sockaddr *)&server->address, 1)) { if (sockaddr_eq(address, (struct sockaddr *)&server->address, 1)) {
log(EVDNS_LOG_DEBUG, "Duplicate nameserver."); tor_log(EVDNS_LOG_DEBUG, "Duplicate nameserver.");
return 3; return 3;
} }
server = server->next; server = server->next;
} while (server != started_at); } while (server != started_at);
} }
if (addrlen > (int)sizeof(ns->address)) { if (addrlen > (int)sizeof(ns->address)) {
log(EVDNS_LOG_DEBUG, "Addrlen %d too long.", (int)addrlen); tor_log(EVDNS_LOG_DEBUG, "Addrlen %d too long.", (int)addrlen);
return 2; return 2;
} }
...@@ -2315,14 +2315,14 @@ _evdns_nameserver_add_impl(const struct sockaddr *address, ...@@ -2315,14 +2315,14 @@ _evdns_nameserver_add_impl(const struct sockaddr *address,
!sockaddr_is_loopback((struct sockaddr*)&global_bind_address)) { !sockaddr_is_loopback((struct sockaddr*)&global_bind_address)) {
if (bind(ns->socket, (struct sockaddr *)&global_bind_address, if (bind(ns->socket, (struct sockaddr *)&global_bind_address,
global_bind_addrlen) < 0) { global_bind_addrlen) < 0) {
log(EVDNS_LOG_DEBUG, "Couldn't bind to outgoing address."); tor_log(EVDNS_LOG_DEBUG, "Couldn't bind to outgoing address.");
err = 2; err = 2;
goto out2; goto out2;
} }
} }
if (connect(ns->socket, address, addrlen) != 0) { if (connect(ns->socket, address, addrlen) != 0) {
log(EVDNS_LOG_DEBUG, "Couldn't open socket to nameserver."); tor_log(EVDNS_LOG_DEBUG, "Couldn't open socket to nameserver.");
err = 2; err = 2;
goto out2; goto out2;
} }
...@@ -2331,12 +2331,12 @@ _evdns_nameserver_add_impl(const struct sockaddr *address, ...@@ -2331,12 +2331,12 @@ _evdns_nameserver_add_impl(const struct sockaddr *address,
ns->state = 1; ns->state = 1;
event_set(&ns->event, ns->socket, EV_READ | EV_PERSIST, nameserver_ready_callback, ns); event_set(&ns->event, ns->socket, EV_READ | EV_PERSIST, nameserver_ready_callback, ns);
if (event_add(&ns->event, NULL) < 0) { if (event_add(&ns->event, NULL) < 0) {
log(EVDNS_LOG_DEBUG, "Couldn't add event for nameserver."); tor_log(EVDNS_LOG_DEBUG, "Couldn't add event for nameserver.");
err = 2; err = 2;
goto out2; goto out2;
} }
log(EVDNS_LOG_DEBUG, "Added nameserver %s", debug_ntop(address)); tor_log(EVDNS_LOG_DEBUG, "Added nameserver %s", debug_ntop(address));
/* insert this nameserver into the list of them */ /* insert this nameserver into the list of them */
if (!server_head) { if (!server_head) {
...@@ -2360,7 +2360,7 @@ out2: ...@@ -2360,7 +2360,7 @@ out2:
out1: out1:
CLEAR(ns); CLEAR(ns);
mm_free(ns); mm_free(ns);
log(EVDNS_LOG_WARN, "Unable to add nameserver %s: error %d", debug_ntop(address), err);