uloop: revert signalfd support for now
authorFelix Fietkau <nbd@nbd.name>
Thu, 19 May 2016 08:59:46 +0000 (10:59 +0200)
committerFelix Fietkau <nbd@nbd.name>
Thu, 19 May 2016 08:59:48 +0000 (10:59 +0200)
It hasn't fixed the reported race condition and it introduced some new
issues.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
uloop-epoll.c
uloop-kqueue.c
uloop.c

index 2d1c4a723dbeabb92bd78362855faada1ff91bc2..bb652fd3444aebc0a916cb411a915c482df02826 100644 (file)
@@ -16,8 +16,6 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <sys/signalfd.h>
-
 /**
  * FIXME: uClibc < 0.9.30.3 does not define EPOLLRDHUP for Linux >= 2.6.17
  */
 #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;
 }
 
index e93bc828f7be3137f70af25860d66311e09daf16..0cb1c14ff64ad65732ffac080ef639b222285b30 100644 (file)
  * 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 af84737c28ce6112337ee2362e23444885d7c57f..cd3de85e1435140c2807a75444848705f1f9b6ab 100644 (file)
--- 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;