uloop: make SIGCHLD signal handling optional 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>
uloop: Fix race condition in SIGCHLD handling 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>
uloop: allow passing 0 as timeout to uloop_run Useful for processing only immediate timers and fds Signed-off-by: Felix Fietkau <nbd@nbd.name>
uloop: fix a regression in timeout handling Variable confusion was breaking timers Fixes: 368fd2645878 ("uloop: allow specifying a timeout for uloop_run()") Signed-off-by: Felix Fietkau <nbd@nbd.name>
uloop: allow specifying a timeout for uloop_run() 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>
uloop: add uloop_cancelling function Returns true if uloop_run is still running and uloop_cancelled is set Signed-off-by: Felix Fietkau <nbd@nbd.name>
uloop: handle waker pipe write() return value 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
loop: make uloop_run() return the cancelling signal 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>
uloop: add missing waker_pipe initialization Signed-off-by: Felix Fietkau <nbd@nbd.name>
uloop: use a waker for notifying sigchld and loop cancel events 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>
uloop: revert signalfd support for now It hasn't fixed the reported race condition and it introduced some new issues. Signed-off-by: Felix Fietkau <nbd@nbd.name>
uloop: add back support for overriding signal handlers when signalfd is in use Signed-off-by: Felix Fietkau <nbd@nbd.name>
uloop: retry waitpid on signal interrupt Signed-off-by: Felix Fietkau <nbd@nbd.name>
uloop: try to use signalfd for signal handling if available Signed-off-by: Felix Fietkau <nbd@nbd.name>
uloop: move epoll code into a separate file Signed-off-by: Felix Fietkau <nbd@nbd.name>
uloop: move kqueue code into a separate file Signed-off-by: Felix Fietkau <nbd@nbd.name>
allow process callback to call uloop_end() Signed-off-by: John Crispin <blogic@openwrt.org>
uloop: ignore SIGPIPE by default 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>
uloop: optimize uloop_timeout_set() implementaiton a bit. Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
uloop: Do not override signal handlers not installed by us Signed-off-by: Michel Stam <m.stam@fugro.nl>