summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-04-01 02:37:40 +0000
committerNick Mathewson <nickm@torproject.org>2005-04-01 02:37:40 +0000
commitefe9ca659a3d53b388124e2dd777d29e4914e1fb (patch)
tree9b61f8a09b38909d78536d4af118afe3ea718150
parent837d7dff69c9844e40d9cdd440906e2dbe97106c (diff)
downloadtor-efe9ca659a3d53b388124e2dd777d29e4914e1fb.tar.gz
tor-efe9ca659a3d53b388124e2dd777d29e4914e1fb.zip
Use recent libevent features when possible
svn:r3940
-rw-r--r--configure.in2
-rw-r--r--src/common/log.c34
-rw-r--r--src/common/log.h1
-rw-r--r--src/or/config.c9
-rw-r--r--src/or/main.c7
5 files changed, 51 insertions, 2 deletions
diff --git a/configure.in b/configure.in
index 3ef0668de6..4cc90c5d77 100644
--- a/configure.in
+++ b/configure.in
@@ -152,7 +152,7 @@ dnl These headers are not essential
AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h pthread.h stddef.h inttypes.h)
-AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit setrlimit strlcat strlcpy strtoull getpwnam ftello pthread_create getaddrinfo localtime_r gmtime_r)
+AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit setrlimit strlcat strlcpy strtoull getpwnam ftello pthread_create getaddrinfo localtime_r gmtime_r event_get_version event_get_method event_set_log_callback)
AC_FUNC_FSEEKO
AC_CHECK_MEMBERS([struct timeval.tv_sec])
diff --git a/src/common/log.c b/src/common/log.c
index c134fe4ee0..94a683fb96 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -17,6 +17,12 @@ const char log_c_id[] = "$Id$";
#include "./util.h"
#include "./log.h"
+#ifdef HAVE_EVENT_H
+#include <event.h>
+#else
+#error "Tor requires libevent to build."
+#endif
+
#define TRUNCATED_STR "[...truncated]"
#define TRUNCATED_STR_LEN 14
@@ -475,3 +481,31 @@ void switch_logs_debug(void)
}
}
+#ifdef HAVE_EVENT_SET_LOG_CALLBACK
+void libevent_logging_callback(int severity, const char *msg)
+{
+ switch (severity) {
+ case _EVENT_LOG_DEBUG:
+ log(LOG_DEBUG, "Message from libevent: %s", msg);
+ break;
+ case _EVENT_LOG_MSG:
+ log(LOG_INFO, "Message from libevent: %s", msg);
+ break;
+ case _EVENT_LOG_WARN:
+ log(LOG_WARN, "Warning from libevent: %s", msg);
+ break;
+ case _EVENT_LOG_ERR:
+ log(LOG_ERR, "Error from libevent: %s", msg);
+ break;
+ default:
+ log(LOG_WARN, "Message [%d] from libevent: %s", severity, msg);
+ break;
+ }
+}
+void configure_libevent_logging(void)
+{
+ event_set_log_callback(libevent_logging_callback);
+}
+#else
+void configure_libevent_logging(void) {}
+#endif
diff --git a/src/common/log.h b/src/common/log.h
index d362549e9c..af90f6d90a 100644
--- a/src/common/log.h
+++ b/src/common/log.h
@@ -66,6 +66,7 @@ void reset_logs(void);
void add_temp_log(void);
void close_temp_logs(void);
void mark_logs_temp(void);
+void configure_libevent_logging(void);
/* Outputs a message to stdout */
void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3);
diff --git a/src/or/config.c b/src/or/config.c
index eb48449380..3fc183aec4 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -269,7 +269,16 @@ options_act(void) {
start_daemon(options->DataDirectory);
}
if (!libevent_initialized) {
+ configure_libevent_logging();
event_init();
+#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
+ * or methods better. */
+ log_fn(LOG_NOTICE, "Initialized libevent version %s using method %s",
+ event_get_version(), event_get_method());
+#else
+ log_fn(LOG_NOTICE, "Initialized old libevent (version 1.0b or earlier)");
+#endif
libevent_initialized = 1;
}
diff --git a/src/or/main.c b/src/or/main.c
index 3fd2423032..12d923b9bc 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -953,8 +953,13 @@ static int do_main_loop(void) {
int e = errno;
/* let the program survive things like ^z */
if (e != EINTR) {
- log_fn(LOG_ERR,"event poll failed: %s [%d]",
+#ifdef HAVE_EVENT_GET_METHOD
+ log_fn(LOG_ERR,"libevent poll with %s failed: %s [%d]",
+ event_get_method(), tor_socket_strerror(e), e);
+#else
+ log_fn(LOG_ERR,"libevent poll failed: %s [%d]",
tor_socket_strerror(e), e);
+#endif
return -1;
} else {
log_fn(LOG_DEBUG,"event poll interrupted.");