From 1257a38a6e64511207bb3b077ca7e8e1a3338fc1 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 19 May 2016 10:59:46 +0200 Subject: [PATCH] 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 --- uloop-epoll.c | 77 -------------------------------------------------- uloop-kqueue.c | 7 ----- uloop.c | 36 ++++++++--------------- 3 files changed, 11 insertions(+), 109 deletions(-) diff --git a/uloop-epoll.c b/uloop-epoll.c index 2d1c4a7..bb652fd 100644 --- a/uloop-epoll.c +++ b/uloop-epoll.c @@ -16,8 +16,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include - /** * FIXME: uClibc < 0.9.30.3 does not define EPOLLRDHUP for Linux >= 2.6.17 */ @@ -25,79 +23,8 @@ #define EPOLLRDHUP 0x2000 #endif -static void -uloop_signal_fd_cb(struct uloop_fd *fd, unsigned int events) -{ - struct signalfd_siginfo fdsi; - struct sigaction act; - int ret; - -retry: - ret = read(fd->fd, &fdsi, sizeof(fdsi)); - if (ret < 0 && errno == EINTR) - goto retry; - - if (ret != sizeof(fdsi)) - return; - - switch (fdsi.ssi_signo) { - case SIGQUIT: - case SIGINT: - case SIGTERM: - sigaction(fdsi.ssi_signo, NULL, &act); - if (act.sa_handler != SIG_IGN && - act.sa_handler != SIG_DFL) { - act.sa_handler(fdsi.ssi_signo); - break; - } - - /* fall through */ - default: - uloop_handle_signal(fdsi.ssi_signo); - break; - } -} - -static bool -uloop_setup_signalfd(bool add) -{ - static struct uloop_fd sfd = { - .cb = uloop_signal_fd_cb - }; - static sigset_t prev_mask; - sigset_t mask; - - if (signal_fd < 0) - return false; - - sigemptyset(&mask); - - if (!add) { - uloop_fd_delete(&sfd); - sigprocmask(SIG_BLOCK, &prev_mask, NULL); - } else { - sigaddset(&mask, SIGQUIT); - sigaddset(&mask, SIGINT); - sigaddset(&mask, SIGTERM); - sigaddset(&mask, SIGCHLD); - sigprocmask(SIG_BLOCK, &mask, &prev_mask); - - sfd.fd = signal_fd; - uloop_fd_add(&sfd, ULOOP_READ | ULOOP_EDGE_TRIGGER); - } - - if (signalfd(signal_fd, &mask, SFD_NONBLOCK | SFD_CLOEXEC) < 0) { - sigprocmask(SIG_BLOCK, &prev_mask, NULL); - return false; - } - - return true; -} - int uloop_init(void) { - sigset_t mask; - if (poll_fd >= 0) return 0; @@ -106,10 +33,6 @@ int uloop_init(void) return -1; fcntl(poll_fd, F_SETFD, fcntl(poll_fd, F_GETFD) | FD_CLOEXEC); - - sigemptyset(&mask); - signal_fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC); - return 0; } diff --git a/uloop-kqueue.c b/uloop-kqueue.c index e93bc82..0cb1c14 100644 --- a/uloop-kqueue.c +++ b/uloop-kqueue.c @@ -15,13 +15,6 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ - -static bool -uloop_setup_signalfd(bool add) -{ - return false; -} - int uloop_init(void) { struct timespec timeout = { 0, 0 }; diff --git a/uloop.c b/uloop.c index af84737..cd3de85 100644 --- a/uloop.c +++ b/uloop.c @@ -56,7 +56,6 @@ 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; @@ -64,8 +63,6 @@ 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 @@ -331,17 +328,14 @@ static void uloop_handle_processes(void) } -static void uloop_handle_signal(int signo) +static void uloop_handle_sigint(int signo) { - switch (signo) { - case SIGINT: - case SIGQUIT: - case SIGTERM: - uloop_cancelled = true; - break; - case SIGCHLD: - do_sigchld = true; - } + uloop_cancelled = true; +} + +static void uloop_sigchld(int signo) +{ + do_sigchld = true; } static void uloop_install_handler(int signum, void (*handler)(int), struct sigaction* old, bool add) @@ -392,14 +386,11 @@ static void uloop_ignore_signal(int signum, bool ignore) static void uloop_setup_signals(bool add) { - static struct sigaction old_sigint, old_sigchld, old_sigterm, old_sigquit; - - uloop_setup_signalfd(add); + static struct sigaction old_sigint, old_sigchld, old_sigterm; - 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_sigquit, add); - uloop_install_handler(SIGCHLD, uloop_handle_signal, &old_sigchld, add); + 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); uloop_ignore_signal(SIGPIPE, add); } @@ -486,11 +477,6 @@ void uloop_run(void) void uloop_done(void) { - if (signal_fd >= 0) { - close(signal_fd); - signal_fd = -1; - } - if (poll_fd < 0) return; -- 2.25.1