This patch adds support for exporting the signalfd_siginfo struct read
from the signal fd descriptor on signals. This allows watcher callbacks
to, e.g., figure out who sent a signal. See signalfd(2) for details on
struct signalfd_siginfo.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This patch replaces the BSD doubly linked list implementation with a
simplified homegrown version. This not only reduces the dependency on
an external "library", but also greatly simplifies licensing and gives
us a clean name space that does not intrude on users who want to use
their own version of queue.h in their application that also includes
the libuEv header file.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The __attribute__ ((unused)) is useful sometimes to declare variables as
intended to be unused, e.g. in callback functions. However, they tend
to clutter up the code making hard to read. We therefore remove all
uses of it and instead set -Wno-unused-parameter.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The semantics for timerfd in Linux is to use close() to stop,
so no need for the extra overhead with uev_timer_set().
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
A watcher callback may be a timeout callback, or similar, that deletes
itself and the watcher. So we should not dereference anything in the
watcher after the callback.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
No need to check fd with fcntl(). On EPOLLERR the descriptor has an
error condition that must bed ACK'ed by the callback. On EPOLLHUP
we got a hang-up on the remote end, usually a stream or pipe, either
way the callback must ACK this too, regardless.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Both cron and regular timers were closed twice on uev_exit(), first
when iterating over all watchers, next after each cb() has run in
uev_run(). This patch adds a check if a watcher is active before
attempting to stop it (again).
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch is a follow-up to 2f9cce9, and a complete refactor of
fe8f3f1 which first introduced the EPOLLERR and EPOLLHUP handling.
Then mainly for managing errors and hangups on stream sockets.
Now, instead of trying to reopen the epoll() fd, and breaking out
hard from the event loop on catastrophic error, we now delegate
I/O watcher EPOLLERR and EPOLLHUP to the watcher callback, just
like other watchers.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
In 2f9cce9 the invalidate_watcher() function was introduced to stop
invalid timer/cron and signal watchers. This patch refactors that
change to instead call the stop method for cron/timer and attempt to
restart failing signal watchers.
The cron/timer and signal watchers are quite different from regular
I/O watchers in that their internal "fd" is hidden from and not under
the control of the user, so we should try to handle them better. For
the former two we cannot do much other than stop and call the user's
registered callback with UEV_ERROR, but for the latter we can at least
try to restart it.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch fixes a blocking issue discovered in the Finit project.
At shutdown, or when there is any problem with a timer or signal
watcher, the event loop is abruptly terminated.
Instead of unconditionally exiting the event loop on problems with a
single watcher, invalidate the watcher and run the callback one last
time with UEV_ERROR in the events argument.
This is a semantic change wrt. watchers and their callbacks, so the
major version number will be bumped accordingly to signal the severity
of this change. From now on it is STRONGLY recommended that each call
back function check for UEV_ERROR.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The purpose of the event loop is to process events on all registered
watches. When all watchers have completed the event loop should exit.
Having implemented a workaround for issue #12 in commit e0cebc3 it has
become evident we need to check the list of watchers at the beginning
of the event loop rather than the end, since the workaround skips past
the end.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
When handling the stdin redirect workaround we should use FIONREAD to
figure out if there is any data to read.
When there is no more data to read from stdin we remove the watcher from
internal bookkeeping but allow the callback to run one last time so it
can detect a short read.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch implements a workaround for issue #12, i.e. when an I/O
watcher for redirected stdin is registered and causes epoll_ctl()
to return EPERM.
The workaround registers the watcher as `active = -1` and bypasses
the epoll_wait() call in the main loop until all data has been read
from stdin and the temporary -1 watcher(s) have completed.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>