summaryrefslogtreecommitdiff
path: root/event.c
Commit message (Collapse)AuthorAgeFilesLines
* Silence weird GCC warning about an uninitialized variableDmitry Antipov2023-05-141-0/+4
| | | | | | | | | | | | | | | | | | | | For the CMake release build with -DEVENT__ENABLE_GCC_WARNINGS=ON and -DEVENT__DISABLE_MM_REPLACEMENT=ON, GCC version 11 and 12 may complain about possibly uninitialized variable: In function ‘event_debug_assert_not_added_’, inlined from ‘event_assign’ at event.c:2184:2, inlined from ‘event_new’ at event.c:2276:6: cc1: error: ‘ev’ may be used uninitialized [-Werror=maybe-uninitialized] event.c: In function ‘event_new’: event.c:361:13: note: by argument 1 of type ‘const struct event *’ to event_debug_assert_not_added_.part.0’ declared here 361 | static void event_debug_assert_not_added_(const struct event *ev) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This warning is most likely a false positive and can be silenced by explicitly disabling inlining for 'event_assign()'. Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com>
* style fix: use tab for indentliaotonglang2023-05-051-16/+16
|
* signal: new signal handling backend based on signalfdDmitry Antipov2022-11-121-0/+7
| | | | | | | | Linux-specific signal handling backend based on signalfd(2) system call, and public function event_base_get_signal_method() to obtain an underlying kernel signal handling mechanism. Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com>
* Suppress -Wdangling-pointer in event_signal_closure()Azat Khuzhin2022-11-121-0/+14
| | | | | | | | | | | | | | gcc 12 complains: [34/46] Building C object CMakeFiles/event_static.dir/event.c.o /src/le/libevent/event.c: In function ‘event_signal_closure’: /src/le/libevent/event.c:1384:32: warning: storing the address of local variable ‘ncalls’ in ‘*ev.ev_.ev_signal.ev_pncalls’ [-Wdangling-pointer=] 1384 | ev->ev_pncalls = &ncalls; | ~~~~~~~~~~~~~~~^~~~~~~~~ /src/le/libevent/event.c:1378:15: note: ‘ncalls’ declared here 1378 | short ncalls; | ^~~~~~ /src/le/libevent/event.c:1378:15: note: ‘ev’ declared here
* Fix non-std printf %p arguments (#1327)mareksm2022-08-281-21/+21
| | | | | * Fix non-std printf %p arguments when running with -Werror -pedantic-errors Co-authored-by: Mareks Malnacs <mareks.malnacs>
* ev_io_timeout consistencyYong Wu2021-09-121-1/+1
|
* modify typo - timeeoutsYong Wu2021-09-051-1/+1
|
* Add wepoll support to light up the epoll backend on WindowsNick Grifka2020-05-081-0/+6
| | | | | | | | | | | | | | | | | | | | | | libevent is lacking a scalable backend on Windows. Let's leverage the wepoll library until Windows comes up with an epoll/kqueue compete user mode API. - All regress tests pass for standard wepoll - These 2 tests fail intermittently for changelist wepoll, so disabling changelist wepoll for now http/cancel_inactive_server http/stream_in - verify target on Windows runs tests for both wepoll and win32 backends - wepoll backend preferred over win32 backend - wepoll version 1.5.6 v2: cleaner backend abstraction. Disallow wepoll on MinGW/Cygwin. v3: Add wepoll.h to dist v4: Make sure wepoll source files are excluded from cygwin/mingw builds v5: Keep win32 as default backend on windows. v6: Include wepoll in mingw builds. Verified that regress tests pass w/ WEPOLL backend. v7: Enable wepoll on mingw when building with cmake v8: Add wepoll testrunner for autotools test target
* event_base_once: fix potential null pointer threatchenguolong2020-02-161-0/+3
| | | | | | | 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>
* Revert "Warn if forked from the event loop during event_reinit()"Azat Khuzhin2019-09-021-6/+0
| | | | | | | | | | | | | | | | | 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
* Fix memory corruption in EV_CLOSURE_EVENT_FINALIZE with debug enabledJan Kasiak2019-08-281-1/+1
| | | | | Call event_debug_note_teardown_ before evcb_evfinalize to avoid possible UAF (if finalizer free's event).
* Warn if forked from the event loop during event_reinit()Azat Khuzhin2019-07-011-0/+6
| | | | | | | | 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
* Protect min_heap_push_ against integer overflow.Tobias Stoeckmann2019-04-221-8/+10
| | | | | | | | 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)
* evwatch: fix race conditionDan Rosen2019-04-171-6/+8
| | | | | | | | 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).
* evwatch: Add "prepare" and "check" watchers.Dan Rosen2019-04-031-1/+33
| | | | | | | | | | 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
* Add support for EV_TIMEOUT to event_base_active_by_fdJohn Ohl2019-03-031-1/+29
| | | | Closes: #194 (cherry-pick)
* Do not check O_NONBLOCK for invalid fdsAzat Khuzhin2018-12-091-6/+7
| | | | Fixes: 6f988ee1 ("Merge branch 'check-O_NONBLOCK-in-debug'")
* event: add some debug information into loop for event_base_free_queues_()Azat Khuzhin2018-11-131-0/+1
| | | | | Refs: 7c8d0152dda18ecc52d3099fea235b04ddb850d9 ("Free event queues even for recursive finalizers")
* assert that fds are nonblocking in debug modeGreg Hazel2018-11-041-12/+27
| | | | | | | | | | Check that each fd that had been added with some event do has O_NOBLOCK after event_enable_debug_mode() Rebased and do not check signals (EV_SIGNAL) by azat. Refs: nmathewson/Libevent#90 Refs: #96
* Add ET flag into event_base_dump_events()Azat Khuzhin2018-10-311-1/+2
|
* Notify event base if there are no more events, so it can exit without delayAzat Khuzhin2018-04-261-0/+4
| | | | Fixes: #623
* Fix base unlocking in event_del() if event_base_set() runned in another threadAzat Khuzhin2018-02-281-5/+4
| | | | | | | | | | | | | | | | | Image next situation: T1: T2: event_del_() lock the event.ev_base.th_base_lock event_del_nolock_() event_set_base() unlock the event.ev_base.th_base_lock In this case we will unlock the wrong base after event_del_nolock_() returns, and deadlock is likely to happens, since event_base_set() do not check any mutexes (due to it is possible to do this only if event is not inserted anywhere). So event_del_() has to cache the base before removing the event, and cached base.th_base_lock after.
* Convert event_debug_*() helpers from macros to static functionsAzat Khuzhin2018-02-271-125/+150
|
* If precise_time is false, we should not set EVENT_BASE_FLAG_PRECISE_TIMERyongqing.jiao2017-12-111-1/+3
| | | | | Fixes: 630f077c296de61c7b99ed83bf30de11e75e2740 ("Simple unit tests for monotonic timers")
* Fix race in access to ev_res from event loop with event_active()James Synge2017-08-151-1/+3
| | | | | | | | | | | | | | | | | | | | | | | Detected using ThreadSanitizer, resolved by capturing the value of ev_res in a local variable while the event is locked, then passing that captured variable to the callback. TSAN report: I0728 14:35:09.822118 WARNING: ThreadSanitizer: data race (pid=815501) I0728 14:35:09.822186 Write of size 2 at 0x7b2c00001bf2 by thread T80 (mutexes: write M1110835549570434736): I0728 14:35:09.822248 #0 event_active_nolock_ libevent/event.c:2893:14 (0a2b90577e830d775300664df77d0b91+0x1fdab28) I0728 14:35:09.822316 #1 event_active libevent/event.c:2858:2 (0a2b90577e830d775300664df77d0b91+0x1fdd10e) I0728 14:35:09.822379 #2 Envoy::Event::TimerImpl::enableTimer(std::chrono::duration<long, std::ratio<1l, 1000l> > const&) envoy/source/common/event/timer_impl.cc:24:5 (0a2b90577e830d775300664df77d0b91+0x459fa0) ... I0728 14:35:09.824146 Previous read of size 2 at 0x7b2c00001bf2 by main thread: I0728 14:35:09.824232 #0 event_process_active_single_queue libevent/event.c:1646:33 (0a2b90577e830d775300664df77d0b91+0x1fdf83d) I0728 14:35:09.824350 #1 event_process_active libevent/event.c (0a2b90577e830d775300664df77d0b91+0x1fd9ad8) I0728 14:35:09.824445 #2 event_base_loop libevent/event.c:1961 (0a2b90577e830d775300664df77d0b91+0x1fd9ad8) I0728 14:35:09.824550 #3 Envoy::Event::DispatcherImpl::run(Envoy::Event::Dispatcher::RunType) envoy/source/common/event/dispatcher_impl.cc:166:3 (0a2b90577e830d775300664df77d0b91+0x4576d9) ... Fixes: #543 (pull-request)
* Return from event_del() after the last event callback terminationJosé Luis Millán2017-04-301-14/+15
| | | | | | | | | | | | | | Delete the event from the queue before blocking for the current event callback termination. Ensures that no callback is being executed when event_del() returns, hence making this function a secure mechanism to access data which is handled in the event callack. Fixes: #236 Fixes: #225 Refs: 6b4b77a Fixes: del_wait
* Make event_count macros cleanerAzat Khuzhin2017-03-261-7/+3
| | | | Fixes: #489
* Export symbols for -fvisibility=hidden (under cmake)Azat Khuzhin2017-03-131-0/+1
| | | | Fixes: #442
* Fix -Werror=implicit-fallthrough (fixes gcc-7)Azat Khuzhin2017-01-291-0/+1
| | | | Fixes: #447
* event_reinit: make signals works after fork() without evsig_add()Nicholas Marriott2015-12-271-0/+5
| | | | | | | | event_reinit() removes the event, but only evsig_add puts it back. So any signals set up before event_reinit will be ignored until another signal is added. Fixes: #307
* event_reinit: always re-init signal's socketpairNicholas Marriott2015-12-271-6/+5
| | | | | | | | | | Before this patch event_reinit() only closes the signal socketpair fds and recreates them if signals have been added, but this is wrong, since socketpair fds created on backend init, and if we will not re-create them bad things in child/parent signal handling will happens (and indeed this is what happens for non-reinit backends like select). Fixes: #307
* Free event queues even for recursive finalizersAzat Khuzhin2015-10-301-13/+36
| | | | | | | | | | | For finalizers we can register yet another finalizer out from finalizer, and iff finalizer will be in active_later_queue we can add finalizer to activequeues, and we will have events in activequeues after event_base_free() returns, which is not what we want (we even have an assertion for this). A simple case is bufferevent with underlying (i.e. filters) in inactive queue. Fixes: regress bufferevent/bufferevent_socket_filter_inactive
* Fix checking for make_base_notifiable()Azat Khuzhin2015-10-041-1/+1
| | | | | | Fixes: a068f2e5 ("event_debug_created_threadable_ctx_: fix compilation without debug mode") Found-after: 3e56da23 ("travis: add builds without debug mode into matrix")
* event_debug_created_threadable_ctx_: fix compilation without debug modeAzat Khuzhin2015-09-291-1/+5
| | | | | | | | The following command failed before: $ ./configure --disable-debug-mode Fixes: dcfb19a27b7760299bc9e7291c9abd88c59fd91a ("Debug mode option to error on evthread init AFTER other event calls.")
* Debug mode option to error on evthread init AFTER other event calls.Mark Ellzey2015-05-151-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - A handy event_enable_debug_mode() feature which will error and abort the application if any thread-aware libevent functions are called BEFORE the evthread API has been initialized (manually, or through evthread_use_windows_threads() / evthread_use_pthreads() - This is done by setting the global debug variable 'event_debug_created_threadable_ctx_' whenever the following functions are called: evthreadimpl_lock_alloc_() evthreadimpl_cond_alloc_() event_base_new_with_config() <- this checks to see if the thread callbacks are enabled first, so we have to manually set the variable. - Example: int main(int argc, char ** argv) { struct event_base * base; event_enable_debug_mode(); base = event_base_new(); evthread_use_pthreads(); return 0; } When executed, the program will throw an error and exit: [err] evthread initialization must be called BEFORE anything else!
* tabGreg Hazel2015-03-241-1/+1
|
* fix the return value of event_deferred_cb_schedule_Greg Hazel2015-03-241-4/+7
|
* Merge remote-tracking branch 'azat/be-pair-fix-freeing-shared-lock-v5'Nick Mathewson2015-02-041-0/+1
|\
| * event_free_debug_globals_locks(): disable lock debuggingAzat Khuzhin2015-01-261-0/+1
| | | | | | | | | | | | This will allow to use library event after event_free_debug_globals_locks()/libevent_global_shutdown() without invalid read/write's.
* | event: call event_disable_debug_mode() in libevent_global_shutdown()Azat Khuzhin2015-01-081-3/+6
|/ | | | | | | | | This will avoid leaking of event_debug_map_HT_GROW I buildin it into libevent_glboal_shutdown() because event_disable_debug_mode() -> event_free_debug_globals() -> event_free_debug_globals_locks() will clean event_debug_map_lock_ that used in event_disable_debug_mode().
* Implement new/free for struct evutil_monotonic_timer and export monotonic ↵Andrea Shepard2014-12-041-0/+15
| | | | time functions
* Merge remote-tracking branch 'public/patches-2.0'Nick Mathewson2014-11-301-4/+10
|\ | | | | | | | | | | Conflicts: ChangeLog event.c
| * Fix race caused by event_activevjpai2014-11-301-2/+20
| | | | | | | | There is a race between manual event_active and natural event activation. If both happen at the same time on the same FD, they would both be protected by the same event base lock except for 1 LoC where the fields of struct event are read without any kind of lock. This commit does those reads into local variables inside the lock and then invokes the callback with those local arguments outside the lock. In 2.0-stable, none of this is inside the lock; in HEAD, only the callback is read inside the lock. This gets the callback and all 3 arguments inside the lock before calling it outside the lock.
* | Fix use-after-free error in EV_CLOSURE_EVENT callbackJohn Ohl2014-09-181-1/+2
| |
* | Fix a use-after-free error on EV_CLOSURE_EVENT_FINALIZE callbacksNick Mathewson2014-03-181-1/+2
| | | | | | | | | | | | | | | | After running the callback, we were checking evcb->evcb_closure to decide whether to call mm_free(ev). But the callback itself might have freed ev, so we need to grab that field first Found with AddressSanitizer
* | Move assert(ev) to before we use ev in EV_CLOSURE_EVENT_FINALIZE caseNick Mathewson2014-03-061-2/+3
| | | | | | | | Based on a patch from Harlan Stenn.
* | Tweaked callbacks to prevent race condition ↵John Ohl2014-01-271-16/+26
| | | | | | | | (https://github.com/libevent/libevent/issues/104)
* | Tweaked callbacks to prevent race condition ↵John Ohl2014-01-271-2/+9
| | | | | | | | (https://github.com/libevent/libevent/issues/104)
* | Implemented EV_CLOSED event for epoll backend (EPOLLRDHUP).Diego Giagio2014-01-171-15/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Added new EV_CLOSED event - detects premature connection close by clients without the necessity of reading all the pending data. Does not depend on EV_READ and/or EV_WRITE. - Added new EV_FEATURE_EARLY_CLOSED feature for epoll. Must be supported for listening to EV_CLOSED event. - Added new regression test: test-closed.c - All regression tests passed (test/regress and test/test.sh) - strace output of test-closed using EV_CLOSED: socketpair(PF_LOCAL, SOCK_STREAM, 0, [6, 7]) = 0 sendto(6, "test string\0", 12, 0, NULL, 0) = 12 shutdown(6, SHUT_WR) = 0 epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLRDHUP, {u32=7, u64=7}}) = 0 epoll_wait(3, {{EPOLLRDHUP, {u32=7, u64=7}}}, 32, 3000) = 1 epoll_ctl(3, EPOLL_CTL_MOD, 7, {EPOLLRDHUP, {u32=7, u64=7}}) = 0 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...}) mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYM... write(1, "closed_cb: detected connection close "..., 45) = 45
* | Merge remote-tracking branch 'asweeny86/event-count-max'Nick Mathewson2014-01-061-2/+44
|\ \