From fe8e6706bd847ddfe43337d544f88318ec63946d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 7 Jan 2015 14:32:16 +1000 Subject: [PATCH] tools: switch signal handler in event-debug MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Under gdb, signalfd will still deliver the signal when gdb itself is interrupted and quit event-debug. For a debugging tool, that's not optimal. Switch to a normal signal handler instead, signalfd is overkill here anyway. Signed-off-by: Peter Hutterer Reviewed-by: Jonas Ådahl --- tools/event-debug.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/tools/event-debug.c b/tools/event-debug.c index c567550..090fc3f 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -32,7 +32,6 @@ #include #include "linux/input.h" #include -#include #include @@ -42,6 +41,7 @@ uint32_t start_time; static const uint32_t screen_width = 100; static const uint32_t screen_height = 100; struct tools_options options; +static unsigned int stop = 0; static int open_restricted(const char *path, int flags, void *user_data) @@ -331,24 +331,26 @@ handle_and_print_events(struct libinput *li) } static void -mainloop(struct libinput *li) +sighandler(int signal, siginfo_t *siginfo, void *userdata) { - struct pollfd fds[2]; - sigset_t mask; + stop = 1; +} - fds[0].fd = libinput_get_fd(li); - fds[0].events = POLLIN; - fds[0].revents = 0; +static void +mainloop(struct libinput *li) +{ + struct pollfd fds; + struct sigaction act; - sigemptyset(&mask); - sigaddset(&mask, SIGINT); + fds.fd = libinput_get_fd(li); + fds.events = POLLIN; + fds.revents = 0; - fds[1].fd = signalfd(-1, &mask, SFD_NONBLOCK); - fds[1].events = POLLIN; - fds[1].revents = 0; + memset(&act, 0, sizeof(act)); + act.sa_sigaction = sighandler; + act.sa_flags = SA_SIGINFO; - if (fds[1].fd == -1 || - sigprocmask(SIG_BLOCK, &mask, NULL) == -1) { + if (sigaction(SIGINT, &act, NULL) == -1) { fprintf(stderr, "Failed to set up signal handling (%s)\n", strerror(errno)); return; @@ -359,14 +361,8 @@ mainloop(struct libinput *li) fprintf(stderr, "Expected device added events on startup but got none. " "Maybe you don't have the right permissions?\n"); - while (poll(fds, 2, -1) > -1) { - if (fds[1].revents) - break; - + while (!stop && poll(&fds, 1, -1) > -1) handle_and_print_events(li); - } - - close(fds[1].fd); } int -- 2.7.4