4956 Commits

Author SHA1 Message Date
Azat Khuzhin
57d9eec641 Disable signalfd by default
signalfd may behave differently to sigaction/signal, so to avoid
breaking libevent users (like [1], [2]) disable it by default.

  [1]: https://github.com/tmux/tmux/pull/3621
  [2]: https://github.com/tmux/tmux/pull/3626

Also signalfd is not that perfect:
- you need to SIG_BLOCK the signal before
  - blocked signals are not reset on exec
  - blocked signals are allowed to coalesce - so in case of multiple
    signals sent you may get the signal only once (ok for most of the
    signals, but may be a problem for SIGCHLD, though you may call
    waitpid() in a loop or use pidfd)
- and also one implementation problem -
  sigprocmask is unspecified in a multithreaded process

Refs:
- https://lwn.net/Articles/415684/
- https://ldpreload.com/blog/signalfd-is-useless

Refs: https://github.com/libevent/libevent/issues/1460
Refs: #1342 (cc @dmantipov)
2023-07-13 21:21:09 +02:00
Vladislav Gusev
227510d577
Fix EVDNS_BASE_DISABLE_WHEN_INACTIVE (#1493)
I faced with strange problem: event loop doesn't exit after dns resolving with
`EVDNS_BASE_DISABLE_WHEN_INACTIVE`.

Stand:
- Ubuntu 22;
- libevent release-2.1.12-stable
- `resolve.conf` contains 2 nameservers;
- I use `evdns_base_new` with `EVDNS_BASE_DISABLE_WHEN_INACTIVE | EVDNS_BASE_INITIALIZE_NAMESERVERS` to avoid OS specific code.

After small investigation, look like events related with dns sockets added to
event_base before `evdns->disable_when_inactive` was initialized. `libevent`
did epoll_ctl(DEL) after resolving completed on the first socket, but the
second socket remained in the `epoll` interest list.
2023-07-13 21:20:33 +02:00
mareksm
36ad1006c9 #1479: GCC12 error for EVUTIL_FALLTHROUGH 2023-07-07 20:26:58 +02:00
Azat Khuzhin
5ab24bddbe Merge branch 'becat-fixes'
* becat-fixes:
  becat: fix handling positional arguments
  becat: handle -T correctly
2023-06-28 21:33:47 +02:00
Azat Khuzhin
2b729238e5 becat: fix handling positional arguments 2023-06-28 21:33:41 +02:00
Azat Khuzhin
687124d018 becat: handle -T correctly 2023-06-28 21:33:41 +02:00
Azat Khuzhin
be4eb97dc2
Disable lazy gettimeofday/clock_gettime comparison (#1474) 2023-06-21 22:26:51 +03:00
Azat Khuzhin
2e31277207 Disable lazy gettimeofday/clock_gettime comparison
The benefit of this optimization is questionable for the following
reasons:
- libevent uses CLOCK_MONOTONIC_COARSE which is fast enough (on my
  desktop CLOCK_MONOTONIC/CLOCK_MONOTONIC_RAW works 40/50 millions of
  ops per second, and CLOCK_MONOTONIC_COARSE is faster)
- libevent has caching of time (EVENT_BASE_FLAG_NO_CACHE_TIME)

So I don't see any reason for using one more caching - lazy comparsion
(whatever you call it).
2023-06-21 09:47:07 +02:00
Krzysztof Dynowski
13366d2711 Test timer - synchronize clock before tv_timeout calculation. 2023-06-21 09:47:07 +02:00
Krzysztof Dynowski
4f993028be Synchronize clock before tv_timeout calculation. 2023-06-21 08:58:58 +02:00
FreeCipher
b30c0d0466
Use mm_* functions in evutil_inet_pton_scope (#1476) 2023-06-20 21:55:00 +02:00
Dave Hart
242f767684 Enable containing package CFLAGS etc.
Add AC_SUBST of LIBEVENT_FLAGS, LIBEVENT_CPPFLAGS, and LIBEVENT_LDFLAGS so they are relayed from the configure command line to the Makefile
2023-06-20 22:45:45 +03:00
Q_uan
57bb630ce3 Add __cplusplus in ws.h to fix compilation errors when using c++ compiler 2023-06-20 12:16:59 +03:00
Alex
b0194392fb
wepoll: replace default malloc/free with libevent mm_ variants (#1472)
This replaces malloc and free in wepoll.c with mm_malloc and mm_free. I'm using event-internal.h instead of mm-internal.h. Using only mm-internal.h in wepoll.c can cause errors regarding the export symbol macros.
2023-06-08 23:25:22 +02:00
Azat Khuzhin
45e24185f5
Merge pull request #1470 from mdavidsaver/auto-detect-ssl
Both cmake and autoconf are capable of automatically detecting the presence of OpenSSL and MbedTLS.  However, the present build time logic doesn't do this.

With cmake, my starting point is to preserve the reversed logic of `EVENT__DISABLE_OPENSSL` and `EVENT__DISABLE_MBEDTLS`, adding a third option `AUTO` as the new default.  I'm following the pattern of this [post on the cmake list](https://cmake.org/pipermail/cmake/2016-October/064342.html).  `OFF` and `ON` should continue with their present behaviors.

With autoconf, I've tried to implement what I understand to be conventional behavior.  eg. `--enable-openssl` and `--disable-openssl` should continue to have the same effect.  The default if neither is passed is equivalent to the new `--enable-openssl=auto`.

I've also added another commit removing what I think is an unnecessary `break` in `m4/libevent_mbedtls.m4`, which I suspect is leftover from some copy+paste from `m4/libevent_openssl.m4`.  Surprisingly to me, a `break` outside of any loop does not seem to be treated as an error.
2023-06-07 22:39:46 +02:00
Michael Davidsaver
7cd51ae1dd Add CI tests which require SSL libraries 2023-06-07 11:10:14 -07:00
Michael Davidsaver
9ce6ae78af Add option to auto-detect OpenSSL and MbedTLS 2023-06-07 11:10:14 -07:00
Michael Davidsaver
71848a237e libevent_mbedtls.m4 remove extraneous break
Maybe a leftover or copy+paste from a for loop
in libevent_openssl.m4 ?
2023-06-06 12:41:53 -07:00
Diogo Teles Sant'Anna
bca26524fc
Create Security Policy (#1462)
I've created the SECURITY.md file following a GitHub's template and considering the report vulnerability through security advisory, which is a handy new GitHub feature (but it's still in beta and has to be enabled).

Closes #1461
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
2023-05-25 07:05:28 +02:00
Leo Zhang
1418e793ad build: fix some new warnings
/opensource/libevent/sample/ws-chat-server.c:253:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
2023-05-25 07:00:35 +02:00
Azat Khuzhin
283a371f51 cmake: log when CMAKE_DEBUG_POSTFIX/CMAKE_BUILD_TYPE is changed 2023-05-23 21:46:14 +02:00
Azat Khuzhin
2112c3969a autotools: fix generating pkg-config files (by substituting CMAKE_DEBUG_POSTFIX)
Fixes: #1459
2023-05-22 08:48:06 +02:00
Daniel Engberg
4effaee523 cmake: Fix .pc files when building in Release mode
Don't define CMAKE_DEBUG_POSTFIX as this breaks Release builds, only apply when doing debug builds.
2023-05-22 08:14:42 +02:00
Azat Khuzhin
abc114e3c8 Bump default version when git tag is incorrect
Fixes: #1457
2023-05-21 12:49:34 +02:00
Azat Khuzhin
1c06b68fee Add a note about the last number in NUMERIC_VERSION 2023-05-21 10:10:18 +02:00
Azat Khuzhin
fe9dc8f614 Merge branch 'release-2.2-pull' - 2.2.1-alpha (#1380)
* release-2.2-pull:
  Bump version to 2.2.1
  Update ChangeLog and whatsnew for 2.2.1
  Update contributors (for 2.2 release)
release-2.2.1-alpha
2023-05-21 08:54:07 +02:00
Azat Khuzhin
8d1388a372 Bump version to 2.2.1 2023-05-21 08:47:42 +02:00
Azat Khuzhin
4e19e8b455 Update ChangeLog and whatsnew for 2.2.1 2023-05-21 08:47:39 +02:00
Azat Khuzhin
6ce568c38c Update contributors (for 2.2 release) 2023-05-20 18:19:31 +02:00
Azat Khuzhin
13ce3045c7 Merge branch 'changelog-improvements'
* changelog-improvements:
  Generate changelog in a reverse order
  Add PR number into the changelog
  Use authors of the real patches instead of merge commits
  Cleanup changelog.py
2023-05-20 18:19:04 +02:00
Azat Khuzhin
1fb3e6d79e Generate changelog in a reverse order 2023-05-20 18:18:57 +02:00
Azat Khuzhin
8b87ad48cb Add PR number into the changelog 2023-05-20 18:18:57 +02:00
Azat Khuzhin
fb2e1a6919 Use authors of the real patches instead of merge commits 2023-05-20 18:18:57 +02:00
Azat Khuzhin
c2e917d301 Cleanup changelog.py
- Use positional argument for revision range
- Remove unused import
- Add some todos
2023-05-20 18:18:57 +02:00
Azat Khuzhin
2c2ffb8d6e Revert "cmake: Only use relative paths for install DESTINATION option (#1405)"
After rebasing I broke the initial intention of this patch, so it simply
should be reverted.

This reverts commit 81c6b8823c1b58d7837e827bb1098aa5f9e5956b.
2023-05-20 16:00:44 +02:00
Azat Khuzhin
5324e482d0 Merge branch 'ssl-read-pull' - #1454
* ssl-read-pull:
  ssl: add some comments for lack of notify_close
  Drop unused le_ssl_ops::err_is_ok
  More SSL_read() to fill big buffer
  Make bufferevent_set_max_single_read() effect
2023-05-16 21:21:48 +02:00
Azat Khuzhin
49a7ae4c56 ssl: add some comments for lack of notify_close 2023-05-16 21:20:35 +02:00
Azat Khuzhin
e5941b2ce9 Drop unused le_ssl_ops::err_is_ok
It is not used anymore since errors are ignored if some progress had
been done.
2023-05-16 21:20:21 +02:00
Thuan Tran
ef51444f43 More SSL_read() to fill big buffer
Once SSL_read() only get max 16K bytes (one TLS record).
In case of big buffer, should more SSL_read() to fill the buffer.

Using sample https-client to measure max income MBit/s via nload tool.
Note: set bufferevent_set_max_single_read() by 32K and add the chunk
callback to read out each piece of data.

The client sample do https request a data 900KB (the server don't use
Transfer-Encoding: chunked)
- With origin/master: max income is 2.26 MBit/s
  The chunk callback never get a piece of data > 16K.
- With this PR: max income is 2.44 MBit/s
  The chunk callback can get some piece of data 32K or more.
2023-05-16 21:11:54 +02:00
Thuan Tran
4ab3242da1 Make bufferevent_set_max_single_read() effect 2023-05-16 21:11:54 +02:00
Ingo Bauersachs
acfac7ae4a Make dependency paths relocatable
The generated configurations for both CMake and pkg-config included
absolute paths to dependencies (OpenSSL, MbedTLS). This is contrary
to the general CMake advise to create relocatable packages [1].

Additionally, when building both mbedtls and libevent via CMake's
FetchContent in the same project, loading the project would fail with

  INTERFACE_INCLUDE_DIRECTORIES property contains path:
    "/home/user/project/cmake-build/_deps/mbedtls-build/include"
  which is prefixed in the source directory.

The required changes include:
- Adding the outer includes only to the BUILD_INTERFACE solves the
  makes the CMake paths relocatable and thus solves the FetchContent
  problem.
- Updates to libevent_*.pc.in fixes the relocatable issues for
  pkg-config and properly declares currently missing dependencies.
- Using components for linking to OpenSSL (requiring CMake 3.4)
  and MbedTLS. The new MbedTLS target names now match the component
  names of the MbedTLS' CMake project.
- Use the Threads CMake library reference instead of a direct
  reference to support both built-in pthread and -lpthread.

v2 (azat): get back CMAKE_REQUIRED_LIBRARIES

[1] https://cmake.org/cmake/help/v3.25/manual/cmake-packages.7.html#creating-relocatable-packages
2023-05-16 07:46:56 +02:00
Jeremy W. Murphy
81c6b8823c
cmake: Only use relative paths for install DESTINATION option (#1405)
As described in #1404, the explicit use of CMAKE_INSTALL_PREFIX conflicts with using command-line --prefix.

This simply removes all explicit use of CMAKE_INSTALL_PREFIX.

Otherwise this path will be duplicated:

    $ cmake -DCMAKE_BUILD_TYPE=debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_INSTALL_PREFIX=inst ..
    $ DESTDIR=inst ninja install
    ...
    -- Installing: inst/src/le/libevent/.cmake-debug/inst/include/event2/util.h
    -- Installing: inst/src/le/libevent/.cmake-debug/inst/include/event2/ws.h
    ...

Fixes: #1404
Co-authored-by: Jeremy Murphy <jeremymu@blackmagicdesign.com>
2023-05-15 21:07:36 +02:00
Azat Khuzhin
4dee61c02c Merge remote-tracking branch 'upstream/pr/1397' - #1397
* upstream/pr/1397:
  Make sure exported include dirs are correct
  Fix Configure_RPATH()
  Install LibeventConfig.cmake similar to other cmake files
  Use GNUInstallDirs for mapping installation directories
2023-05-14 22:56:02 +02:00
Tobias Mayer
16be768dac Make sure exported include dirs are correct
CMake config files don't need any logic to detect the location of
installed headers or DSOs, because these locations are already
determined at project configuration time. They also don't need
to distinguish between build and install trees, because that is
already handled by the generated `LibeventTargets-*.cmake` files.
2023-05-14 22:43:47 +02:00
Azat Khuzhin
41a7393f3e Fix Configure_RPATH() 2023-05-14 22:43:47 +02:00
Jonathan Ringer
be03bf385b Install LibeventConfig.cmake similar to other cmake files
- Don't destroy cmake file between test case invocations
2023-05-14 22:43:47 +02:00
Jonathan Ringer
1f1593ff27 Use GNUInstallDirs for mapping installation directories 2023-05-14 22:43:47 +02:00
Azat Khuzhin
fe610f2cdc Fix util/mm_calloc_enomem under FreeBSD
It looks like the compiler optimizes this call out with tt_assert():

    (gdb) disas /m test_event_calloc_enomem
    Dump of assembler code for function test_event_calloc_enomem:
       0x0000000000293bb0 <+0>:     push   %rbp
       0x0000000000293bb1 <+1>:     mov    %rsp,%rbp
       0x0000000000293bb4 <+4>:     call   0x29f510 <__error@plt>
       0x0000000000293bb9 <+9>:     movl   $0x0,(%rax)
       0x0000000000293bbf <+15>:    call   0x2990e0 <tinytest_set_test_failed_>
       0x0000000000293bc4 <+20>:    mov    $0x2168e4,%edi
       0x0000000000293bc9 <+25>:    mov    $0x220582,%esi
       0x0000000000293bce <+30>:    mov    $0x20d893,%edx
       0x0000000000293bd3 <+35>:    mov    $0x53a,%ecx
       0x0000000000293bd8 <+40>:    xor    %eax,%eax
       0x0000000000293bda <+42>:    call   0x29f3b0 <printf@plt>
       0x0000000000293bdf <+47>:    mov    $0x20da72,%edi
       0x0000000000293be4 <+52>:    mov    $0x20f731,%esi
       0x0000000000293be9 <+57>:    xor    %eax,%eax
       0x0000000000293beb <+59>:    pop    %rbp
       0x0000000000293bec <+60>:    jmp    0x29f3b0 <printf@plt>

While with tt_ptr_op() it does not:

    (gdb) disas /m test_event_calloc_enomem
    Dump of assembler code for function test_event_calloc_enomem:
       0x0000000000293bd0 <+0>:     push   %rbp
       0x0000000000293bd1 <+1>:     mov    %rsp,%rbp
       0x0000000000293bd4 <+4>:     push   %rbx
       0x0000000000293bd5 <+5>:     push   %rax
       0x0000000000293bd6 <+6>:     call   0x29f610 <__error@plt>
       0x0000000000293bdb <+11>:    movl   $0x0,(%rax)
       0x0000000000293be1 <+17>:    mov    $0xffffffffffffffff,%rdi
       0x0000000000293be8 <+24>:    mov    $0xffffffffffffffff,%rsi
       0x0000000000293bef <+31>:    call   0x2a01c0 <calloc@plt>
       0x0000000000293bf4 <+36>:    test   %rax,%rax
       0x0000000000293bf7 <+39>:    je     0x293c2b <test_event_calloc_enomem+91>
2023-05-14 22:35:53 +02:00
Azat Khuzhin
13f5552336 test: add missing include of arpa/inet.h for ntohs in regress_ws.c
This will fix one warning in FreeBSD
2023-05-14 22:31:02 +02:00
Azat Khuzhin
1f006637ec Merge branch 'build/osx-fixes'
* build/osx-fixes:
  Suppress -Wmacro-redefined for htonll/ntohll in OSX
  Fix -Wtautological-constant-out-of-range-compare in regress_http under OSX
2023-05-14 22:03:26 +02:00