4112 Commits

Author SHA1 Message Date
yangyongsheng
d9da412658 Initialize variable to 0 replace use memset function in sample/hello-world.c
(cherry picked from commit 1edb6f6188d5dd2155c6e8ad997eaca11157e95f)
2020-06-28 21:19:54 +03:00
Azat Khuzhin
2db851a980 cmake: set CMAKE_{RUNTIME,LIBRARY,ARCHIVE}_OUTPUT_DIRECTORY they are not defined
This will allow overriding them in parent cmake rules, i.e. if libevent
is used via add_subdirectory().

Closes: #931
(cherry picked from commit 8f13c170cf6e9a02dec410b967884ec5e08947ab)
2020-06-28 21:19:54 +03:00
Azat Khuzhin
47eb8c1208 cmake: use CMAKE_LIBRARY_OUTPUT_DIRECTORY for the final shared library symlink
Fixes: 669a53f3 ("cmake: set library names to be the same as with autotools")
(cherry picked from commit b9f442e2d7af8b01cd34f75f2f404763b76d42dc)
2020-06-28 21:19:54 +03:00
Azat Khuzhin
8ad26d0b11 test-ratelim: calculate timers bias (for slow CPUs) to avoid false-positive
This can be/should be done for regression tests too.

Refs: https://ci.appveyor.com/project/libevent/libevent/builds/28916689/job/kg621aa194a0qbym
Refs: https://github.com/libevent/libevent/pull/917#issuecomment-553811834
v2: EVENT_BASE_FLAG_PRECISE_TIMER
(cherry picked from commit 8a34869984c470fb243fc9587c469b316add2f7e)
2020-06-28 21:19:54 +03:00
Azat Khuzhin
ffc528e99f mailmap: add name/email aliases for yuangongji (name and email)
Before:
  $ git log --format='%aE %aN' --author=yuangongji | sort | uniq -c
       30 82787816@qq.com yuangongji
        1 82787816@qq.com yuangongji (A)

After:
  $ git log --format='%aE %aN' --author=yuangongji | sort | uniq -c
       34 yuangongji@foxmail.com yuangongji
(cherry picked from commit 026590f908f8ef8602d54bd680c8bef9f4552d55)
2020-06-28 21:19:54 +03:00
yuangongji
baec84f28a cmake: test for find_package()
(cherry picked from commit cd15112b620feadafe8fd3531043870a5c19a4a6)
2020-06-28 21:19:54 +03:00
yuangongji
1c047618ba cmake: improve package config file
(cherry picked from commit dc4be869d5009f38e0ef02ff07dd799f9c2fef2f)
2020-06-28 21:19:54 +03:00
Azat Khuzhin
976f7d34ff Link with iphlpapi only on windows
Fixes: 9fecb59a ("Parse IPv6 scope IDs.")
Refs: #923
(cherry picked from commit 1495f8b67a6061ac5c8dcbc42dd71398d6355c9a)
2020-06-28 21:19:54 +03:00
Philip Homburg
f602211fa1 Parse IPv6 scope IDs.
(cherry picked from commit 9fecb59a94ef246088d7f3e0365c2fe80d0df2f4)
2020-06-28 21:19:54 +03:00
Azat Khuzhin
ca92a7559e Relax bufferevent_connect_hostname_emfile
Do not do any assumptions on the error for the EMFILE from
getaddrinfo(), expect just any error.

Fixes: #924
(cherry picked from commit 4436287d1247fb2e9c80560debf852a94657e485)
2020-06-28 21:19:42 +03:00
yuangongji
93174bb537 autotools: fails build when need but can not find openssl
(cherry picked from commit 53b3be4ee9e814a22876675c0ee004f0ebfb8535)
2020-06-28 21:17:33 +03:00
yuangongji
a9d1121d16 cmake: eliminate duplicate installation of public headers
(cherry picked from commit 5fe83d7433022e29a401753f64ec78faaf25e0a7)
2020-06-28 21:17:33 +03:00
Michael Davidsaver
87c6f7358e append to CMAKE_MODULE_PATH
Don't override any -DCMAKE_MODULE_PATH= passed from CLI
to eg. test custom Platform/ support.

(cherry picked from commit 84affc1837a727640f46eff2723c1364d2cd1695)
2020-06-28 21:17:33 +03:00
Azat Khuzhin
d2871a37bf Do not use sysctl.h on linux (it had been deprecated)
It had been deprecated for a long time (AFAIK), but since
glibc-2.29.9000-309-g744e829637 it produces a #warning

(cherry picked from commit b9b9f19058dc04b7ad4d079a38f6b86c0e7b1072)
2020-06-28 21:17:33 +03:00
yuangongji
e35e02e680 sample/https-client: link crypt32 explicitly when build with mingw-w64
(cherry picked from commit 78b5bca6d83a70a0b9dfc438898d5c1908cc3c2a)
2020-06-28 21:17:33 +03:00
Kamil Rytarowski
5febb4e191 Fix compat with NetBSD >= 10
kevent::udata was switched from intptr_t to void*.

Handle both cases with the GCC extension typeof().

(cherry picked from commit 72e6eff0251bffec72e0b8b2cedf72f173c8b9e9)
2020-06-28 21:17:33 +03:00
William A Rowe Jr
50b9be003c Avoid transforming base C_FLAGS set deliberately
The CMAKE_C_FLAGS_DEBUG, CMAKE_C_FLAGS_RELEASE, CMAKE_C_FLAGS_MINSIZEREL
and CMAKE_C_FLAGS_RELWITHDEBINFO options are correctly and deliberately
toggled to use the libcmt (/MT) flag options in place of the usual
msvcrt (/MD) options, but this isn't necessarily desired by the user.
The default choice can be overriden with the EVENT__MSVC_STATIC_RUNTIME
cmake option.

However, the /MD flag that is the choice of CMake only enters into
play for the four types of builds above. If the user introduces another
CMAKE_BUILD_TYPE, the base CMAKE_C_FLAGS must not be manipulated, as
that value (and the CMAKE_C_FLAGS_{custom} value) have been explicitly
chosen by the user/developer deploying this library, and the mismatch
between these flags in different dependencies results in link errors.

The CMake build schema itself doesn't place an /MD flag in CMAKE_BUILD_TYPE
so any /M compile option in that variable needs to be retained.

Signed-off-by: William Rowe <wrowe@pivotal.io>
Signed-off-by: Yechiel Kalmenson <ykalmenson@pivotal.io>
(cherry picked from commit af4b07a55cc0ff0298cbd26c87b3f6a08f84c394)
2020-06-28 21:17:33 +03:00
yuangongji
794e8f75b5 tinytest: support timeout on Windows
(cherry picked from commit 8d5c5650d281019832fa7b5133b85c7ad29f664e)
2020-06-28 21:17:33 +03:00
Azat Khuzhin
a4f0387c22 Merge branch 'upstream/pr/899' (evbuffer_freeze testcase enhancements)
* upstream/pr/899:
  improve the description of parameter to evbuffer_read()
  regress_buffer: improve testcase for evbuffer_freeze()

(cherry picked from commit a977d6963611c729b75108d31bf74718b7b3e06d)
2020-06-28 21:17:33 +03:00
Azat Khuzhin
5f017bde64 evbuffer_add_file: fix freeing of segment in the error path
if evbuffer_add_file_segment() fails it returns -1, so we should call
evbuffer_file_segment_free() only on error, and this -1 not 0.

Fixes: 6a81b1f5 ("Avoid double-free on error in evbuffer_add_file. Found by coverity.")
Backport-to: 2.1
(cherry picked from commit 4727150a54e21725f0ef4f43ca5028cc6f353664)
2020-06-28 21:17:33 +03:00
yuangongji
f4a6152c3b evutil_time: detect and use _gmtime64_s()/_gmtime64()
(cherry picked from commit 148d12ad31b03a813f4ffd9df14a85392aa74130)
2020-06-28 21:17:33 +03:00
yuangongji
c169bdcbb2 http: rename bind_socket_ai() to create_bind_socket_nonblock()
(cherry picked from commit 0cd536b0b33d2aa59cee3805846f81cf4e4a5ce9)
2020-06-28 21:17:33 +03:00
yuangongji
e9478640b2 https-client: load certificates from the system cert store on Windows
(cherry picked from commit 572a565130d40172e1f2b5ac83d0cdffd502105b)
2020-06-28 21:17:33 +03:00
Azat Khuzhin
fc51bf2c5b Fix checking return value of the evdns_base_resolv_conf_parse()
Reported-by: Maxim Gorbachyov <maxim.gorbachyov@gmail.com>
(cherry picked from commit c3f353450e94248ee677a068ed2c4ed29d64f79e)
2020-06-28 21:17:33 +03:00
Azat Khuzhin
e0e5f3bdd2 cmake: fix getrandom() detection
Fixes: 86f55b04 ("arc4random: replace sysctl() with getrandom (on linux)")
(cherry picked from commit 194a5d822651c03fc988c1bf087e65ed20f453f7)
2020-06-28 21:17:32 +03:00
Azat Khuzhin
66ec78fddb arc4random: replace sysctl() with getrandom (on linux)
Since sysctl() is deprecated for a long-long time, according to
sysctl(2):

    Since Linux 2.6.24, uses of this system call result in warnings in the kernel log.

Fixes: #890
Suggested-by: Pierce Lopez
(cherry picked from commit 86f55b0420f864b518475f781ce7a3c619180b12)
2020-06-28 21:17:32 +03:00
yuangongji
45da7d9d44 Upgrade autoconf (after upgrading minimum required to 2.67)
- AC_PROG_SED
- AC_USE_SYSTEM_EXTENSIONS
- AC_TRY_COMPILE -> AC_COMPILE_IFELSE
- AC_TRY_RUN -> AC_RUN_IFELSE
...

Also use:
- AC_CONFIG_AUX_DIR

Refs: #870
Fixes: 3f09e923 ("Change the minimum version of automake to 1.13 and autoconf to 2.67")
(cherry picked from commit 13b8fc39fd4000de2c836b0acdc52ae5b4c757c7)
2020-06-28 21:17:32 +03:00
Azat Khuzhin
71f5c0d349 Revert "Warn if forked from the event loop during event_reinit()"
Thinking about this more and realizing that this was a mistake, so
should be reverted.

In a nut shell I guess most of the apps calls event_reinit() from the
loop (see [1] for example), and this should be totally fine (the bit
with the signals [2] handled in event_reinit() gracefully)

  [1]: https://archives.seul.org/libevent/users/Aug-2019/msg00009.html
  [2]: https://github.com/libevent/libevent/pull/833#issuecomment-501834453

This reverts commit 497ef904d544ac51de43934549dbeccce8e6e8f8.

Reported-by: mikulas@twibright.com
Backport-to: 2.1
(cherry picked from commit ddacaef59ab6808a0801007d0a681f2415af4871)
2020-06-28 21:17:32 +03:00
yuangongji
9e468c7742 eliminate some C4267 warnings in Windows
(cherry picked from commit 6f970267b6ba68c9dd9090d789c928529745dc68)
2020-06-28 21:16:53 +03:00
yuangongji
5d1e85701d autotools: attach doxygen target into all target
v2: disable man pages by default
(cherry picked from commit f9c6a14ee089452c74e492edc674260a3717763e)
2020-06-28 21:16:47 +03:00
yuangongji
7a85300ab0 cmake: attach doxygen target into all target
v2: Disable non-html generator for doxygen by default
v3: convert cmake option to doxygen config
(cherry picked from commit 1d1c19091f13b7e19015698a23f454aa85f17ac3)
2020-06-28 21:16:14 +03:00
Jan Kasiak
8ccd8f561b Fix memory corruption in EV_CLOSURE_EVENT_FINALIZE with debug enabled
Call event_debug_note_teardown_ before evcb_evfinalize to avoid possible
UAF (if finalizer free's event).

(cherry picked from commit 445027a5dcfe0acce431b7d4065d2ac1f6b270d7)
2020-06-28 21:14:32 +03:00
Jan Kasiak
23af76de0a test: prevent duplicate event_enable_debug_mode() for TT_ENABLE_DEBUG_MODE
(cherry picked from commit 70daa93a514075eb0102eec4c6e5002b114264a9)
2020-06-28 21:14:32 +03:00
Azat Khuzhin
0126814f2f test: introduce TT_ENABLE_DEBUG_MODE flag
(cherry picked from commit 6186d3126f124494dd90b14f62c17b47f7a7f484)
2020-06-28 21:14:32 +03:00
David Disseldorp
4a6f1ccfae sample/http-server: fix parameter parsing
argv[1] is currently unconditionally passed as the docroot to
send_document_cb(). This is broken if any optional parameters are
provided, such as -p <port>.

Signed-off-by: David Disseldorp <ddiss@samba.org>
(cherry picked from commit 7d71214e02646a31eede66ad5badf695a2ab2058)
2020-06-28 21:14:32 +03:00
David Disseldorp
f9d7ac0de8 sample/signal-test: fix use of uninitialized variable
signal_int is uninitialized in the !base error path.

Signed-off-by: David Disseldorp <ddiss@samba.org>
(cherry picked from commit a0276292a5e783c30643992897c7597f0db2cc96)
2020-06-28 21:14:32 +03:00
dota17
ec52e6af2f Fix typos in comments (sample/test/event-internal.h)
(cherry picked from commit 9c151f3c3413c5ee6bad498aca84be481196bbc7)
2020-06-28 21:14:32 +03:00
dota17
317b026b82 sample/signal-test: add NULL checks
Fixes: #865
(cherry picked from commit 101fbe31005c07cde0fdbdb38a4f6c3499e07edc)
2020-06-28 21:14:32 +03:00
ygj6
fdb8fb661e 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

(cherry picked from commit 3f09e9230ab45008e0016b63fc1d3b05eb23e6ec)
2020-06-28 21:14:28 +03:00
Azat Khuzhin
877f2355e9 Add Uninstall.cmake.in into dist archive
Fixes: #863
(cherry picked from commit f05ba671931e2b4e38459899f6f63f79f99869fe)
2020-06-28 21:14:11 +03:00
Azat Khuzhin
4c908dde58
Merge branch 'release-2.1.11-stable-pull' into patches-2.1
* release-2.1.11-stable-pull:
  Bump version to 2.1.11-stable (with ABI breakage)
  Bump ChangeLog
  Bump AUTHORS.md
  ...
release-2.1.11-stable
2019-08-02 00:37:51 +03:00
Azat Khuzhin
5b723a66b4
Bump version to 2.1.11-stable (with ABI breakage) 2019-08-02 00:26:20 +03:00
Azat Khuzhin
7002616960
Bump ChangeLog 2019-08-02 00:20:30 +03:00
Azat Khuzhin
b9c364e4ec
Bump AUTHORS.md 2019-08-02 00:12:11 +03:00
Azat Khuzhin
598f247d98
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
(cherry picked from commit bdcade47224f154052c927aed3c363a18b37112e)
2019-08-02 00:08:41 +03:00
yuangongji
2a3330081a
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")
(cherry picked from commit 1947dd0ddbced0d8f9891656c820353f82261c52)
2019-08-02 00:08:41 +03:00
Azat Khuzhin
596855f7af
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")
(cherry picked from commit 55d1e20e1a5dbd1188f4143968f7cafee33edc0d)
2019-08-02 00:08:41 +03:00
yuangongji
9559349cbc
Missing <winerror.h> on win7/MinGW(MINGW32_NT-6.1)/MSYS
(cherry picked from commit 7806f3ec78368d69bfcf53cdffcdb424a528a113)
2019-08-02 00:08:41 +03:00
yuangongji
305251b9ce
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
(cherry picked from commit 669a53f341e192657140952cfe025c260da2b1c1)
2019-08-02 00:08:41 +03:00
Keith Smiley
f013fc7dde
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.

(cherry picked from commit 41c95abb9930b0c13c238e110b857acb810ad7b9)
2019-08-02 00:08:41 +03:00