From ebdd396f70b7586f8078b0e9eff312adcbdffd71 Mon Sep 17 00:00:00 2001 From: Hyunjee Kim Date: Mon, 9 Dec 2019 16:33:37 +0900 Subject: [PATCH] Imported Upstream version 2.1.11 Change-Id: Ibcea6fe4d4a26d047815cfdbc3bc1d87afc8e82a Signed-off-by: Hyunjee Kim --- .gitignore | 2 ++ CMakeLists.txt | 46 ++++++++++++++++++++++++++--- ChangeLog | 48 +++++++++++++++++++++++++++++- Makefile.am | 10 ++++--- README.md | 6 ++++ WIN32-Code/nmake/event2/event-config.h | 4 +-- appveyor.yml | 2 +- arc4random.c | 1 + buffer.c | 7 ++++- buffer_iocp.c | 1 + bufferevent_async.c | 1 + cmake/AddEventLibrary.cmake | 54 +++++++++++++++++++++++++++++----- cmake/Uninstall.cmake.in | 23 +++++++++++++++ cmake/VersionViaGit.cmake | 4 +-- configure.ac | 6 ++-- evdns.c | 31 +++++++++++++++++++ event.c | 24 ++++++++------- evutil.c | 11 ++++--- include/event2/buffer_compat.h | 3 +- include/event2/bufferevent.h | 8 ++--- include/event2/dns.h | 3 +- include/event2/event.h | 6 ++-- include/event2/event_struct.h | 2 +- include/include.am | 7 +++-- listener.c | 1 + m4/libevent_openssl.m4 | 2 +- minheap-internal.h | 54 ++++++++++++++++++---------------- sample/https-client.c | 2 +- test/regress_buffer.c | 12 ++++++-- test/regress_dns.c | 23 +++++++++++++++ util-internal.h | 20 ++++++++----- 31 files changed, 336 insertions(+), 88 deletions(-) create mode 100644 cmake/Uninstall.cmake.in diff --git a/.gitignore b/.gitignore index 4af0358..955846c 100644 --- a/.gitignore +++ b/.gitignore @@ -129,6 +129,7 @@ LibeventConfigVersion.cmake LibeventTargets.cmake bin/ cmake_install.cmake +Uninstall.cmake lib/ tmp/ verify_tests.sh @@ -139,6 +140,7 @@ event_extra.dir *.vcxproj *.sln *.filters +install_manifest.txt # ninja build.ninja diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e91c08..70acb69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,14 @@ set(EVENT_ABI_LIBVERSION set(EVENT_PACKAGE_VERSION "${EVENT_VERSION_MAJOR}.${EVENT_VERSION_MINOR}.${EVENT_VERSION_PATCH}") -set(EVENT_NUMERIC_VERSION 0x02010a00) +set(EVENT_NUMERIC_VERSION 0x02010b00) +# equals to VERSION_INFO in Makefile.am +set(EVENT_ABI_LIBVERSION_CURRENT 7) +set(EVENT_ABI_LIBVERSION_REVISION 0) +set(EVENT_ABI_LIBVERSION_AGE 0) + +# equals to RELEASE in Makefile.am +set(EVENT_PACKAGE_RELEASE 2.1) # only a subset of names can be used, defaults to "beta" set(EVENT_STAGE_NAME ${EVENT_VERSION_STAGE}) @@ -322,7 +329,7 @@ endif() # Winsock. if(WIN32) set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h) - set(CMAKE_REQUIRED_LIBRARIES ws2_32.lib) + set(CMAKE_REQUIRED_LIBRARIES ws2_32.lib shell32.lib advapi32.lib) set(CMAKE_REQUIRED_DEFINITIONS -FIwinsock2.h -FIws2tcpip.h) endif() if (SOLARIS) @@ -337,6 +344,10 @@ if (NOT DEFINED _GNU_SOURCE) unset(_GNU_SOURCE CACHE) CHECK_SYMBOL_EXISTS(_GNU_SOURCE "features.h" _GNU_SOURCE) endif() + + if (ANDROID) + set(_GNU_SOURCE TRUE) + endif() endif() if (_GNU_SOURCE) @@ -626,7 +637,7 @@ CHECK_TYPE_SIZE("time_t" EVENT__SIZEOF_TIME_T) # Verify kqueue works with pipes. if (EVENT__HAVE_KQUEUE) - if (CMAKE_CROSSCOMPILING AND NOT EVENT__FORCE_KQUEUE_CHECK) + if ((CMAKE_CROSSCOMPILING OR APPLE) AND NOT EVENT__FORCE_KQUEUE_CHECK) message(WARNING "Cannot check if kqueue works with pipes when crosscompiling, use EVENT__FORCE_KQUEUE_CHECK to be sure (this requires manually running a test program on the cross compilation target)") set(EVENT__HAVE_WORKING_KQUEUE 1) else() @@ -873,7 +884,7 @@ if(WIN32) list(APPEND HDR_PRIVATE WIN32-Code/getopt.h) set(EVENT__DNS_USE_FTIME_FOR_ID 1) - set(LIB_PLATFORM ws2_32) + set(LIB_PLATFORM ws2_32 shell32 advapi32) add_definitions( -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE) @@ -1465,6 +1476,33 @@ install(EXPORT LibeventTargets DESTINATION "${DEF_INSTALL_CMAKE_DIR}" COMPONENT dev) +# Install the scripts. +install(PROGRAMS + ${CMAKE_CURRENT_SOURCE_DIR}/event_rpcgen.py + DESTINATION "bin" + COMPONENT runtime) + +# Create documents with doxygen. +find_program(DOXYGEN doxygen) +if (DOXYGEN) + add_custom_target(doxygen + COMMAND ${DOXYGEN} Doxyfile + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +else() + message(WARNING "The doxygen target will not support since doxygen command was not found!") +endif() + + +# Create the uninstall target. +# https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake +configure_file(${PROJECT_SOURCE_DIR}/cmake/Uninstall.cmake.in + ${PROJECT_BINARY_DIR}/Uninstall.cmake + @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/Uninstall.cmake) + + message(STATUS "") message(STATUS " ---( Libevent " ${EVENT_VERSION} " )---") message(STATUS "") diff --git a/ChangeLog b/ChangeLog index 1cc6007..e89d5a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,49 @@ +Changes in version 2.1.11-stable (01 Aug 2019) + + This release contains one ABI breakage fix (that had been introduced in + 2.1.10, and strictly speaking this release breaks ABI again to make it + compatible with 2.1.9 and less, please take a look at 18104973 for more + details). Apart from that it contains some bug fixes, that grouped below. + + And even though the return value for evbuffer_setcb() had been changed it + should ABI compatible (anyway that function is in -compat.h header). + + There is also one patch that introduce new functionality, this is 546a366c, + to tune SO_RCVBUF/SO_SNDBUF in evdns, but one can count it as a bug-fix on + the application level, since before you cannot tune this settings and hence + you could stumble on problems. + + ABI breakage: + o Protect min_heap_push_ against integer overflow. (8c899768 Tobias Stoeckmann) + o Revert "Protect min_heap_push_ against integer overflow." (18104973 Azat Khuzhin) + + functionality: + o evdns: add new options -- so-rcvbuf/so-sndbuf (546a366c Azat Khuzhin) + + build: + o Change autoconf version to 2.62 and automake version to 1.11.2 (2a333008 yuangongji) + o cmake: install shared library only if it was requested (596855f7 Azat Khuzhin) + o Missing on win7/MinGW(MINGW32_NT-6.1)/MSYS (9559349c yuangongji) + o cmake: set library names to be the same as with autotools (305251b9 yuangongji) + o Enable _GNU_SOURCE for Android (f013fc7d Keith Smiley) + o Enable kqueue for APPLE targets (3aa68a82 Keith Smiley) + o autotools: do not install bufferevent_ssl.h under --disable-openssl (5349a07e Azat Khuzhin) + o cmake: link against shell32.lib/advapi32.lib (c9ce638c Azat Khuzhin) + o Add README.md into dist archive (3660a4cc Azat Khuzhin) + o cmake: add missing autotools targets (doxygen, uninstall, event_rpcgen.py) (2d65071c yuangongji) + o m4/libevent_openssl.m4: fix detection of openssl (d4056e59 Fabrice Fontaine) + o Fix detection of the __has_attribute() for apple clang [ci skip] (7fd7c5ef Azat Khuzhin) + + lib: + o buffer: fix possible NULL dereference in evbuffer_setcb() on ENOMEM (598f247d Azat Khuzhin) + o Warn if forked from the event loop during event_reinit() (b75922ae Azat Khuzhin) + o evutil: set the have_checked_interfaces in evutil_check_interfaces() + (ef498aa2, a09265ac jeremyerb) + + samples: + o https-client: correction error checking (a8a04565 wenyg) + + Changes in version 2.1.10-stable (26 May 2019) This release contains mostly fixes (some evbuffer oddity, AF_UNIX handling in @@ -9,7 +55,7 @@ Changes in version 2.1.10-stable (26 May 2019) trivial fixes pruned out from it - to make it a little bit more informative). To view full changelog please use git: - git log --format=' o %s (%h %aN)' release-2.1.8-stable...release-2.1.9-beta + git log --format=' o %s (%h %aN)' release-2.1.9-beta...release-2.1.10-stable dist: o Add getopt into dist archive (7042ff24 Azat Khuzhin) diff --git a/Makefile.am b/Makefile.am index 240d014..dd90502 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,8 +5,8 @@ # See LICENSE for copying information. # 'foreign' means that we're not enforcing GNU package rules strictly. -# '1.9' means that we need automake 1.9 or later (and we do). -AUTOMAKE_OPTIONS = foreign 1.9 subdir-objects +# '1.11.2' means that we need automake 1.11.2 or later (and we do). +AUTOMAKE_OPTIONS = foreign 1.11.2 subdir-objects ACLOCAL_AMFLAGS = -I m4 @@ -38,7 +38,7 @@ RELEASE = -release 2.1 # # Once an RC is out, DO NOT MAKE ANY ABI-BREAKING CHANGES IN THAT SERIES # UNLESS YOU REALLY REALLY HAVE TO. -VERSION_INFO = 6:4:0 +VERSION_INFO = 7:0:0 # History: RELEASE VERSION_INFO # 2.0.1-alpha -- 2.0 1:0:0 @@ -73,7 +73,8 @@ VERSION_INFO = 6:4:0 # 2.1.7-beta -- 2.1 6:1:0 (ABI changed slightly) # 2.1.8-stable-- 2.1 6:2:0 (No ABI change) # 2.1.9-beta-- 2.1 6:3:0 (No ABI change) -# 2.1.10-stable-- 2.1 6:4:0 (No ABI change) +# 2.1.10-stable-- 2.1 6:4:0 (No ABI change, WRONG) +# 2.1.11-stable-- 2.1 7:0:0 (ABI changed) # ABI version history for this package effectively restarts every time # we change RELEASE. Version 1.4.x had RELEASE of 1.4. @@ -142,6 +143,7 @@ EXTRA_DIST = \ make-event-config.sed \ whatsnew-2.0.txt \ whatsnew-2.1.txt \ + README.md \ $(CMAKE_FILES) \ $(PLATFORM_DEPENDENT_SRC) diff --git a/README.md b/README.md index 2b6d7e4..8be37f4 100644 --- a/README.md +++ b/README.md @@ -459,5 +459,11 @@ fixing bugs: * Yury Korzhetsky * zhuizhuhaomeng * Pierce Lopez + * yuangongji + * Keith Smiley + * jeremyerb + * Fabrice Fontaine + * wenyg + If we have forgotten your name, please contact us. diff --git a/WIN32-Code/nmake/event2/event-config.h b/WIN32-Code/nmake/event2/event-config.h index 51597c3..35ec16f 100644 --- a/WIN32-Code/nmake/event2/event-config.h +++ b/WIN32-Code/nmake/event2/event-config.h @@ -271,7 +271,7 @@ /* #undef EVENT__HAVE_WORKING_KQUEUE */ /* Numeric representation of the version */ -#define EVENT__NUMERIC_VERSION 0x02010a00 +#define EVENT__NUMERIC_VERSION 0x02010b00 /* Name of package */ #define EVENT__PACKAGE "libevent" @@ -332,7 +332,7 @@ #define EVENT__TIME_WITH_SYS_TIME 1 /* Version number of package */ -#define EVENT__VERSION "2.1.10-stable" +#define EVENT__VERSION "2.1.11-stable" /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ diff --git a/appveyor.yml b/appveyor.yml index 9add580..edfe337 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 2.1.10.{build} +version: 2.1.11.{build} os: Visual Studio 2017 platform: diff --git a/arc4random.c b/arc4random.c index 02fd744..be64452 100644 --- a/arc4random.c +++ b/arc4random.c @@ -54,6 +54,7 @@ #ifdef _WIN32 #include #include +#include #else #include #include diff --git a/buffer.c b/buffer.c index 5e3d91b..a51b6c5 100644 --- a/buffer.c +++ b/buffer.c @@ -3304,7 +3304,7 @@ evbuffer_add_file(struct evbuffer *buf, int fd, ev_off_t offset, ev_off_t length return r; } -void +int evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg) { EVBUFFER_LOCK(buffer); @@ -3315,10 +3315,15 @@ evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg) if (cb) { struct evbuffer_cb_entry *ent = evbuffer_add_cb(buffer, NULL, cbarg); + if (!ent) { + EVBUFFER_UNLOCK(buffer); + return -1; + } ent->cb.cb_obsolete = cb; ent->flags |= EVBUFFER_CB_OBSOLETE; } EVBUFFER_UNLOCK(buffer); + return 0; } struct evbuffer_cb_entry * diff --git a/buffer_iocp.c b/buffer_iocp.c index 2d76a90..2af0c49 100644 --- a/buffer_iocp.c +++ b/buffer_iocp.c @@ -44,6 +44,7 @@ #include "mm-internal.h" #include +#include #include #include diff --git a/bufferevent_async.c b/bufferevent_async.c index 141cf34..40c7c5e 100644 --- a/bufferevent_async.c +++ b/bufferevent_async.c @@ -46,6 +46,7 @@ #ifdef _WIN32 #include +#include #include #endif diff --git a/cmake/AddEventLibrary.cmake b/cmake/AddEventLibrary.cmake index 9de4484..352c86b 100644 --- a/cmake/AddEventLibrary.cmake +++ b/cmake/AddEventLibrary.cmake @@ -38,6 +38,10 @@ endmacro() # Global variables that it uses: # - EVENT_ABI_LIBVERSION +# - EVENT_ABI_LIBVERSION_CURRENT +# - EVENT_ABI_LIBVERSION_REVISION +# - EVENT_ABI_LIBVERSION_AGE +# - EVENT_PACKAGE_RELEASE # - CMAKE_THREAD_LIBS_INIT LIB_PLATFORM # - OPENSSL_LIBRARIES # - HDR_PUBLIC @@ -87,16 +91,44 @@ macro(add_event_library LIB_NAME) set_event_shared_lib_flags("${LIB_NAME}" "${EVENT_SHARED_FLAGS}") endif() - set_target_properties("${LIB_NAME}_shared" PROPERTIES - OUTPUT_NAME "${LIB_NAME}" - CLEAN_DIRECT_OUTPUT 1) - set_target_properties( - "${LIB_NAME}_shared" PROPERTIES - PUBLIC_HEADER "${HDR_PUBLIC}") + if (WIN32) + set_target_properties( + "${LIB_NAME}_shared" PROPERTIES + OUTPUT_NAME "${LIB_NAME}" + SOVERSION ${EVENT_ABI_LIBVERSION}) + elseif (APPLE) + math(EXPR COMPATIBILITY_VERSION "${EVENT_ABI_LIBVERSION_CURRENT}+1") + math(EXPR CURRENT_MINUS_AGE "${EVENT_ABI_LIBVERSION_CURRENT}-${EVENT_ABI_LIBVERSION_AGE}") + set_target_properties( + "${LIB_NAME}_shared" PROPERTIES + OUTPUT_NAME "${LIB_NAME}-${EVENT_PACKAGE_RELEASE}.${CURRENT_MINUS_AGE}" + INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib" + LINK_FLAGS "-compatibility_version ${COMPATIBILITY_VERSION} -current_version ${COMPATIBILITY_VERSION}.${EVENT_ABI_LIBVERSION_REVISION}") + else() + math(EXPR CURRENT_MINUS_AGE "${EVENT_ABI_LIBVERSION_CURRENT}-${EVENT_ABI_LIBVERSION_AGE}") + set_target_properties( + "${LIB_NAME}_shared" PROPERTIES + OUTPUT_NAME "${LIB_NAME}-${EVENT_PACKAGE_RELEASE}" + VERSION "${CURRENT_MINUS_AGE}.${EVENT_ABI_LIBVERSION_AGE}.${EVENT_ABI_LIBVERSION_REVISION}" + SOVERSION "${CURRENT_MINUS_AGE}") + endif() + set_target_properties( "${LIB_NAME}_shared" PROPERTIES - SOVERSION ${EVENT_ABI_LIBVERSION} - ) + PUBLIC_HEADER "${HDR_PUBLIC}" + CLEAN_DIRECT_OUTPUT 1) + + if (NOT WIN32) + set(LIB_LINK_NAME + "${CMAKE_SHARED_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}") + + add_custom_command(TARGET ${LIB_NAME}_shared + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E create_symlink + "$" + "${LIB_LINK_NAME}" + WORKING_DIRECTORY "lib") + endif() list(APPEND LIBEVENT_SHARED_LIBRARIES "${LIB_NAME}_shared") list(APPEND ADD_EVENT_LIBRARY_TARGETS "${LIB_NAME}_shared") @@ -117,6 +149,12 @@ macro(add_event_library LIB_NAME) PUBLIC_HEADER DESTINATION "include/event2" COMPONENT dev ) + if (NOT WIN32 AND ${EVENT_LIBRARY_SHARED}) + install(FILES + "$/${LIB_LINK_NAME}" + DESTINATION "lib" + COMPONENT lib) + endif() add_library(${LIB_NAME} INTERFACE) target_link_libraries(${LIB_NAME} INTERFACE ${ADD_EVENT_LIBRARY_INTERFACE}) diff --git a/cmake/Uninstall.cmake.in b/cmake/Uninstall.cmake.in new file mode 100644 index 0000000..c6dc09e --- /dev/null +++ b/cmake/Uninstall.cmake.in @@ -0,0 +1,23 @@ +# https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake + +if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") +endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + +file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach(file ${files}) + message(STATUS "Uninstalling $ENV{DESTDIR}${file}") + if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + exec_program( + "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif(NOT "${rm_retval}" STREQUAL 0) + else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") +endforeach(file) diff --git a/cmake/VersionViaGit.cmake b/cmake/VersionViaGit.cmake index 9ac7e30..504980a 100644 --- a/cmake/VersionViaGit.cmake +++ b/cmake/VersionViaGit.cmake @@ -23,8 +23,8 @@ macro(event_fuzzy_version_from_git) # set our defaults. set(EVENT_GIT___VERSION_MAJOR 2) set(EVENT_GIT___VERSION_MINOR 1) - set(EVENT_GIT___VERSION_PATCH 10) - set(EVENT_GIT___VERSION_STAGE "beta") + set(EVENT_GIT___VERSION_PATCH 11) + set(EVENT_GIT___VERSION_STAGE "stable") find_package(Git) diff --git a/configure.ac b/configure.ac index e644034..298d3ab 100644 --- a/configure.ac +++ b/configure.ac @@ -5,8 +5,8 @@ dnl See LICENSE for copying information. dnl dnl Original version Dug Song -AC_INIT(libevent,2.1.10-stable) -AC_PREREQ(2.59) +AC_INIT(libevent,2.1.11-stable) +AC_PREREQ(2.62) AC_CONFIG_SRCDIR(event.c) AC_CONFIG_MACRO_DIR([m4]) @@ -14,7 +14,7 @@ AM_INIT_AUTOMAKE dnl AM_SILENT_RULES req. automake 1.11. [no] defaults V=1 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) AC_CONFIG_HEADERS(config.h evconfig-private.h:evconfig-private.h.in) -AC_DEFINE(NUMERIC_VERSION, 0x02010a00, [Numeric representation of the version]) +AC_DEFINE(NUMERIC_VERSION, 0x02010b00, [Numeric representation of the version]) dnl Initialize prefix. if test "$prefix" = "NONE"; then diff --git a/evdns.c b/evdns.c index 1b81536..de3848a 100644 --- a/evdns.c +++ b/evdns.c @@ -77,6 +77,7 @@ #include #ifdef _WIN32 #include +#include #include #ifndef _WIN32_IE #define _WIN32_IE 0x400 @@ -346,6 +347,9 @@ struct evdns_base { struct timeval global_getaddrinfo_allow_skew; + int so_rcvbuf; + int so_sndbuf; + int getaddrinfo_ipv4_timeouts; int getaddrinfo_ipv6_timeouts; int getaddrinfo_ipv4_answered; @@ -2538,6 +2542,23 @@ evdns_nameserver_add_impl_(struct evdns_base *base, const struct sockaddr *addre } } + if (base->so_rcvbuf) { + if (setsockopt(ns->socket, SOL_SOCKET, SO_RCVBUF, + (void *)&base->so_rcvbuf, sizeof(base->so_rcvbuf))) { + log(EVDNS_LOG_WARN, "Couldn't set SO_RCVBUF to %i", base->so_rcvbuf); + err = -SO_RCVBUF; + goto out2; + } + } + if (base->so_sndbuf) { + if (setsockopt(ns->socket, SOL_SOCKET, SO_SNDBUF, + (void *)&base->so_sndbuf, sizeof(base->so_sndbuf))) { + log(EVDNS_LOG_WARN, "Couldn't set SO_SNDBUF to %i", base->so_sndbuf); + err = -SO_SNDBUF; + goto out2; + } + } + memcpy(&ns->address, address, addrlen); ns->addrlen = addrlen; ns->state = 1; @@ -3531,6 +3552,16 @@ evdns_base_set_option_impl(struct evdns_base *base, val); memcpy(&base->global_nameserver_probe_initial_timeout, &tv, sizeof(tv)); + } else if (str_matches_option(option, "so-rcvbuf:")) { + int buf = strtoint(val); + if (!(flags & DNS_OPTION_MISC)) return 0; + log(EVDNS_LOG_DEBUG, "Setting SO_RCVBUF to %s", val); + base->so_rcvbuf = buf; + } else if (str_matches_option(option, "so-sndbuf:")) { + int buf = strtoint(val); + if (!(flags & DNS_OPTION_MISC)) return 0; + log(EVDNS_LOG_DEBUG, "Setting SO_SNDBUF to %s", val); + base->so_sndbuf = buf; } return 0; } diff --git a/event.c b/event.c index a778f96..b2ad341 100644 --- a/event.c +++ b/event.c @@ -837,8 +837,7 @@ static int event_base_free_queues_(struct event_base *base, int run_finalizers) static void event_base_free_(struct event_base *base, int run_finalizers) { - int i; - size_t n_deleted=0; + int i, n_deleted=0; struct event *ev; /* XXXX grab the lock? If there is contention when one thread frees * the base, then the contending thread will be very sad soon. */ @@ -913,7 +912,7 @@ event_base_free_(struct event_base *base, int run_finalizers) } if (n_deleted) - event_debug(("%s: "EV_SIZE_FMT" events were still set in base", + event_debug(("%s: %d events were still set in base", __func__, n_deleted)); while (LIST_FIRST(&base->once_events)) { @@ -988,6 +987,12 @@ event_reinit(struct event_base *base) EVBASE_ACQUIRE_LOCK(base, th_base_lock); + if (base->running_loop) { + event_warnx("%s: forked from the event_loop.", __func__); + res = -1; + goto done; + } + evsel = base->evsel; /* check if this event mechanism requires reinit on the backend */ @@ -3679,7 +3684,7 @@ event_base_foreach_event_nolock_(struct event_base *base, event_base_foreach_event_cb fn, void *arg) { int r, i; - size_t u; + unsigned u; struct event *ev; /* Start out with all the EVLIST_INSERTED events. */ @@ -3832,7 +3837,7 @@ event_base_active_by_fd(struct event_base *base, evutil_socket_t fd, short event /* If we want to activate timer events, loop and activate each event with * the same fd in both the timeheap and common timeouts list */ int i; - size_t u; + unsigned u; struct event *ev; for (u = 0; u < base->timeheap.n; ++u) { @@ -3962,21 +3967,20 @@ void event_base_assert_ok_nolock_(struct event_base *base) { int i; - size_t u; int count; /* First do checks on the per-fd and per-signal lists */ evmap_check_integrity_(base); /* Check the heap property */ - for (u = 1; u < base->timeheap.n; ++u) { - size_t parent = (u - 1) / 2; + for (i = 1; i < (int)base->timeheap.n; ++i) { + int parent = (i - 1) / 2; struct event *ev, *p_ev; - ev = base->timeheap.p[u]; + ev = base->timeheap.p[i]; p_ev = base->timeheap.p[parent]; EVUTIL_ASSERT(ev->ev_flags & EVLIST_TIMEOUT); EVUTIL_ASSERT(evutil_timercmp(&p_ev->ev_timeout, &ev->ev_timeout, <=)); - EVUTIL_ASSERT(ev->ev_timeout_pos.min_heap_idx == u); + EVUTIL_ASSERT(ev->ev_timeout_pos.min_heap_idx == i); } /* Check that the common timeouts are fine */ diff --git a/evutil.c b/evutil.c index 402ab0d..3412c2a 100644 --- a/evutil.c +++ b/evutil.c @@ -29,6 +29,7 @@ #ifdef _WIN32 #include +#include #include #define WIN32_LEAN_AND_MEAN #include @@ -750,7 +751,7 @@ done: /* Test whether we have an ipv4 interface and an ipv6 interface. Return 0 if * the test seemed successful. */ static int -evutil_check_interfaces(int force_recheck) +evutil_check_interfaces(void) { evutil_socket_t fd = -1; struct sockaddr_in sin, sin_out; @@ -758,9 +759,12 @@ evutil_check_interfaces(int force_recheck) ev_socklen_t sin_out_len = sizeof(sin_out); ev_socklen_t sin6_out_len = sizeof(sin6_out); int r; - if (have_checked_interfaces && !force_recheck) + if (have_checked_interfaces) return 0; + /* From this point on we have done the ipv4/ipv6 interface check */ + have_checked_interfaces = 1; + if (evutil_check_ifaddrs() == 0) { /* Use a nice sane interface, if this system has one. */ return 0; @@ -1228,8 +1232,7 @@ evutil_adjust_hints_for_addrconfig_(struct evutil_addrinfo *hints) return; if (hints->ai_family != PF_UNSPEC) return; - if (!have_checked_interfaces) - evutil_check_interfaces(0); + evutil_check_interfaces(); if (had_ipv4_address && !had_ipv6_address) { hints->ai_family = PF_INET; } else if (!had_ipv4_address && had_ipv6_address) { diff --git a/include/event2/buffer_compat.h b/include/event2/buffer_compat.h index 24f828c..0ce1025 100644 --- a/include/event2/buffer_compat.h +++ b/include/event2/buffer_compat.h @@ -90,9 +90,10 @@ typedef void (*evbuffer_cb)(struct evbuffer *buffer, size_t old_len, size_t new_ @param cb the callback function to invoke when the evbuffer is modified, or NULL to remove all callbacks. @param cbarg an argument to be provided to the callback function + @return 0 if successful, or -1 on error */ EVENT2_EXPORT_SYMBOL -void evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg); +int evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg); /** diff --git a/include/event2/bufferevent.h b/include/event2/bufferevent.h index dac34dc..48cd153 100644 --- a/include/event2/bufferevent.h +++ b/include/event2/bufferevent.h @@ -491,7 +491,7 @@ short bufferevent_get_enabled(struct bufferevent *bufev); (In other words, if reading or writing is disabled, or if the bufferevent's read or write operation has been suspended because - there's no data to write, or not enough banwidth, or so on, the + there's no data to write, or not enough bandwidth, or so on, the timeout isn't active. The timeout only becomes active when we we're willing to actually read or write.) @@ -569,7 +569,7 @@ void bufferevent_unlock(struct bufferevent *bufev); /** * Public interface to manually increase the reference count of a bufferevent * this is useful in situations where a user may reference the bufferevent - * somewhere eles (unknown to libevent) + * somewhere else (unknown to libevent) * * @param bufev the bufferevent to increase the refcount on * @@ -802,7 +802,7 @@ void ev_token_bucket_cfg_free(struct ev_token_bucket_cfg *cfg); They are: socket-based bufferevents (normal and IOCP-based), and SSL-based bufferevents. - Return 0 on sucess, -1 on failure. + Return 0 on success, -1 on failure. */ EVENT2_EXPORT_SYMBOL int bufferevent_set_rate_limit(struct bufferevent *bev, @@ -853,7 +853,7 @@ int bufferevent_rate_limit_group_set_cfg( The default min-share is currently 64 bytes. - Returns 0 on success, -1 on faulre. + Returns 0 on success, -1 on failure. */ EVENT2_EXPORT_SYMBOL int bufferevent_rate_limit_group_set_min_share( diff --git a/include/event2/dns.h b/include/event2/dns.h index 3c548a1..13ce027 100644 --- a/include/event2/dns.h +++ b/include/event2/dns.h @@ -455,7 +455,8 @@ void evdns_cancel_request(struct evdns_base *base, struct evdns_request *req); The currently available configuration options are: ndots, timeout, max-timeouts, max-inflight, attempts, randomize-case, - bind-to, initial-probe-timeout, getaddrinfo-allow-skew. + bind-to, initial-probe-timeout, getaddrinfo-allow-skew, + so-rcvbuf, so-sndbuf. In versions before Libevent 2.0.3-alpha, the option name needed to end with a colon. diff --git a/include/event2/event.h b/include/event2/event.h index ff20851..a6b6144 100644 --- a/include/event2/event.h +++ b/include/event2/event.h @@ -285,7 +285,7 @@ struct event * There are many options that can be used to alter the behavior and * implementation of an event_base. To avoid having to pass them all in a * complex many-argument constructor, we provide an abstract data type - * where you set up configation information before passing it to + * where you set up configuration information before passing it to * event_base_new_with_config(). * * @see event_config_new(), event_config_free(), event_base_new_with_config(), @@ -632,7 +632,7 @@ int event_config_set_num_cpus_hint(struct event_config *cfg, int cpus); /** * Record an interval and/or a number of callbacks after which the event base * should check for new events. By default, the event base will run as many - * events are as activated at the higest activated priority before checking + * events are as activated at the highest activated priority before checking * for new events. If you configure it by setting max_interval, it will check * the time after each callback, and not allow more than max_interval to * elapse before checking for new events. If you configure it by setting @@ -1321,7 +1321,7 @@ struct event *event_base_get_running_event(struct event_base *base); The event_initialized() function can be used to check if an event has been initialized. - Warning: This function is only useful for distinguishing a a zeroed-out + Warning: This function is only useful for distinguishing a zeroed-out piece of memory from an initialized event, it can easily be confused by uninitialized memory. Thus, it should ONLY be used to distinguish an initialized event from zero. diff --git a/include/event2/event_struct.h b/include/event2/event_struct.h index 35c5170..1c8b71b 100644 --- a/include/event2/event_struct.h +++ b/include/event2/event_struct.h @@ -126,7 +126,7 @@ struct event { /* for managing timeouts */ union { TAILQ_ENTRY(event) ev_next_with_common_timeout; - size_t min_heap_idx; + int min_heap_idx; } ev_timeout_pos; evutil_socket_t ev_fd; diff --git a/include/include.am b/include/include.am index 9aad2db..aaa2042 100644 --- a/include/include.am +++ b/include/include.am @@ -1,4 +1,4 @@ -# include/Makefile.am for libevent +# include/include.am for libevent # Copyright 2000-2007 Niels Provos # Copyright 2007-2012 Niels Provos and Nick Mathewson # @@ -11,7 +11,6 @@ EVENT2_EXPORT = \ include/event2/buffer_compat.h \ include/event2/bufferevent.h \ include/event2/bufferevent_compat.h \ - include/event2/bufferevent_ssl.h \ include/event2/bufferevent_struct.h \ include/event2/dns.h \ include/event2/dns_compat.h \ @@ -33,6 +32,10 @@ EVENT2_EXPORT = \ include/event2/util.h \ include/event2/visibility.h +if OPENSSL +EVENT2_EXPORT += include/event2/bufferevent_ssl.h +endif + ## Without the nobase_ prefixing, Automake would strip "include/event2/" from ## the source header filename to derive the installed header filename. ## With nobase_ the installed path is $(includedir)/include/event2/ev*.h. diff --git a/listener.c b/listener.c index 387a89e..f5c00c9 100644 --- a/listener.c +++ b/listener.c @@ -35,6 +35,7 @@ #define _WIN32_WINNT 0x0403 #endif #include +#include #include #include #endif diff --git a/m4/libevent_openssl.m4 b/m4/libevent_openssl.m4 index 7b45813..1981198 100644 --- a/m4/libevent_openssl.m4 +++ b/m4/libevent_openssl.m4 @@ -40,7 +40,7 @@ case "$enable_openssl" in ;; esac CPPFLAGS_SAVE=$CPPFLAGS - CPPFLAGS+=$OPENSSL_INCS + CPPFLAGS="$CPPFLAGS $OPENSSL_INCS" AC_CHECK_HEADERS([openssl/ssl.h], [], [have_openssl=no]) CPPFLAGS=$CPPFLAGS_SAVE AC_SUBST(OPENSSL_INCS) diff --git a/minheap-internal.h b/minheap-internal.h index 858e7eb..b3a0eb1 100644 --- a/minheap-internal.h +++ b/minheap-internal.h @@ -39,7 +39,7 @@ typedef struct min_heap { struct event** p; - size_t n, a; + unsigned n, a; } min_heap_t; static inline void min_heap_ctor_(min_heap_t* s); @@ -47,30 +47,30 @@ static inline void min_heap_dtor_(min_heap_t* s); static inline void min_heap_elem_init_(struct event* e); static inline int min_heap_elt_is_top_(const struct event *e); static inline int min_heap_empty_(min_heap_t* s); -static inline size_t min_heap_size_(min_heap_t* s); +static inline unsigned min_heap_size_(min_heap_t* s); static inline struct event* min_heap_top_(min_heap_t* s); -static inline int min_heap_reserve_(min_heap_t* s, size_t n); +static inline int min_heap_reserve_(min_heap_t* s, unsigned n); static inline int min_heap_push_(min_heap_t* s, struct event* e); static inline struct event* min_heap_pop_(min_heap_t* s); static inline int min_heap_adjust_(min_heap_t *s, struct event* e); static inline int min_heap_erase_(min_heap_t* s, struct event* e); -static inline void min_heap_shift_up_(min_heap_t* s, size_t hole_index, struct event* e); -static inline void min_heap_shift_up_unconditional_(min_heap_t* s, size_t hole_index, struct event* e); -static inline void min_heap_shift_down_(min_heap_t* s, size_t hole_index, struct event* e); +static inline void min_heap_shift_up_(min_heap_t* s, unsigned hole_index, struct event* e); +static inline void min_heap_shift_up_unconditional_(min_heap_t* s, unsigned hole_index, struct event* e); +static inline void min_heap_shift_down_(min_heap_t* s, unsigned hole_index, struct event* e); #define min_heap_elem_greater(a, b) \ (evutil_timercmp(&(a)->ev_timeout, &(b)->ev_timeout, >)) void min_heap_ctor_(min_heap_t* s) { s->p = 0; s->n = 0; s->a = 0; } void min_heap_dtor_(min_heap_t* s) { if (s->p) mm_free(s->p); } -void min_heap_elem_init_(struct event* e) { e->ev_timeout_pos.min_heap_idx = EV_SIZE_MAX; } -int min_heap_empty_(min_heap_t* s) { return 0 == s->n; } -size_t min_heap_size_(min_heap_t* s) { return s->n; } +void min_heap_elem_init_(struct event* e) { e->ev_timeout_pos.min_heap_idx = -1; } +int min_heap_empty_(min_heap_t* s) { return 0u == s->n; } +unsigned min_heap_size_(min_heap_t* s) { return s->n; } struct event* min_heap_top_(min_heap_t* s) { return s->n ? *s->p : 0; } int min_heap_push_(min_heap_t* s, struct event* e) { - if (min_heap_reserve_(s, s->n + 1)) + if (s->n == UINT32_MAX || min_heap_reserve_(s, s->n + 1)) return -1; min_heap_shift_up_(s, s->n++, e); return 0; @@ -81,8 +81,8 @@ struct event* min_heap_pop_(min_heap_t* s) if (s->n) { struct event* e = *s->p; - min_heap_shift_down_(s, 0, s->p[--s->n]); - e->ev_timeout_pos.min_heap_idx = EV_SIZE_MAX; + min_heap_shift_down_(s, 0u, s->p[--s->n]); + e->ev_timeout_pos.min_heap_idx = -1; return e; } return 0; @@ -95,10 +95,10 @@ int min_heap_elt_is_top_(const struct event *e) int min_heap_erase_(min_heap_t* s, struct event* e) { - if (EV_SIZE_MAX != e->ev_timeout_pos.min_heap_idx) + if (-1 != e->ev_timeout_pos.min_heap_idx) { struct event *last = s->p[--s->n]; - size_t parent = (e->ev_timeout_pos.min_heap_idx - 1) / 2; + unsigned parent = (e->ev_timeout_pos.min_heap_idx - 1) / 2; /* we replace e with the last element in the heap. We might need to shift it upward if it is less than its parent, or downward if it is greater than one or both its children. Since the children are known @@ -108,7 +108,7 @@ int min_heap_erase_(min_heap_t* s, struct event* e) min_heap_shift_up_unconditional_(s, e->ev_timeout_pos.min_heap_idx, last); else min_heap_shift_down_(s, e->ev_timeout_pos.min_heap_idx, last); - e->ev_timeout_pos.min_heap_idx = EV_SIZE_MAX; + e->ev_timeout_pos.min_heap_idx = -1; return 0; } return -1; @@ -116,10 +116,10 @@ int min_heap_erase_(min_heap_t* s, struct event* e) int min_heap_adjust_(min_heap_t *s, struct event *e) { - if (EV_SIZE_MAX == e->ev_timeout_pos.min_heap_idx) { + if (-1 == e->ev_timeout_pos.min_heap_idx) { return min_heap_push_(s, e); } else { - size_t parent = (e->ev_timeout_pos.min_heap_idx - 1) / 2; + unsigned parent = (e->ev_timeout_pos.min_heap_idx - 1) / 2; /* The position of e has changed; we shift it up or down * as needed. We can't need to do both. */ if (e->ev_timeout_pos.min_heap_idx > 0 && min_heap_elem_greater(s->p[parent], e)) @@ -130,14 +130,18 @@ int min_heap_adjust_(min_heap_t *s, struct event *e) } } -int min_heap_reserve_(min_heap_t* s, size_t n) +int min_heap_reserve_(min_heap_t* s, unsigned n) { if (s->a < n) { struct event** p; - size_t a = s->a ? s->a * 2 : 8; + unsigned a = s->a ? s->a * 2 : 8; if (a < n) a = n; +#if (SIZE_MAX == UINT32_MAX) + if (a > SIZE_MAX / sizeof *p) + return -1; +#endif if (!(p = (struct event**)mm_realloc(s->p, a * sizeof *p))) return -1; s->p = p; @@ -146,9 +150,9 @@ int min_heap_reserve_(min_heap_t* s, size_t n) return 0; } -void min_heap_shift_up_unconditional_(min_heap_t* s, size_t hole_index, struct event* e) +void min_heap_shift_up_unconditional_(min_heap_t* s, unsigned hole_index, struct event* e) { - size_t parent = (hole_index - 1) / 2; + unsigned parent = (hole_index - 1) / 2; do { (s->p[hole_index] = s->p[parent])->ev_timeout_pos.min_heap_idx = hole_index; @@ -158,9 +162,9 @@ void min_heap_shift_up_unconditional_(min_heap_t* s, size_t hole_index, struct e (s->p[hole_index] = e)->ev_timeout_pos.min_heap_idx = hole_index; } -void min_heap_shift_up_(min_heap_t* s, size_t hole_index, struct event* e) +void min_heap_shift_up_(min_heap_t* s, unsigned hole_index, struct event* e) { - size_t parent = (hole_index - 1) / 2; + unsigned parent = (hole_index - 1) / 2; while (hole_index && min_heap_elem_greater(s->p[parent], e)) { (s->p[hole_index] = s->p[parent])->ev_timeout_pos.min_heap_idx = hole_index; @@ -170,9 +174,9 @@ void min_heap_shift_up_(min_heap_t* s, size_t hole_index, struct event* e) (s->p[hole_index] = e)->ev_timeout_pos.min_heap_idx = hole_index; } -void min_heap_shift_down_(min_heap_t* s, size_t hole_index, struct event* e) +void min_heap_shift_down_(min_heap_t* s, unsigned hole_index, struct event* e) { - size_t min_child = 2 * (hole_index + 1); + unsigned min_child = 2 * (hole_index + 1); while (min_child <= s->n) { min_child -= min_child == s->n || min_heap_elem_greater(s->p[min_child], s->p[min_child - 1]); diff --git a/sample/https-client.c b/sample/https-client.c index 5869974..58e449b 100644 --- a/sample/https-client.c +++ b/sample/https-client.c @@ -53,7 +53,7 @@ http_request_done(struct evhttp_request *req, void *ctx) char buffer[256]; int nread; - if (req == NULL) { + if (!req || !evhttp_request_get_response_code(req)) { /* If req is NULL, it means an error occurred, but * sadly we are mostly left guessing what the error * might have been. We'll do our best... */ diff --git a/test/regress_buffer.c b/test/regress_buffer.c index 02d557b..8ac4b6e 100644 --- a/test/regress_buffer.c +++ b/test/regress_buffer.c @@ -1956,12 +1956,12 @@ test_evbuffer_callbacks(void *ptr) tt_assert(cb1 != NULL); cb2 = evbuffer_add_cb(buf, log_change_callback, buf_out2); tt_assert(cb2 != NULL); - evbuffer_setcb(buf, self_draining_callback, NULL); + tt_int_op(evbuffer_setcb(buf, self_draining_callback, NULL), ==, 0); evbuffer_add_printf(buf, "This should get drained right away."); tt_uint_op(evbuffer_get_length(buf), ==, 0); tt_uint_op(evbuffer_get_length(buf_out1), ==, 0); tt_uint_op(evbuffer_get_length(buf_out2), ==, 0); - evbuffer_setcb(buf, NULL, NULL); + tt_int_op(evbuffer_setcb(buf, NULL, NULL), ==, 0); evbuffer_add_printf(buf, "This will not."); tt_str_op((const char *) evbuffer_pullup(buf, -1), ==, "This will not."); evbuffer_validate(buf); @@ -1987,6 +1987,14 @@ test_evbuffer_callbacks(void *ptr) "0->15; 15->11; 11->0; "); #endif + /* the next call to readline should fail */ +#ifndef EVENT__DISABLE_MM_REPLACEMENT + event_set_mem_functions(failing_malloc, realloc, free); + tt_int_op(evbuffer_setcb(buf, self_draining_callback, NULL), ==, -1); + evbuffer_validate(buf); + event_set_mem_functions(malloc, realloc, free); +#endif + end: if (buf) evbuffer_free(buf); diff --git a/test/regress_dns.c b/test/regress_dns.c index 76b0b86..d2084b7 100644 --- a/test/regress_dns.c +++ b/test/regress_dns.c @@ -2352,6 +2352,26 @@ end: } #endif +static void +test_set_so_rcvbuf_so_sndbuf(void *arg) +{ + struct basic_test_data *data = arg; + struct evdns_base *dns_base; + + dns_base = evdns_base_new(data->base, 0); + tt_assert(dns_base); + + tt_assert(!evdns_base_set_option(dns_base, "so-rcvbuf", "10240")); + tt_assert(!evdns_base_set_option(dns_base, "so-sndbuf", "10240")); + + /* actually check SO_RCVBUF/SO_SNDBUF not fails */ + tt_assert(!evdns_base_nameserver_ip_add(dns_base, "127.0.0.1")); + +end: + if (dns_base) + evdns_base_free(dns_base, 0); +} + #define DNS_LEGACY(name, flags) \ { #name, run_legacy_test_fn, flags|TT_LEGACY, &legacy_setup, \ dns_##name } @@ -2421,6 +2441,9 @@ struct testcase_t dns_testcases[] = { TT_FORK|TT_OFF_BY_DEFAULT, NULL, NULL }, #endif + { "set_SO_RCVBUF_SO_SNDBUF", test_set_so_rcvbuf_so_sndbuf, + TT_FORK|TT_NEED_BASE, &basic_setup, NULL }, + END_OF_TESTCASES }; diff --git a/util-internal.h b/util-internal.h index b727bf1..39576c7 100644 --- a/util-internal.h +++ b/util-internal.h @@ -52,16 +52,22 @@ extern "C" { /* __has_attribute() wrapper */ #ifdef __has_attribute -#define EVUTIL_HAS_ATTRIBUTE __has_attribute +# define EVUTIL_HAS_ATTRIBUTE __has_attribute #endif /** clang 3 __has_attribute misbehaves in some versions */ -#if defined(__clang__) && \ - __clang__ == 1 && __clang_major__ == 3 && \ - (__clang_minor__ >= 2 && __clang_minor__ <= 5) -#undef EVUTIL_HAS_ATTRIBUTE -#endif +#if defined(__clang__) && __clang__ == 1 +# if defined(__apple_build_version__) +# if __clang_major__ <= 6 +# undef EVUTIL_HAS_ATTRIBUTE +# endif +# else /* !__apple_build_version__ */ +# if __clang_major__ == 3 && __clang_minor__ >= 2 && __clang_minor__ <= 5 +# undef EVUTIL_HAS_ATTRIBUTE +# endif +# endif /* __apple_build_version__ */ +#endif /*\ defined(__clang__) && __clang__ == 1 */ #ifndef EVUTIL_HAS_ATTRIBUTE -#define EVUTIL_HAS_ATTRIBUTE(x) 0 +# define EVUTIL_HAS_ATTRIBUTE(x) 0 #endif /* If we need magic to say "inline", get it for free internally. */ -- 2.7.4