4183 Commits

Author SHA1 Message Date
Azat Khuzhin
e41a1969b0 test-time: do not use deprecated API
- event_init() -> event_base_new()
- event_set() -> event_new()
- check return value of event_base_dispatch()
- use EXIT_SUCCESS/EXIT_FAILURE

(cherry picked from commit 4e5a41ca0f668da1a18832e5cb02b4afeae074ff)
2020-06-28 21:24:21 +03:00
Azat Khuzhin
29e2c7f2b7 test-time: enable debug mode if EVENT_DEBUG_LOGGING_ALL env set
(cherry picked from commit a11edbfa369f7a99886359b3f4baa69686dc275f)
2020-06-28 21:24:21 +03:00
yuangongji
30662a3ca9 increase segment refcnt only if evbuffer_add_file_segment() succeeds
(cherry picked from commit 114b3836755f1e526e658b248464465136bd87b8)
2020-06-28 21:24:21 +03:00
ayuseleznev
6f8e0e97e5 evdns: fix a crash when evdns_base with waiting requests is freed
Fix undefined behaviour and application crash that might take
place in some rare cases after calling evdns_base_free when
there are requests in the waiting queue.

Current cleanup procedure in evdns_base_free_and_unlock
function includes 2 steps:
1. Finish all inflight requests.
2. Finish all waiting requests.
During the first step we iterate over each list in req_heads
structure and finish all requests in these lists. With current
logic finishing an inflight request (function request_finished)
removes it from the inflight requests container and forces
a wating connection to be sent (by calling
evdns_requests_pump_waiting_queue). When these new requests are
sent it is possible that they will be inserted to the list in
req_heads that we've already cleaned.
So in some cases container of the inflight requests is not empty
after this procedure and some requests are not finished and
deleted. When timeouts for these requests expire
evdns_request_timeout_callback is called but corresponding
evdns_base has been already deleted which causes undefined
behaviour and possible applicaton crash.

It is interesting to note that in old versions of libevent such
situation was not possible. This bug was introduced by the commit
14f84bbdc77d90b1d936076661443cdbf516c593. Before this commit
nameservers were deleted before finishing the requests. Therefore
it was not possible that requests from the waiting queue be sent
while we finish the inflight requests.

(cherry picked from commit 4da9f87ccbe71edb3b3aaf74b8b64d7e9c41dcaf)
2020-06-28 21:24:21 +03:00
chenguolong
2e9ceb1655 event_base_once: fix potential null pointer threat
supposing if base is null, EVBASE_ACQUIRE_LOCK and EVBASE_RELEASE_LOCK
would get a coredump, so we add a guard for protection.

Signed-off-by: chenguolong <cgl.chenguolong@huawei.com>
(cherry picked from commit 968bbd5c918568eb95b493af05c464ddfc36671b)
2020-06-28 21:24:21 +03:00
yuangongji
9e993c3cdb test-ratelim: add missing free
(cherry picked from commit 5fbe6313ae7e81cde3e056b29171a6346c54aa0b)
2020-06-28 21:24:21 +03:00
Azat Khuzhin
8a9b565501 Do not use shared global structures on CYGWIN
Fixes: #950
(cherry picked from commit 2c473056abdf710b6c476b7b19777d5313e71d8a)
2020-06-28 21:24:21 +03:00
Azat Khuzhin
0ef87f5f0e test: move thread into realtime class even on EVENT__DISABLE_THREAD_SUPPORT
(cherry picked from commit ca2b72c546d80dfb4fa255b20ef4a829ed102a70)
2020-06-28 21:24:17 +03:00
Azat Khuzhin
5a400c1f28 test: fix compilation without thread support (EVENT__DISABLE_THREAD_SUPPORT=ON)
(cherry picked from commit d0adbc05654eca27384b6496cfd8a22ed4dfb4fb)
2020-06-28 21:22:40 +03:00
Azat Khuzhin
1121ebed84 test: fix bufferevent/bufferevent_connect_fail_eventcb* under osx/freebsd
For OSX the socket should be closed, otherwise the "connection refused"
will not be triggered.

And freebsd can return error from the connect().

(cherry picked from commit 30fe125041ab38045487bd3af60d2f564dffc81c)
2020-06-28 21:22:40 +03:00
Azat Khuzhin
d5d18a5644 test: fix dst thread in move_pthread_to_realtime_scheduling_class (osx)
Fixes the following tests on osx:
- del_wait
- no_events

Refs: #940
(cherry picked from commit 10504fcab927e8b226ef2e988b1b3f175c3e9f71)
2020-06-28 21:22:40 +03:00
Azat Khuzhin
265cbe1077 test: fix compilation under win32 (rearrange thread_setup() code)
(cherry picked from commit 34d51e1bc9c650c4d012fe3024f7777c819ba969)
2020-06-28 21:22:37 +03:00
Azat Khuzhin
8991346df9 test: use THREAD_* wrappers over pthread* in del_notify
(cherry picked from commit 391003e9b78acff0ee5096c592fc4b601a02648d)
2020-06-28 21:22:03 +03:00
Azat Khuzhin
e85afbe3d5 Merge branch 'osx-clock'
Moves the thread into real-time scheduling class, as recommended in [1], it
fixes the separate test provided by @ygj6 [2] everywhere (github actions,
travis-ci, appveyor) under osx.

  [1]: https://developer.apple.com/library/archive/technotes/tn2169/_index.html
  [2]: dde1a6e4d0

Although even after this changes the following time-related tests failed
on travis-ci:
- no_events
- del_wait

But anyway I guess #940 can be closed, since this fixes the issue in common.

* osx-clock:
  test: Use THREAD_* wrappers in del_notify/del_wait
  test: move threads created with THREAD_START() to realtime scheduling class too
  test: put thread into real time scheduling class on osx for better latencies

Closes: #940
(cherry picked from commit a6f81aa45455c8afb69980f7026a0e706f4f9387)
2020-06-28 21:21:56 +03:00
Azat Khuzhin
677378ea42 cmake: do not print used method (EVENT_SHOW_METHOD) while running tests
autotools don't, plus this will make CI logs cleaner

(cherry picked from commit f8a6f12712e775720b36e0c4375a5fd6870bb737)
2020-06-28 21:20:52 +03:00
Azat Khuzhin
70ac214476 cmake: run regress test quietly like autotools (makes CI logs cleaner)
(cherry picked from commit fa33819e3b0f706a0c8b6bcb6eb2c6646609542a)
2020-06-28 21:20:52 +03:00
Azat Khuzhin
e24242299b Merge branch 'http-connect'
After this patchset http-connect works with pproxy [1]:

    $ pproxy -l http://:8000/ -vvv &
    $ http-connect //127.1:8000 http://kernel.org:80/

  [1]: https://pypi.org/project/pproxy/

* http-connect:
  http-connect: do not check connection on GET cb
  http-connect: set Host header (for CONNECT and GET) (like curl)
  http-connect: cleanup and helpers
  http: do not close connection for CONNECT
  http: do not assume body for CONNECT

Fixes: #946
(cherry picked from commit 462f2e97660cc2b6af563ab631050a83c3e0935b)
2020-06-28 21:20:52 +03:00
Azat Khuzhin
1b42270b7a http: do not assume body for CONNECT
(cherry picked from commit 998e68340e5cd289a16f340cc5c625e984e1f762)
2020-06-28 21:20:52 +03:00
Dimo Markov
3f1fb1f9ab Added uninstall target check to cmakelists
(cherry picked from commit f0e79bafd8823aedf535e9b344d4cf9a4f9747e5)
2020-06-28 21:20:52 +03:00
Azat Khuzhin
921bdcdd81 Fix compilation without OPENSSL_API_COMPAT
Use the following for openssl 1.1+:
- X509_getm_notBefore over X509_get_notBefore
- X509_getm_notAfter  over X509_get_notAfter
- use OPENSSL_VERSION_NUMBER over SSLeay()
- add missing headers

Refs: openssl/openssl@0b7347effe
(cherry picked from commit 08981f8d752ad23e21887b42944783e843b2e281)
2020-06-28 21:20:46 +03:00
yuangongji
d42240d1c6 evutil_time: Implements usleep() using wait funtion on Windows
(cherry picked from commit 6412f34f242e9b5b87f0378715baf97ba0bf1a8c)
2020-06-28 21:19:54 +03:00
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