]> granicus.if.org Git - libevent/log
libevent
5 years agoChange the minimum version of automake to 1.13 and autoconf to 2.67
ygj6 [Thu, 8 Aug 2019 13:48:21 +0000 (21:48 +0800)]
Change the minimum version of automake to 1.13 and autoconf to 2.67

When I run make check via automake with a version of 1.12.6 or lower, I got this error:

    /bin/sh: line 9: ./test_runner_epoll: No such file or directory
    FAIL: test_runner_epoll
    /bin/sh: line 9: ./test_runner_select: No such file or directory
    FAIL: test_runner_select
    /bin/sh: line 9: ./test_runner_kqueue: No such file or directory
    FAIL: test_runner_kqueue
    /bin/sh: line 9: ./test_runner_evport: No such file or directory
    FAIL: test_runner_evport
    /bin/sh: line 9: ./test_runner_devpoll: No such file or directory
    FAIL: test_runner_devpoll
    /bin/sh: line 9: ./test_runner_poll: No such file or directory
    FAIL: test_runner_poll
    /bin/sh: line 9: ./test_runner_win32: No such file or directory
    FAIL: test_runner_win32
    /bin/sh: line 9: ./test_runner_timerfd: No such file or directory
    FAIL: test_runner_timerfd
    /bin/sh: line 9: ./test_runner_changelist: No such file or directory
    FAIL: test_runner_changelist
    /bin/sh: line 9: ./test_runner_timerfd_changelist: No such file or directory
    FAIL: test_runner_timerfd_changelist

Open the Makefile generated by command ./autogen.sh && ./configure
I can see the errors are caused by this line:

    if $(TESTS_ENVIRONMENT) $${dir}$$tst $(AM_TESTS_FD_REDIRECT); then

$${dir}$$tst will expand to ./test_runner_epoll, but test_runner_epoll is only a target in test/include.am,
not a file, so it print:

    /bin/sh: line 9: ./test_runner_epoll: No such file or directory.

It seems like a bug in automake 1.12.6.
The errors will disappear if I simply upgrade automake to 1.13, and upgrade autoconf to 2.65
(2.65 is the lowest version dependent by automake-1.13).

When I build with automake-1.13 and autoconf-2.66, I got another error:

    configure.ac:667: error: AC_CHECK_SIZEOF: requires literal arguments

The code in configure.ac line 667 is :

    AC_CHECK_SIZEOF(void *)

It is a bug in autoconf-2.66 :
http://gnu-autoconf.7623.n7.nabble.com/AC-CHECK-SIZEOF-int-is-error-in-autoconf-2-66-td13537.html

Finally, everything works fine when using automake-1.13 and autoconf-2.67.
Refs: #858

5 years agoAdd Uninstall.cmake.in into dist archive
Azat Khuzhin [Sat, 3 Aug 2019 11:32:21 +0000 (14:32 +0300)]
Add Uninstall.cmake.in into dist archive

Fixes: #863
5 years agobuffer: fix possible NULL dereference in evbuffer_setcb() on ENOMEM
Azat Khuzhin [Wed, 31 Jul 2019 07:34:38 +0000 (10:34 +0300)]
buffer: fix possible NULL dereference in evbuffer_setcb() on ENOMEM

[ @azat:

  - add return heredoc for evbuffer_setcb()
  - add unit test with event_set_mem_functions()
  - look through the report from abi-compliance-checker/abi-dumper
]

Closes: #855
5 years agoChange autoconf version to 2.62 and automake version to 1.11.2
yuangongji [Sat, 27 Jul 2019 14:41:39 +0000 (22:41 +0800)]
Change autoconf version to 2.62 and automake version to 1.11.2

On my computer, the version of autoconf is 2.59 and automake is 1.9
I build with autogen.sh & configure & make and failed.

I find In Makefile.am:
    include/event2/event-config.h: config.h make-event-config.sed
        $(AM_V_GEN)test -d include/event2 || $(MKDIR_P) include/event2
        $(AM_V_at)$(SED) -f $(srcdir)/make-event-config.sed < config.h > $@T
        $(AM_V_at)mv -f $@T $@

There are three undefined variables: MKDIR_P, AM_V_GEN and AM_V_at.
Then I tried:
- autoconf-2.60 / automake-1.10
- autoconf-2.61 / automake-1.11
- autoconf-2.62 / automake-1.11.2

And only autoconf-2.62 & automake-1.11.2 is ok.

Therefore, I recommend changing the autoconf version from 2.59 to 2.62
and automake version from 1.9 to 1.11.2.

Plus autoconf 2.59 is too old - 2003.12.16 [1], so as automake 1.9 -
2004.08.11 [2], while $(AM_V_GEN)/$(AM_V_at) had been introduced in
371a1237 back in 2012.

  [1]: http://ftp.gnu.org/gnu/autoconf/
  [1]: http://ftp.gnu.org/gnu/automake/

Fixes: 371a1237 ("Make quiet build even quieter")
5 years agocmake: install shared library only if it was requested
Azat Khuzhin [Thu, 11 Jul 2019 21:00:12 +0000 (00:00 +0300)]
cmake: install shared library only if it was requested

  $ cmake -DEVENT__LIBRARY_TYPE=static ..
  ...
  CMake Error:
  Error evaluating generator expression:

    $<TARGET_FILE_DIR:event_core_shared>

  No target "event_core_shared"

Fixes: #853
Fixes: 669a53f3 ("cmake: set library names to be the same as with autotools")
5 years agoMissing <winerror.h> on win7/MinGW(MINGW32_NT-6.1)/MSYS
yuangongji [Tue, 2 Jul 2019 16:27:22 +0000 (00:27 +0800)]
Missing <winerror.h> on win7/MinGW(MINGW32_NT-6.1)/MSYS

5 years agocmake: set library names to be the same as with autotools
yuangongji [Tue, 9 Jul 2019 16:30:12 +0000 (00:30 +0800)]
cmake: set library names to be the same as with autotools

libtool has VERSION_INFO [1], cmake has SOVERSION/VERSION instead
(although it has different format). Also libtool has RELEASE [2] while
cmake do not have analog yet [3], hence manual symlinks should be
created.

  [1]: https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
  [2]: https://www.gnu.org/software/libtool/manual/html_node/Release-numbers.html
  [3]: https://gitlab.kitware.com/cmake/cmake/issues/17652

Plus osx has compatibility_version/current_version dylib properties and
cmake do not have separate properties for them [4], hence manual LINK_FLAGS.
And also there INSTALL_NAME_DIR property which should be adjusted too.

  [4]: https://public.kitware.com/Bug/view.php?id=4383

So after all changes, here is an example before/after for osx and linux:

  # osx
    # autotools
    .libs/libevent_pthreads-2.2.1.dylib
    .libs/libevent_pthreads.dylib -> libevent_pthreads-2.2.1.dylib
    /usr/local/lib/libevent_pthreads-2.2.1.dylib (compatibility version 2.0.0, current version 2.0.0)
    # cmake
      # before patch
      lib/libevent_pthreads.2.2.0.dylib
      lib/libevent_pthreads.dylib -> libevent_pthreads.2.2.0.dylib
      @rpath/libevent_pthreads.2.2.0.dylib (compatibility version 2.2.0, current version 0.0.0)
      # after patch
      lib/libevent_pthreads-2.2.1.dylib
      lib/libevent_pthreads.dylib -> libevent_pthreads-2.2.1.dylib
      /vagrant/.cmake/inst/lib/libevent_pthreads-2.2.1.dylib (compatibility version 2.0.0, current version 2.0.0)

  # linux
    # autotools
    .libs/libevent_pthreads-2.2.so.1 -> libevent_pthreads-2.2.so.1.0.0
    .libs/libevent_pthreads-2.2.so.1.0.0
    .libs/libevent_pthreads.so -> libevent_pthreads-2.2.so.1.0.0
    # cmake
      # before patch
      lib/libevent_pthreads.so -> libevent_pthreads.so.2.2.0
      lib/libevent_pthreads.so.2.2.0
      # after patch
      lib/libevent_pthreads-2.2.so -> libevent_pthreads-2.2.so.1
      lib/libevent_pthreads-2.2.so.1 -> libevent_pthreads-2.2.so.1.0.0
      lib/libevent_pthreads-2.2.so.1.0.0
      lib/libevent_pthreads.so -> libevent_pthreads-2.2.so.1.0.0

Closes: #838 (cherry-picked)
Closes: #760
5 years agoEnable _GNU_SOURCE for Android
Keith Smiley [Mon, 8 Jul 2019 21:06:55 +0000 (14:06 -0700)]
Enable _GNU_SOURCE for Android

When targeting the Android NDK _GNU_SOURCE is not enabled by default:

```
 /*
  * With bionic, you always get all C and POSIX API.
  *
  * If you want BSD and/or GNU extensions, _BSD_SOURCE and/or _GNU_SOURCE are
  * expected to be defined by callers before *any* standard header file is
  * included.
  *
  * In our header files we test against __USE_BSD and __USE_GNU.
  */
 #if defined(_GNU_SOURCE)
 #  define __USE_BSD 1
 #  define __USE_GNU 1
 #endif
```

Because of this `pipe2` is not available:

```
 #if defined(__USE_GNU)
 int pipe2(int __fds[2], int __flags) __INTRODUCED_IN(9);
 #endif
```

The function used to check if it does exist:

```
CHECK_FUNCTION_EXISTS_EX(pipe2 EVENT__HAVE_PIPE2)
```

Just check that the _linking_ succeeds, which it does, it's just not
visible in the import, leading to a warning (or error):

```
evutil.c:2637:6: error: implicit declaration of function 'pipe2' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        if (pipe2(fd, O_NONBLOCK|O_CLOEXEC) == 0)
            ^
```

When targeting the NDK it should be safe to always opt into this. Clang
would pass the right flag for us automatically _if_ the source was C++
instead of C.

5 years agoEnable kqueue for APPLE targets
Keith Smiley [Tue, 2 Jul 2019 17:47:47 +0000 (10:47 -0700)]
Enable kqueue for APPLE targets

The CMAKE_CROSSCOMPILING variable is not set for Apple targets seemingly
because of cmake implementation details (more info
https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING.html).
Since Apple targets have working kqueue implementations this check makes
sure we enable it always when those are the targets, without users
having to explicitly set EVENT__HAVE_WORKING_KQUEUE

5 years agoWarn if forked from the event loop during event_reinit()
Azat Khuzhin [Mon, 1 Jul 2019 20:54:02 +0000 (23:54 +0300)]
Warn if forked from the event loop during event_reinit()

Calling fork() from the event loop is not a great idea, since at least
it shares some internal pipes (for handling signals) before
event_reinit() call

Closes: #833
5 years agoautotools: do not install bufferevent_ssl.h under --disable-openssl
Azat Khuzhin [Wed, 26 Jun 2019 06:36:49 +0000 (09:36 +0300)]
autotools: do not install bufferevent_ssl.h under --disable-openssl

Refs: https://github.com/libevent/libevent/issues/760#issuecomment-502345788

5 years agocmake: link against shell32.lib/advapi32.lib
Azat Khuzhin [Tue, 25 Jun 2019 22:27:20 +0000 (01:27 +0300)]
cmake: link against shell32.lib/advapi32.lib

Fixes: #844
Refs: #760 (cmake-vs-autotools)

5 years agoAdd README.md/Documentation into dist archive
Azat Khuzhin [Tue, 25 Jun 2019 22:20:53 +0000 (01:20 +0300)]
Add README.md/Documentation into dist archive

Fixes: #841
5 years agoRequire cmake >= 3.1.2 (for correct openssl 1.0.2 detection)
Azat Khuzhin [Tue, 25 Jun 2019 21:59:41 +0000 (00:59 +0300)]
Require cmake >= 3.1.2 (for correct openssl 1.0.2 detection)

@ygj6 reported:
  "My platform is MacOS 10.13.5, This problem only happens on Mac.

   As written in the file CMakeLists.txt, the minimum required version of cmake is 3.1:
     cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
   So I built this project with cmake-3.1.0, but I got the following errors:

       CMake Error at /usr/local/cmake-3.1.0/share/cmake/Modules/FindOpenSSL.cmake:293 (list):
         list GET given empty list
       Call Stack (most recent call first):
         CMakeLists.txt:824 (find_package)

       CMake Error at /usr/local/cmake-3.1.0/share/cmake/Modules/FindOpenSSL.cmake:294 (list):
         list GET given empty list
       Call Stack (most recent call first):
         CMakeLists.txt:824 (find_package)

       CMake Error at /usr/local/cmake-3.1.0/share/cmake/Modules/FindOpenSSL.cmake:296 (list):
         list GET given empty list
       Call Stack (most recent call first):
         CMakeLists.txt:824 (find_package)

       CMake Error at /usr/local/cmake-3.1.0/share/cmake/Modules/FindOpenSSL.cmake:298 (list):
         list GET given empty list
       Call Stack (most recent call first):
         CMakeLists.txt:824 (find_package)

   I googled this error and got this answer:
     https://bugs.archlinux.org/task/43688

   It is a bug in FindOpenSSL.cmake on cmake-3.1.0 and fixed on cmake-3.1.2 .
   Of course, It was successful when rebuilding with cmake-3.1.2 .
   So I suggest setting the minimum version required for cmake to 3.1.2 or higher.
   "

Closes: #845
Refs: https://github.com/Kitware/CMake/commit/de4ccee75a89519f95fcbcca75abc46577bfefea

5 years agoevdns: add new options -- so-rcvbuf/so-sndbuf
Azat Khuzhin [Sat, 15 Jun 2019 20:18:05 +0000 (23:18 +0300)]
evdns: add new options -- so-rcvbuf/so-sndbuf

This will allow to customize SO_RCVBUF/SO_SNDBUF for nameservers in this
evdns_base, you may want to adjust them if the kernel starts dropping
udp packages.

5 years agoevutil: drop force_check from evutil_check_interfaces() (unused)
Azat Khuzhin [Fri, 14 Jun 2019 21:16:00 +0000 (00:16 +0300)]
evutil: drop force_check from evutil_check_interfaces() (unused)

5 years agoevutil: set the have_checked_interfaces in evutil_check_interfaces()
jeremyerb [Fri, 14 Jun 2019 14:19:51 +0000 (10:19 -0400)]
evutil: set the have_checked_interfaces in evutil_check_interfaces()

Closes: #836 (cherry-picked)
Fixes: #834
5 years agocmake: add missing autotools targets (doxygen, uninstall, event_rpcgen.py)
yuangongji [Sun, 9 Jun 2019 12:15:37 +0000 (20:15 +0800)]
cmake: add missing autotools targets (doxygen, uninstall, event_rpcgen.py)

Close: #832 (cherry-picked)

5 years agom4/libevent_openssl.m4: fix detection of openssl
Fabrice Fontaine [Sat, 8 Jun 2019 21:44:37 +0000 (23:44 +0200)]
m4/libevent_openssl.m4: fix detection of openssl

Since commit 506df426dbeb0187bbd3654bd286b4100628fb16, OPENSSL_INCS is
added to CPPFLAGS without any white space, as a result openssl detection
fails on:
configure:10395: checking openssl/ssl.h usability
configure:10395: /home/fabrice/buildroot-test/buildroot/output/host/bin/riscv32-linux-gcc -c -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os   -Wall -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64-I/home/fabrice/buildroot-test/buildroot/output/host/bin/../riscv32-buildroot-linux-gnu/sysroot/usr/include  conftest.c >&5
<command-line>:0:0: warning: "_FILE_OFFSET_BITS" redefined
<command-line>:0:0: note: this is the location of the previous definition
<command-line>:0:23: error: division by zero in #if

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
5 years agodoc: cmake command on Windows
yuangongji (A) [Mon, 3 Jun 2019 15:22:35 +0000 (23:22 +0800)]
doc: cmake command on Windows

Closes: #825 (cherry-pick)
5 years agobecat: remove extra SSL_CTX options usage [ci skip]
Azat Khuzhin [Sun, 2 Jun 2019 18:51:35 +0000 (21:51 +0300)]
becat: remove extra SSL_CTX options usage [ci skip]

Because:
- this do not affects performance
- this breaks builds for with older openssl

5 years agoFix detection of the __has_attribute() for apple clang [ci skip]
Azat Khuzhin [Sun, 2 Jun 2019 17:20:02 +0000 (20:20 +0300)]
Fix detection of the __has_attribute() for apple clang [ci skip]

Fixes build on the next osx env:
- Mac OS 10.9/clang 600
- Mac OS 10.8/clang 500

Refs: https://github.com/libevent/libevent/issues/447#issuecomment-497908488

5 years agohttps-client: correction error checking
wenyg [Thu, 30 May 2019 09:38:49 +0000 (17:38 +0800)]
https-client: correction error checking

When connecting to a non-existent HTTPS service, the "req" is not null
but the "evhttp_request_get_response_code(req)" is zero.

Closes: #822 (cherry-picked)
5 years agotypo error in header file
yuangongji [Thu, 30 May 2019 18:12:55 +0000 (02:12 +0800)]
typo error in header file

5 years agocmake: limit MSVC to Clang-CL
Jan Beich [Tue, 28 May 2019 12:45:59 +0000 (12:45 +0000)]
cmake: limit MSVC to Clang-CL

5 years agohttp: do not name variable "sun" since this breaks solaris builds
Azat Khuzhin [Sat, 25 May 2019 20:41:38 +0000 (23:41 +0300)]
http: do not name variable "sun" since this breaks solaris builds

  -bash-3.2$ /opt/csw/bin/gcc -xc /dev/null -dM -E | grep '#define sun'
  #define sun 1

5 years agotest: mark bev_connect_hostname() as static (to avoid prototype requirement)
Azat Khuzhin [Sat, 25 May 2019 14:29:25 +0000 (17:29 +0300)]
test: mark bev_connect_hostname() as static (to avoid prototype requirement)

5 years agocmake: add -Wmissing-prototypes (like autotools has)
Azat Khuzhin [Sat, 25 May 2019 14:28:53 +0000 (17:28 +0300)]
cmake: add -Wmissing-prototypes (like autotools has)

5 years agotime-test: disable buffering (mostly for windows)
Azat Khuzhin [Tue, 21 May 2019 07:59:05 +0000 (10:59 +0300)]
time-test: disable buffering (mostly for windows)

5 years agoMerge branch 'evbuffer-fixes-806-v2'
Azat Khuzhin [Thu, 16 May 2019 07:25:50 +0000 (10:25 +0300)]
Merge branch 'evbuffer-fixes-806-v2'

* evbuffer-fixes-806-v2:
  evbuffer: fix last_with_datap after prepend with empty chain
  test: regression for evbuffer_expand_fast_() with invalid last_with_datap
  test: cover adjusting of last_with_datap in evbuffer_prepend()

Fixes: #806
5 years agoevbuffer: fix last_with_datap after prepend with empty chain
Azat Khuzhin [Fri, 10 May 2019 21:17:03 +0000 (00:17 +0300)]
evbuffer: fix last_with_datap after prepend with empty chain

last_with_datap should be adjusted only if it buf->first *was* not
empty, otherwise last_with_datap should point to the prepended chain.

5 years agotest: regression for evbuffer_expand_fast_() with invalid last_with_datap
Azat Khuzhin [Thu, 16 May 2019 06:42:41 +0000 (09:42 +0300)]
test: regression for evbuffer_expand_fast_() with invalid last_with_datap

Before the fix:
  $ regress --no-fork evbuffer/reserve_invalid_last_with_datap
  evbuffer/empty_chain_expand: [err] ../buffer.c:2138: Assertion chain == buf->first failed in evbuffer_expand_fast_
  Aborted (core dumped)

This is the a shorter version of test from the #806 (with some
comments).

5 years agotest: cover adjusting of last_with_datap in evbuffer_prepend()
Azat Khuzhin [Thu, 16 May 2019 06:50:43 +0000 (09:50 +0300)]
test: cover adjusting of last_with_datap in evbuffer_prepend()

Before the fix:
  $ regress evbuffer/empty_reference_prepend..
  evbuffer/empty_reference_prepend: [forking]
    FAIL ../test/regress_buffer.c:104: assert(chain == buf->first)
    FAIL ../test/regress_buffer.c:2291: Buffer format invalid
    [empty_reference_prepend FAILED]
  evbuffer/empty_reference_prepend_buffer: [forking] OK
  1/2 TESTS FAILED. (0 skipped)

5 years agoAdd getopt into dist archive
Azat Khuzhin [Wed, 15 May 2019 18:29:03 +0000 (21:29 +0300)]
Add getopt into dist archive

Fixes: #815
5 years agoImplement bufferevent_socket_connect_hostname_hints()
Joseph Spadavecchia [Mon, 8 Dec 2014 17:32:07 +0000 (17:32 +0000)]
Implement bufferevent_socket_connect_hostname_hints()

So that ai_flags (such as AI_ADDRCONFIG) can be specified.

Closes: #193 (cherry-picked with conflicts resolved)
5 years agoMerge branch 'issue-807-accept4-getnameinfo-AF_UNIX'
Azat Khuzhin [Sun, 12 May 2019 16:06:43 +0000 (19:06 +0300)]
Merge branch 'issue-807-accept4-getnameinfo-AF_UNIX'

* issue-807-accept4-getnameinfo-AF_UNIX:
  http-server: add usage/help dialog
  http: avoid use of uninitialized value for AF_UNIX/AF_LOCAL sockaddr
  http-server: add ability to bind to unix-socket
  build: struct sockaddr_un detection (sys/un.h, afunix.h)

Fixes: #807
5 years agohttp-server: add usage/help dialog
Azat Khuzhin [Sun, 12 May 2019 15:25:37 +0000 (18:25 +0300)]
http-server: add usage/help dialog

5 years agohttp: avoid use of uninitialized value for AF_UNIX/AF_LOCAL sockaddr
Azat Khuzhin [Sun, 12 May 2019 12:19:31 +0000 (15:19 +0300)]
http: avoid use of uninitialized value for AF_UNIX/AF_LOCAL sockaddr

unixsock peer does not have sun_path initialized.

5 years agohttp-server: add ability to bind to unix-socket
Azat Khuzhin [Sat, 11 May 2019 15:49:28 +0000 (18:49 +0300)]
http-server: add ability to bind to unix-socket

Usage example:
  http-server -u -U /tmp/sock /tmp/no-such-dir
  curl -v --unix-socket /tmp/sock 127.1:8080/foo

5 years agobuild: struct sockaddr_un detection (sys/un.h, afunix.h)
Azat Khuzhin [Sun, 12 May 2019 13:12:06 +0000 (16:12 +0300)]
build: struct sockaddr_un detection (sys/un.h, afunix.h)

- On UNIX:     sys/un.h
- Since win10: afunix.h

And windows has AF_UNIX but do not have sockaddr_un (before windows
build 17061 [1]), hence the sockaddr_un detection.

  [1]: https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/

5 years agokqueue: Avoid undefined behaviour.
Tobias Stoeckmann [Fri, 10 May 2019 21:54:14 +0000 (23:54 +0200)]
kqueue: Avoid undefined behaviour.

As ploxiln pointed out in pull request 811 the check "newsize < 0"
is undefined behaviour (signed int overflow).

Follow the advice and check kqop->changes_size instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Closes: #813 (cherry-picked)
5 years agoPrevent integer overflow in kq_build_changes_list.
Tobias Stoeckmann [Tue, 7 May 2019 18:53:17 +0000 (20:53 +0200)]
Prevent integer overflow in kq_build_changes_list.

On amd64 systems with kqueue (e.g. *BSD systems) an integer overflow
could be triggered with an excessively huge amount of events.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 years agoevdns: fix lock/unlock mismatch in evdns_close_server_port()
zhuizhuhaomeng [Mon, 6 May 2019 03:37:02 +0000 (11:37 +0800)]
evdns: fix lock/unlock mismatch in evdns_close_server_port()

Closes: #809 (cherry-picked)
5 years agoMerge remote-tracking branch 'official/pr/804'
Azat Khuzhin [Tue, 30 Apr 2019 05:43:27 +0000 (08:43 +0300)]
Merge remote-tracking branch 'official/pr/804'

* official/pr/804:
  Added test for evmap slot validations.
  Prevent endless loop in evmap_make_space.
  Enforce limit of NSIG signals.

5 years agoAdded test for evmap slot validations.
Tobias Stoeckmann [Wed, 24 Apr 2019 20:55:24 +0000 (22:55 +0200)]
Added test for evmap slot validations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 years agoPrevent endless loop in evmap_make_space.
Tobias Stoeckmann [Wed, 24 Apr 2019 20:54:04 +0000 (22:54 +0200)]
Prevent endless loop in evmap_make_space.

If slot is larger than INT_MAX / 2, then the loop which increases
nentries until it is larger than slot would never return.

Also make sure that nentries * msize will never overflow INT_MAX.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 years agoEnforce limit of NSIG signals.
Tobias Stoeckmann [Mon, 22 Apr 2019 17:58:56 +0000 (19:58 +0200)]
Enforce limit of NSIG signals.

It doesn't make sense to allow a signal number higher than NSIG.

The NSIG check already exists in signal.c for internally used
functions.

As this is a programming error of libevent consumers, this is a
purely defensive mechanism.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 years agoProtect min_heap_push_ against integer overflow.
Tobias Stoeckmann [Tue, 16 Apr 2019 19:12:21 +0000 (21:12 +0200)]
Protect min_heap_push_ against integer overflow.

Converting unsigned to size_t for size of memory objects allows
proper handling of very large heaps on 64 bit systems.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Closes: #799 (cherry-picked)
5 years agole-proxy: initiate use of the Winsock DLL
linxiaohui [Thu, 18 Apr 2019 09:10:33 +0000 (17:10 +0800)]
le-proxy: initiate use of the Winsock DLL

Closes: #803 (cherry-picked)
5 years agoevwatch: fix race condition
Dan Rosen [Wed, 17 Apr 2019 19:44:59 +0000 (15:44 -0400)]
evwatch: fix race condition

There was a race between event_base_loop and evwatch_new (adding a
prepare/check watcher while iterating over the watcher list). Only
release the mutex immediately before invoking each watcher callback,
and reacquire it immediately afterwards (same as is done for normal
event handlers).

5 years agoIgnore build files for autotools build in subfolder too
Azat Khuzhin [Sat, 13 Apr 2019 10:22:55 +0000 (13:22 +0300)]
Ignore build files for autotools build in subfolder too

5 years agoMerge branch '21_http_extended_method'
Azat Khuzhin [Thu, 11 Apr 2019 19:52:10 +0000 (22:52 +0300)]
Merge branch '21_http_extended_method'

* 21_http_extended_method:
  Added http method extending
  http: Update allowed_methods field from 16 to 32bits.

Fixes: #327
5 years agoAdded http method extending
Thomas Bernard [Fri, 8 Jan 2016 21:36:20 +0000 (13:36 -0800)]
Added http method extending

User can define his own response method by calling
evhttp_set_ext_method_cmp() on the struct http, or
evhttp_connection_set_ext_method_cmp() on the connection.

We expose a new stucture `evhttp_ext_method` which is passed to the
callback if it's set. So any field can be modified, with some exceptions
(in evhttp_method_):

If the cmp function is set, it has the ability to modify method, and
flags. Other fields will be ignored. Flags returned are OR'd with the
current flags.

Based on changes to the #282 from: Mark Ellzey <socket@gmail.com>

5 years agohttp: Update allowed_methods field from 16 to 32bits.
Thomas Bernard [Tue, 2 Apr 2019 13:43:35 +0000 (15:43 +0200)]
http: Update allowed_methods field from 16 to 32bits.

5 years agohttp: replace EVHTTP_REQ_UNKNOWN_ with 0
Azat Khuzhin [Mon, 8 Apr 2019 19:27:33 +0000 (22:27 +0300)]
http: replace EVHTTP_REQ_UNKNOWN_ with 0

From the server perspective the evhttp_response_phrase_internal() should
not be called with 0 before this patch, it will be called with
EVHTTP_REQ_UNKNOWN_ hence this patch should not change behavior.

Fixes: 68eb526d7b ("http: add WebDAV methods support")
Fixes: #789
Fixes: #796
Reported-by: Thomas Bernard <miniupnp@free.fr>
5 years agoRemove experimental note for finalizers API
Azat Khuzhin [Thu, 4 Apr 2019 06:09:09 +0000 (09:09 +0300)]
Remove experimental note for finalizers API

5 years agohttps-client: do not try to free not initialized base
Azat Khuzhin [Wed, 3 Apr 2019 20:22:54 +0000 (23:22 +0300)]
https-client: do not try to free not initialized base

Otherwise:
  $ https-client --help
  Syntax:
     https-client -url <https-url> [-data data-file.bin] [-ignore-cert] [-retries num] [-timeout sec] [-crt crt]
  Example:
     https-client -url https://ip.appspot.com/
  [warn] event_base_free_: no base to free

5 years agohttp: drop unused internal macros
Azat Khuzhin [Wed, 3 Apr 2019 20:20:06 +0000 (23:20 +0300)]
http: drop unused internal macros

5 years agoevwatch: Add "prepare" and "check" watchers.
Dan Rosen [Tue, 26 Mar 2019 17:33:57 +0000 (13:33 -0400)]
evwatch: Add "prepare" and "check" watchers.

Adds two new callbacks: "prepare" watchers, which fire immediately
before we poll for I/O, and "check" watchers, which fire immediately
after we finish polling and before we process events. This allows other
event loops to be embedded into libevent's, and enables certain
performance monitoring.

Closes: #710
5 years agoDisable logging for tests that assume printing warnings
Azat Khuzhin [Wed, 3 Apr 2019 04:26:21 +0000 (07:26 +0300)]
Disable logging for tests that assume printing warnings

To avoid possible confusion

But there is still one test that has some messages on windows:
  main/methods

Because this test needs >1 of avaiable methods, otherwise it will warn.

5 years agoRemove manually written nmake makefiles (cmake should be used instead)
Azat Khuzhin [Mon, 25 Mar 2019 08:13:03 +0000 (11:13 +0300)]
Remove manually written nmake makefiles (cmake should be used instead)

This nmake stuff is out dated, and nobody wants to support it anyway.

5 years agoappveyor: check intermediate powershell commands exit codes and terminate early
Azat Khuzhin [Tue, 2 Apr 2019 20:25:08 +0000 (23:25 +0300)]
appveyor: check intermediate powershell commands exit codes and terminate early

Otherwise build errors will be ignored, i.e. if build fails but regress
binary exists (copied from artifacts) it will be runned instead of newly
compiled.

5 years agoMerge branch 'fix-uchex-warnings'
Azat Khuzhin [Sun, 31 Mar 2019 23:42:55 +0000 (02:42 +0300)]
Merge branch 'fix-uchex-warnings'

There is one more report that is false positive, see [1]:
  "In bufferevent_openssl.c, pointer wm is dereferenced on line 871
before it is null checked on line 873."

  [1]: https://github.com/libevent/libevent/issues/382#issuecomment-238081938

* fix-uchex-warnings:
  evdns: do not check server_req twice
  evrpc: do not check req twice

Fixes: #382
5 years agoevdns: do not check server_req twice
Azat Khuzhin [Sun, 31 Mar 2019 23:41:17 +0000 (02:41 +0300)]
evdns: do not check server_req twice

Reported by µchex:
  "In evdns.c, pointer server_req is null checked on line 1289 after it
is dereferenced above. Since server_req was already null checked above
on line 1243, there is no risk of crashing and the only bug is the
redundant null check (and indentation) on line 1289.
"

5 years agoevrpc: do not check req twice
Azat Khuzhin [Sun, 31 Mar 2019 23:37:41 +0000 (02:37 +0300)]
evrpc: do not check req twice

reported by µchex:
  "In evrpc.c, pointer req is dereferenced on line 881 before it is null
checked on line 894."

5 years agoevdns: add DNS_OPTION_NAMESERVERS_NO_DEFAULT/EVDNS_BASE_NAMESERVERS_NO_DEFAULT
Azat Khuzhin [Sun, 31 Mar 2019 22:47:00 +0000 (01:47 +0300)]
evdns: add DNS_OPTION_NAMESERVERS_NO_DEFAULT/EVDNS_BASE_NAMESERVERS_NO_DEFAULT

- DNS_OPTION_NAMESERVERS_NO_DEFAULT
  Do not "default" nameserver (i.e. "127.0.0.1:53") if there is no nameservers
  in resolv.conf, (iff DNS_OPTION_NAMESERVERS is set)

- EVDNS_BASE_NAMESERVERS_NO_DEFAULT
  If EVDNS_BASE_INITIALIZE_NAMESERVERS isset, do not add default
  nameserver if there are no nameservers in resolv.conf (just set
  DNS_OPTION_NAMESERVERS_NO_DEFAULT internally)

Fixes: #569
5 years agoevdns: add descriptions for DNS_OPTION_*/DNS_OPTIONS_ALL
Azat Khuzhin [Sun, 31 Mar 2019 22:40:18 +0000 (01:40 +0300)]
evdns: add descriptions for DNS_OPTION_*/DNS_OPTIONS_ALL

5 years agoLink test/regress with event_core/event_extra over event
Azat Khuzhin [Sun, 24 Mar 2019 22:40:46 +0000 (01:40 +0300)]
Link test/regress with event_core/event_extra over event

Due to regress linked with event and event_core (both of them includes
evthread.c) there will be two different evthread_id_fn_ variables under
mingw64:
  evthread_id_fn_: &0x5294f20a8
  evthread_id_fn_: &0x4ba0030a8

And because of this evthread_use_pthreads() can/will set one copy of
variables while evthread*() functions will access another, which will
break a lot of things (for example main/del_notify test).

Fixes: #792
5 years agosignal: guard __cdecl definition with #ifdef
Azat Khuzhin [Sun, 24 Mar 2019 22:41:09 +0000 (01:41 +0300)]
signal: guard __cdecl definition with #ifdef

Under mingw64:
  ../signal.c:88:0: warning: "__cdecl" redefined
   #define __cdecl

  <built-in>: note: this is the location of the previous definition

https://ci.appveyor.com/project/azat/libevent/builds/23321613#L427

5 years agotinytest: fix parsing --timeout argument
Azat Khuzhin [Sun, 24 Mar 2019 17:36:16 +0000 (20:36 +0300)]
tinytest: fix parsing --timeout argument

Fixes: 15b2f41d ("tinytest: implement per-test timeout (via alarm() under !win32 only)")
5 years agotinytest: implement per-test timeout (via alarm() under !win32 only)
Azat Khuzhin [Sun, 24 Mar 2019 13:44:56 +0000 (16:44 +0300)]
tinytest: implement per-test timeout (via alarm() under !win32 only)

5 years agoMerge branch 'buffer-read-size'
Azat Khuzhin [Sat, 16 Mar 2019 14:41:09 +0000 (17:41 +0300)]
Merge branch 'buffer-read-size'

And after this patch set default evbuffer max read via bufferevent is
16K not 4K.

Here is some numbers for the single max read in evbuffer impact:
  function client() { becat "$@" | pv > /dev/null; }
  function server() { cat /dev/zero | becat -l "$@"; }

Plain bufferevent:

- 40K
  $ server -R $((40<<10)) & client -R $((40<<10))
  700MiB/s

- 16K *default now*
  $ server & client
  1.81GiB/s

- 4K
  $ server -R $((4<<10)) & client -R $((4<<10))
  1.05GiB/s

With OpenSSL (-S):

- 40K *default now*
  $ server -S -R $((40<<10)) & client -S -R $((40<<10))
  900MiB/s

- 16K *default now*
  $ server -S & client -S
  745MiB/s

- 4K
  $ server -S -R $((4<<10)) & client -S -R $((4<<10))
  593MiB/s

So as you can see without openssl 16K is faster then 40K/4K, while for
openssl 40K is still faster then 16K (I guess that this is due to with
openssl SSL_read() more at at time, while with plain we have some
allocations splits in evbuffer and maybe due to some buffer in openssl)

* buffer-read-size:
  sample/becat: bufferevent cat, ncat/nc/telnet analog
  Adjust evbuffer max read for bufferevents
  Maximum evbuffer read configuration
  Fix leaks in error path of the bufferevent_init_common_()

5 years agosample/becat: bufferevent cat, ncat/nc/telnet analog
Azat Khuzhin [Tue, 5 Mar 2019 18:34:31 +0000 (21:34 +0300)]
sample/becat: bufferevent cat, ncat/nc/telnet analog

5 years agoAdjust evbuffer max read for bufferevents
Azat Khuzhin [Sat, 16 Mar 2019 14:32:17 +0000 (17:32 +0300)]
Adjust evbuffer max read for bufferevents

5 years agoMaximum evbuffer read configuration
Azat Khuzhin [Sat, 16 Mar 2019 14:09:51 +0000 (17:09 +0300)]
Maximum evbuffer read configuration

Before this patch evbuffer always reads 4K at a time, while this is fine
most of time you can find an example when this will decrease throughput.

So add an API to change default limit:
- evbuffer_set_max_read()
- evbuffer_get_max_read()

And a notice that most of time default is sane.

5 years agoFix leaks in error path of the bufferevent_init_common_()
Azat Khuzhin [Sat, 16 Mar 2019 14:28:31 +0000 (17:28 +0300)]
Fix leaks in error path of the bufferevent_init_common_()

5 years agobench: suppress int conversion warnings
Azat Khuzhin [Sat, 16 Mar 2019 13:52:05 +0000 (16:52 +0300)]
bench: suppress int conversion warnings

5 years agoSuppress int conversion warnings in getopt_long compatibility
Azat Khuzhin [Sat, 16 Mar 2019 13:37:38 +0000 (16:37 +0300)]
Suppress int conversion warnings in getopt_long compatibility

5 years agohttp: add WebDAV methods support
Alexander Drozdov [Wed, 13 Mar 2019 07:51:55 +0000 (10:51 +0300)]
http: add WebDAV methods support

WebDAV introduced new HTTP methods (RFC4918):
PROPFIND, PROPPATCH, MKCOL, LOCK, UNLOCK, COPY, MOVE.

Add support of the methods.

5 years agohttp: suppress -Wwrite-string in evhttp_parse_query_impl()
Azat Khuzhin [Tue, 12 Mar 2019 21:20:25 +0000 (00:20 +0300)]
http: suppress -Wwrite-string in evhttp_parse_query_impl()

5 years agocmake: sync warnings with autotools v2
Azat Khuzhin [Tue, 12 Mar 2019 21:02:39 +0000 (00:02 +0300)]
cmake: sync warnings with autotools v2

By some reason gcc reports next error:
  ../http.c:3330:11: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
       value = "";

Only under -Wwrite-strings, well this is logical, but this information
does not reflected in any documentation.

Follow-up: 8348b413 ("cmake: add various warning flags like autotools has")

f

5 years agoUpdate documentation [ci skip]
Sayan Nandan [Sun, 10 Mar 2019 14:21:44 +0000 (19:51 +0530)]
Update documentation [ci skip]

The documentation for building and installing has been moved into a new
Documentation section

Closes: #788 (cherry-picked)
5 years agoMove list of contributors into separate file
Sayan Nandan [Fri, 8 Mar 2019 11:17:56 +0000 (16:47 +0530)]
Move list of contributors into separate file

Closes: #786 (cherry-picked)
5 years agohttp: implement separate timeouts for read/write/connect phase
Azat Khuzhin [Mon, 4 Mar 2019 03:53:42 +0000 (06:53 +0300)]
http: implement separate timeouts for read/write/connect phase

This patch allows to change timeout for next events read/write/connect
separatelly, using new API:

- client:
  evhttp_connection_set_connect_timeout_tv() -- for connect
  evhttp_connection_set_read_timeout_tv()    -- for read
  evhttp_connection_set_write_timeout_tv()   -- for write

- server:
  evhttp_set_read_timeout_tv()  -- for read
  evhttp_set_write_timeout_tv() -- for write

It also changes a logic a little, before there was next fallbacks which
does not handled in new API:
- HTTP_CONNECT_TIMEOUT
- HTTP_WRITE_TIMEOUT
- HTTP_READ_TIMEOUT

And introduce another internal flag (EVHTTP_CON_TIMEOUT_ADJUSTED) that
will be used in evrpc, which adjust evhttp_connection timeout only if it
is not default.

Fixes: #692
Fixes: #715
5 years agoAdd support for EV_TIMEOUT to event_base_active_by_fd
John Ohl [Wed, 10 Dec 2014 02:43:18 +0000 (21:43 -0500)]
Add support for EV_TIMEOUT to event_base_active_by_fd

Closes: #194 (cherry-pick)
5 years agobuffer: make evbuffer_prepend() of zero-length array no-op
Azat Khuzhin [Sun, 3 Mar 2019 16:03:29 +0000 (19:03 +0300)]
buffer: make evbuffer_prepend() of zero-length array no-op

Refs: #774

5 years agoMerge branch 'evbuffer-empty-chain-handling'
Azat Khuzhin [Sun, 3 Mar 2019 15:58:57 +0000 (18:58 +0300)]
Merge branch 'evbuffer-empty-chain-handling'

* evbuffer-empty-chain-handling:
  buffer: do not rely on ->off in advance_last_with_data()
  buffer: fix evbuffer_remove_buffer() with empty chain in front
  test: verify content of the buffer in evbuffer/remove_buffer_with_empty*

5 years agobuffer: do not rely on ->off in advance_last_with_data()
Azat Khuzhin [Sun, 3 Mar 2019 13:29:52 +0000 (16:29 +0300)]
buffer: do not rely on ->off in advance_last_with_data()

advance_last_with_data() adjusts evbuffer.last_with_datap, and if we
will have empty chain in the middle advance_last_with_data() will stop,
while it should not, since while empty chains is not regular thing they
can pops up in various places like, and while I did not look through all
of them the most tricky I would say is:
  evbuffer_reverse_space()/evbuffer_commit_space()
  evbuffer_add_reference()

Test case from:
  https://github.com/envoyproxy/envoy/pull/6062

Fixes: #778
v2: keep last_with_datap really last with data, i.e. update only if
chain has data in it

5 years agobuffer: fix evbuffer_remove_buffer() with empty chain in front
Azat Khuzhin [Sat, 2 Mar 2019 19:50:00 +0000 (22:50 +0300)]
buffer: fix evbuffer_remove_buffer() with empty chain in front

In case we have empty chain (chain that do not have any data, i.e. ->off
== 0) at the beginning of the buffer, and no more full chains to move to
the dst, we will skip moving of this empty chain, and hence
last_with_datap will not be adjusted, and things will be broken after.

Fix this by not relying on ->off, just count if we have something to
move that's it.

Test case from:
  https://github.com/envoyproxy/envoy/pull/6062

Fixes: #774
5 years agotest: verify content of the buffer in evbuffer/remove_buffer_with_empty*
Azat Khuzhin [Sun, 3 Mar 2019 14:43:37 +0000 (17:43 +0300)]
test: verify content of the buffer in evbuffer/remove_buffer_with_empty*

And replace spaces with tab in remove_buffer_with_empty

5 years agoRemove needless check for arc4_seeded_ok
Seong-Joong Kim [Thu, 21 Feb 2019 16:19:10 +0000 (16:19 +0000)]
Remove needless check for arc4_seeded_ok

5 years agoFix typos: warnigns -> warnings
Enji Cooper [Fri, 1 Mar 2019 01:47:51 +0000 (17:47 -0800)]
Fix typos: warnigns -> warnings

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
5 years agoFix typos in a comment describing the purpose of `VersionViaGit.cmake`
Enji Cooper [Fri, 1 Mar 2019 01:22:30 +0000 (17:22 -0800)]
Fix typos in a comment describing the purpose of `VersionViaGit.cmake`

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
5 years agoDefine `_GNU_SOURCE` properly/consistently per autoconf
Enji Cooper [Mon, 25 Feb 2019 19:59:15 +0000 (11:59 -0800)]
Define `_GNU_SOURCE` properly/consistently per autoconf

Although `_GNU_SOURCE` can be defined as an arbitrary #define per the
glibc docs [1], it's best to define it in a manner consistent with the way
that autoconf defines it, i.e., `1`.

While this shouldn't matter in most cases, it does when the headers from
other projects follow the poorly defined GNU convention implemented by
autoconf and are included after the libevent's util.h header. An example
failure with clang, similar to the failure I encountered, is as follows:
```
$ printf "#define _GNU_SOURCE\n#define _GNU_SOURCE 1" | clang -c -x c -
<stdin>:2:9: warning: '_GNU_SOURCE' macro redefined [-Wmacro-redefined]
        ^
<stdin>:1:9: note: previous definition is here
        ^
1 warning generated.
```

This happened when compiling python [2] with a stale homebrew util.h file from
libevent (which admittedly would not happen in a correct libevent install, as the
header should be installed under /usr/local/include/event2/util.h). However, if
both headers had been combined (which is more likely), it would have failed as
shown above.

Removing the ad hoc definition unbreaks compiling python's pyconfig.h.in header
when included after util.h from libevent.

1. http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
2. https://github.com/python/cpython/blob/master/configure.ac#L126

Closes: #773 (cherry-picked)
Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
5 years agoDon't loose top error in SSL
Yury Korzhetsky [Tue, 26 Feb 2019 09:33:49 +0000 (12:33 +0300)]
Don't loose top error in SSL

Closes: #775 (cherry-picked)
5 years agoIgnore bitrise branches for travis-ci/appvyeor [ci skip]
Azat Khuzhin [Sun, 24 Feb 2019 21:26:39 +0000 (00:26 +0300)]
Ignore bitrise branches for travis-ci/appvyeor [ci skip]

5 years agoUpdate link to the appveyor project
Azat Khuzhin [Sun, 24 Feb 2019 19:59:33 +0000 (22:59 +0300)]
Update link to the appveyor project

Since the migration request has been hanged for a while, let's switch it
for now without beauty API URL.

Fixes: #555
5 years agoMatch definition with prototype for bufferevent_socket_set_conn_address_fd_()
Azat Khuzhin [Sun, 24 Feb 2019 14:34:20 +0000 (17:34 +0300)]
Match definition with prototype for bufferevent_socket_set_conn_address_fd_()

Fixes: #772
Fixes: b29207dc ("Eliminate fd conversion warnings and introduce EVUTIL_INVALID_SOCKET (windows)")
5 years agoRevert "test: avoid regress hanging in macOS"
Azat Khuzhin [Sun, 24 Feb 2019 14:25:31 +0000 (17:25 +0300)]
Revert "test: avoid regress hanging in macOS"

After we started to use kill() over raise() everything should work just
fine.

This reverts commit a86f89d333d870e6714bd28c695ba1774df3d7f5.

Fixed-in: 728c5dc1 ("Use kill() over raise() for raising the signal (fixes osx 10.14 with kqueue)")
Fixes: #747
5 years agoUse kill() over raise() for raising the signal (fixes osx 10.14 with kqueue)
Azat Khuzhin [Sun, 24 Feb 2019 14:07:18 +0000 (17:07 +0300)]
Use kill() over raise() for raising the signal (fixes osx 10.14 with kqueue)

On OSX 10.14+ the raise() uses pthread_kill() (verified with dtruss) and
by some reason signals that has been raised with pthread_kill() do not
received by kqueue EVFILT_SIGNAL.

While on OSX 10.11 the raise()/pthread_kill() uses plain kill() and
everything work just fine (linux also does the same, but instead of
kill() it uses tgkill())

Here is a simple reproducer that installs alarm to show that the signal
does not received by the kqueue backend:
  https://gist.github.com/azat/73638b8e3b0fa563a20dadcca9e652a1

Refs: #747
Fixes: #765