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
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2016-05-17 14:23:28 +0300
committerFelix Fietkau <nbd@nbd.name>2016-05-17 14:23:38 +0300
commit6a75b3b6437d3c98d852c1bca131c8f81646f2f5 (patch)
tree1223e9f430ceab79033ef9952d0b98244d93ba23 /uloop.c
parent8ae74b4378827d48f655c509d786a6e054e9d0b2 (diff)
uloop: try to use signalfd for signal handling if available
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'uloop.c')
-rw-r--r--uloop.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/uloop.c b/uloop.c
index d2784b7..6ef7210 100644
--- a/uloop.c
+++ b/uloop.c
@@ -56,6 +56,7 @@ static struct uloop_fd_stack *fd_stack = NULL;
static struct list_head timeouts = LIST_HEAD_INIT(timeouts);
static struct list_head processes = LIST_HEAD_INIT(processes);
+static int signal_fd = -1;
static int poll_fd = -1;
bool uloop_cancelled = false;
static bool do_sigchld = false;
@@ -63,6 +64,8 @@ static bool do_sigchld = false;
static struct uloop_fd_event cur_fds[ULOOP_MAX_EVENTS];
static int cur_fd, cur_nfds;
+static void uloop_handle_signal(int signo);
+
#ifdef USE_KQUEUE
#include "uloop-kqueue.c"
#endif
@@ -325,14 +328,17 @@ static void uloop_handle_processes(void)
}
-static void uloop_handle_sigint(int signo)
+static void uloop_handle_signal(int signo)
{
- uloop_cancelled = true;
-}
-
-static void uloop_sigchld(int signo)
-{
- do_sigchld = true;
+ switch (signo) {
+ case SIGINT:
+ case SIGQUIT:
+ case SIGTERM:
+ uloop_cancelled = true;
+ break;
+ case SIGCHLD:
+ do_sigchld = true;
+ }
}
static void uloop_install_handler(int signum, void (*handler)(int), struct sigaction* old, bool add)
@@ -385,9 +391,13 @@ static void uloop_setup_signals(bool add)
{
static struct sigaction old_sigint, old_sigchld, old_sigterm;
- uloop_install_handler(SIGINT, uloop_handle_sigint, &old_sigint, add);
- uloop_install_handler(SIGTERM, uloop_handle_sigint, &old_sigterm, add);
- uloop_install_handler(SIGCHLD, uloop_sigchld, &old_sigchld, add);
+ if (uloop_setup_signalfd(add))
+ return;
+
+ uloop_install_handler(SIGINT, uloop_handle_signal, &old_sigint, add);
+ uloop_install_handler(SIGTERM, uloop_handle_signal, &old_sigterm, add);
+ uloop_install_handler(SIGQUIT, uloop_handle_signal, &old_sigterm, add);
+ uloop_install_handler(SIGCHLD, uloop_handle_signal, &old_sigchld, add);
uloop_ignore_signal(SIGPIPE, add);
}
@@ -474,6 +484,11 @@ void uloop_run(void)
void uloop_done(void)
{
+ if (signal_fd >= 0) {
+ close(signal_fd);
+ signal_fd = -1;
+ }
+
if (poll_fd < 0)
return;