From cca90938874baaa5bd29d6406e141e49d6bf12a6 Mon Sep 17 00:00:00 2001 From: Niclas Zeising Date: Mon, 27 Jul 2020 20:27:43 +0200 Subject: [PATCH] tools: Remove signalfd() use Remove signalfd() use from the mouse-dpi-tool and touchpad-edge-detector tools, in favor of using plain old signals. FreeBSD does not have signalfd() without pulling in external libraries, and with this change these tools can be compiled on FreeBSD. Instead of providing two implementations, one using signalfd() and one using signal(), just use the signal() implementation everywhere as it is more portable. Signed-off-by: Niclas Zeising --- tools/mouse-dpi-tool.c | 27 ++++++++++++++------------- tools/touchpad-edge-detector.c | 27 ++++++++++++++------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/tools/mouse-dpi-tool.c b/tools/mouse-dpi-tool.c index 9961f3a..911f61e 100644 --- a/tools/mouse-dpi-tool.c +++ b/tools/mouse-dpi-tool.c @@ -23,7 +23,6 @@ #include "config.h" -#include #include #include #include @@ -40,6 +39,8 @@ #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) +static int signalled = 0; + struct measurements { int distance; double max_frequency; @@ -138,26 +139,26 @@ handle_event(struct measurements *m, const struct input_event *ev) return 0; } +static void +signal_handler(__attribute__((__unused__)) int signal) +{ + signalled++; +} + static int mainloop(struct libevdev *dev, struct measurements *m) { - struct pollfd fds[2]; - sigset_t mask; - - fds[0].fd = libevdev_get_fd(dev); - fds[0].events = POLLIN; + struct pollfd fds; - sigemptyset(&mask); - sigaddset(&mask, SIGINT); - fds[1].fd = signalfd(-1, &mask, SFD_NONBLOCK); - fds[1].events = POLLIN; + fds.fd = libevdev_get_fd(dev); + fds.events = POLLIN; - sigprocmask(SIG_BLOCK, &mask, NULL); + signal(SIGINT, signal_handler); - while (poll(fds, 2, -1)) { + while (poll(&fds, 1, -1)) { struct input_event ev; int rc; - if (fds[1].revents) + if (signalled) break; do { diff --git a/tools/touchpad-edge-detector.c b/tools/touchpad-edge-detector.c index 8b16cd7..7727cad 100644 --- a/tools/touchpad-edge-detector.c +++ b/tools/touchpad-edge-detector.c @@ -23,7 +23,6 @@ #include "config.h" -#include #include #include #include @@ -41,6 +40,8 @@ #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) +static int signalled = 0; + static int usage(void) { printf("Usage: %s 12x34 /dev/input/eventX\n", program_invocation_short_name); @@ -102,26 +103,26 @@ handle_event(struct dimensions *d, const struct input_event *ev) { return 0; } +static void +signal_handler(__attribute__((__unused__)) int signal) +{ + signalled++; +} + static int mainloop(struct libevdev *dev, struct dimensions *dim) { - struct pollfd fds[2]; - sigset_t mask; - - fds[0].fd = libevdev_get_fd(dev); - fds[0].events = POLLIN; + struct pollfd fds; - sigemptyset(&mask); - sigaddset(&mask, SIGINT); - fds[1].fd = signalfd(-1, &mask, SFD_NONBLOCK); - fds[1].events = POLLIN; + fds.fd = libevdev_get_fd(dev); + fds.events = POLLIN; - sigprocmask(SIG_BLOCK, &mask, NULL); + signal(SIGINT, signal_handler); - while (poll(fds, 2, -1)) { + while (poll(&fds, 1, -1)) { struct input_event ev; int rc; - if (fds[1].revents) + if (signalled) break; do { -- 2.34.1