Commit efe9ca65 authored by Nick Mathewson's avatar Nick Mathewson 🤹
Browse files

Use recent libevent features when possible


svn:r3940
parent 837d7dff
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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])
+34 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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);
+9 −0
Original line number Diff line number Diff line
@@ -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;
  }

+6 −1
Original line number Diff line number Diff line
@@ -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.");