diff options
author | Niclas Zeising <zeising@daemonic.se> | 2020-07-27 20:27:43 +0200 |
---|---|---|
committer | Niclas Zeising <zeising@daemonic.se> | 2020-08-14 17:50:56 +0200 |
commit | cca90938874baaa5bd29d6406e141e49d6bf12a6 (patch) | |
tree | 4a6c2c8a46a872b3635311870f04e60a76541b94 /tools/mouse-dpi-tool.c | |
parent | 7ce82709aa43e7a787dba95463e88662cb4688ce (diff) | |
download | libevdev-cca90938874baaa5bd29d6406e141e49d6bf12a6.tar.gz |
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 <zeising@daemonic.se>
Diffstat (limited to 'tools/mouse-dpi-tool.c')
-rw-r--r-- | tools/mouse-dpi-tool.c | 27 |
1 files changed, 14 insertions, 13 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 <sys/signalfd.h> #include <errno.h> #include <fcntl.h> #include <limits.h> @@ -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 { |