Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2023-11-27uloop: reset flags after __uloop_fd_delete callFelix Fietkau
Fixes fd delete with kqueue, which relies on the previous flags value Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-11-27uloop: fix typo in signal handling reworkFelix Fietkau
Fixes procd issues Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-11-04uloop: properly initialize signal handler maskJo-Philipp Wich
The structure passed to `sigaction()` left it's `sa_mask` member uninitialized. Fixes: beb356b ("uloop: add support for user defined signal handlers") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-02uloop: add support for user defined signal handlersJo-Philipp Wich
Reuse and extend the existing signal waker pipe mechanism to add user defined signal handling functionality to uloop. This commit introduces two new api functions `uloop_signal_add()` and `uloop_signal_remove()` along with a new structure type `uloop_signal` to allow adding and removing arbitrary signal handlers. Registered signal handlers are maintained in a linked list and matched by their signo member value which allows registering multiple handlers for the same signal numbers. Upon registering a new signal handler, the existing handler is saved in the `uloop_signal` structure. When removing the user defined signal handler, the original behavior is restored. The Lua binding has been updated as well to support the new signal handler mechanism. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-02uloop: add support for interval timersJo-Philipp Wich
So far, the only way to implement periodic interval timers was to use one-shot uloop_timeout timers which are rearmed within their completion callback immediately on expiration. While simple, this approach is not very precise and interval lengths will slowly drift over time, due to callback execution overhead, scheduling granularity etc. In order to make uloop provide stable and precise interval timer capabilities, this commit introduces a new `uloop_interval` structure along with the new related `uloop_interval_set()`, `uloop_interval_cancel()` and `uloop_interval_remaining()` api functions. Periodic timers are implemented using the timerfd facility an Linux and kqueue EVFILT_TIMER events on macOS/BSD. The Lua binding has been updated to include support for the new timer type as well. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-05-23uloop: add support for integrating with a different event loopFelix Fietkau
- support reading the next timeout in order to determine the poll timeout - add a callback for fd add/delete/update Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-05-23uloop: fix uloop_run_timeoutFelix Fietkau
Avoid running infinite poll loop, fix timeout value Signed-off-by: Felix Fietkau <nbd@nbd.name>
2021-11-04uloop: add uloop_timeout_remaining64Stijn Tintel
This uses the same return type as tv_diff so we don't need to check for integer overflow. Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be> Acked-by: Jo-Philipp Wich <jo@mein.io> Acked-by: John Crispin <john@phrozen.org>
2021-11-04uloop: restore return type of uloop_timeout_remainingStijn Tintel
The uloop_timeout_remaining function is public and changing its return type breaks ABI. Change the return type back to int, and return INT_MIN or INT_MAX if the value returned by tv_diff would overflow integer. Fixes: be3dc7223a6d ("uloop: avoid integer overflow in tv_diff") Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be> Acked-by: Jo-Philipp Wich <jo@mein.io> Acked-by: John Crispin <john@phrozen.org>
2021-11-04uloop: avoid integer overflow in tv_diffStijn Tintel
The tv_diff function can potentially overflow as soon as t2->tv_sec is larger than 2147483. This is very easily hit in ujail, after only 2147484 seconds of uptime, or 24.85 days. Improve the behaviour by changing the return type to int64_t. Fixes: FS#3943 Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
2017-09-29uloop: make SIGCHLD signal handling optionalPetar Paradzik
Some programs want to manage their own child life cycle without using SIGCHLD signal handler. In these cases, uloop is reaping children for them because they don't have SIGCHLD handler set. This patch makes it possible to disable reaping children through 'uloop_handle_sigchld' variable. Signed-off-by: Petar Paradzik <petar.paradzik@sartura.hr>
2017-09-15uloop: Fix race condition in SIGCHLD handlingMichal Sojka
When uloop_process_add() is called outside of uloop_run(), i.e. not from a callback (which is the case of at least utrace and ujail), child events can be missed. The reason is that when SIGCHILD handler is installed in uloop_run(), after the uloop_process_add() is called, then an initial signal could be missed. Commit 4e3a47a ("uloop: use a waker for notifying sigchld and loop cancel events", 2016-06-09) solved a similar problem and introduced uloop_init() but forgot to move a call to uloop_setup_signals() there. This is what this commit does. Now, uloop_process_add() can be called any time after uloop_init() without missing any event. Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz> Acked-by: Yousong Zhou <yszhou4tech@gmail.com>
2017-06-17uloop: allow passing 0 as timeout to uloop_runFelix Fietkau
Useful for processing only immediate timers and fds Signed-off-by: Felix Fietkau <nbd@nbd.name>
2017-06-17uloop: fix a regression in timeout handlingFelix Fietkau
Variable confusion was breaking timers Fixes: 368fd2645878 ("uloop: allow specifying a timeout for uloop_run()") Signed-off-by: Felix Fietkau <nbd@nbd.name>
2017-06-01uloop: allow specifying a timeout for uloop_run()Felix Fietkau
This can be useful for cleanup with pending timers, or for hooking into existing code that does not use uloop Signed-off-by: Felix Fietkau <nbd@nbd.name>
2017-02-03uloop: add uloop_cancelling functionFelix Fietkau
Returns true if uloop_run is still running and uloop_cancelled is set Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-06-26uloop: handle waker pipe write() return valueEyal Birger
Recent glibc warns if result of read() or write() is unused. Added a retry in case of EINTR, all other faults are silently discarded. Signed-off-by: Eyal Birger <eyal.birger@gmail.com> ----- - I was not able to reproduce the EINTR case, but it seems to be the right thing to do - Retrying on EAGAIN in this case would be weird as there is no one to read from the other end of the pipe. We could call waker_consume() directly but since the size of the message is just one byte, I think this would be dead code
2016-06-26loop: make uloop_run() return the cancelling signalMatthias Schiffer
When a process quits in response to a signal it handles, it should to so be re-sending the signal to itself. This especially important for SIGINT, as is explained in [1]. uloop currently hides the reason for quitting uloop_run(). Fix this by returning the signal that caused the loop to quit (or 0 when uloop_end() was used), so a program using loop an comply with [1]. [1] https://www.cons.org/cracauer/sigint.html Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
2016-06-15uloop: add missing waker_pipe initializationFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-06-15uloop: use a waker for notifying sigchld and loop cancel eventsYousong Zhou
Fix a race condition when do_sigchld, uloop_cancelled were set just before epoll_wait(timeout=-1), resulting the loop stuck in the syscall without noticing the events just happened Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-05-19uloop: revert signalfd support for nowFelix Fietkau
It hasn't fixed the reported race condition and it introduced some new issues. Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-05-17uloop: add back support for overriding signal handlers when signalfd is in useFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-05-17uloop: retry waitpid on signal interruptFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-05-17uloop: try to use signalfd for signal handling if availableFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-05-17uloop: move epoll code into a separate fileFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2016-05-17uloop: move kqueue code into a separate fileFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2015-03-21allow process callback to call uloop_end()John Crispin
Signed-off-by: John Crispin <blogic@openwrt.org>
2015-01-28uloop: ignore SIGPIPE by defaultRafał Miłecki
Most app don't want to crash because of unhandled SIGPIPE. It could happen is such trivial situations like writing to socket. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
2015-01-21uloop: optimize uloop_timeout_set() implementaiton a bit.Yousong Zhou
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2014-10-12uloop: Do not override signal handlers not installed by usMichel Stam
Signed-off-by: Michel Stam <m.stam@fugro.nl>
2014-10-12uloop: Remove uloop_cancelled variable, it is not used anywhereMichel Stam
Signed-off-by: Michel Stam <m.stam@fugro.nl>
2014-05-05uloop: fix multiple calls to uloop_run()Luka Perkov
Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-04-26uloop: clear uloop_fd::error on addFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-02-23uloop: Add flag to allow callback to be called on error conditions.Karl Vogel
In some conditions, an application is interested in errors happening on a file descriptor and might be able to resolve the issue in the callback function. This patch adds a flag to notify the uloop framework that errors should be passed to the callback function, instead of silently removing the fd from the polling set. Signed-off-by: Karl Vogel <karl.vogel@gmail.com>
2013-10-22Restore signal handler after uloop_run()Kristian Evensen
uloop_run calls uloop_setup_signals() to set up signal handling before the while loop, but does not remove the signal handling after the loop has ended. This can cause problems for for example applications using the ubus file descriptor in their own event loops, and perhaps with their own signal handling. This patch stores the signal handle that was in place when the initial uloop_run() call was made, and restores the handle when this call returns. For recursive calls, the signal handler is not updated. One use-case I experienced was an application that subscribed to several ubus objects and used the ubus file descriptor in its own event loop. Even though ubus_register_subscriber() (which calls uloop_run()) had returned, the signal handler was not removed. This caused SIGINT not to be caught by the application. Signed-off-by: Kristian Evensen <kristian.evensen@gmail.com> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-08-01uloop: fix deleting pending fd events on uloop_fd_delFelix Fietkau
When a fd gets deleted internally due to errors, fd->registered gets set to false before events are moved to the staging array. This leads to pending events not getting cleared properly when the fd user finally calls uloop_fd_del. Fix this by moving the check down and always checking for pending events. Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-07-24uloop: Fix incorrect timeoutHelmut Schaa
uloop timeouts are calculated based on a time value that was fetched before any callbacks were executed. Hence, the next timeout is off by the time the callback execution took which can lead to strange side effects. Fix this by calculating the next timeout based on a fresh time value. Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com>
2013-06-18uloop: fix corner cases with recursive uloop_run callsFelix Fietkau
With multiple recursive calls to uloop_run, the callback for the same fd can be run multiple times from different levels in the stack. Prevent this by tracking the stack of uloop_fd callbacks and buffering new incoming events for fds already on the stack. Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-06-18uloop: fix event flags processing on mac os xFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-06-18libubox: make uloop_fd::flags genericFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-06-18uloop: fix edge trigger handling on mac os xFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-06-11uloop: rework event processing, fix use-after-free issuesFelix Fietkau
Recursive calls to uloop_run() need to process already fetched events first, before running kqueue/epoll to get more. The state of cur_fd/cur_nfds and the event list needs to be maintained properly to prevent accidental running of events pointing at deleted uloop_fd structs. Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-31uloop: remove file descriptors if neither read nor write notification is ↵Felix Fietkau
requested Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-23uloop: rename uloop_timeout_pending() to uloop_timeout_remaining()Jo-Philipp Wich
2013-01-23uloop: add uloop_timeout_pending() function to determine the remaining time ↵Jo-Philipp Wich
of an active timeout
2013-01-13uloop: replace copyright info (code has been completely rewritten over ↵Felix Fietkau
time), relicense to ISC Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-06uloop: use clock_gettime with the monotonic clock instead of using ↵Felix Fietkau
gettimeofday() Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-05uloop: add back state tracking on mac os x, it seems to work reliably now ↵Felix Fietkau
(after the other fixes) Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-04uloop: improve edge trigger reliability on mac os xFelix Fietkau
Sometimes after re-arming a fd, an initial event for reads is not generated, even though there is data pending. Work around this by making the trigger level-triggered first, then switching to edge trigger after processing the first event. Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-04uloop: ensure SIGCHLD is properly received on mac os xFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@openwrt.org>