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>
This commit is contained in:
Niclas Zeising 2020-07-27 20:27:43 +02:00
parent 7ce82709aa
commit cca9093887
2 changed files with 28 additions and 26 deletions

View file

@ -23,7 +23,6 @@
#include "config.h" #include "config.h"
#include <sys/signalfd.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
@ -40,6 +39,8 @@
#define min(a, b) (((a) < (b)) ? (a) : (b)) #define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b))
static int signalled = 0;
struct measurements { struct measurements {
int distance; int distance;
double max_frequency; double max_frequency;
@ -138,26 +139,26 @@ handle_event(struct measurements *m, const struct input_event *ev)
return 0; return 0;
} }
static void
signal_handler(__attribute__((__unused__)) int signal)
{
signalled++;
}
static int static int
mainloop(struct libevdev *dev, struct measurements *m) { mainloop(struct libevdev *dev, struct measurements *m) {
struct pollfd fds[2]; struct pollfd fds;
sigset_t mask;
fds[0].fd = libevdev_get_fd(dev); fds.fd = libevdev_get_fd(dev);
fds[0].events = POLLIN; fds.events = POLLIN;
sigemptyset(&mask); signal(SIGINT, signal_handler);
sigaddset(&mask, SIGINT);
fds[1].fd = signalfd(-1, &mask, SFD_NONBLOCK);
fds[1].events = POLLIN;
sigprocmask(SIG_BLOCK, &mask, NULL); while (poll(&fds, 1, -1)) {
while (poll(fds, 2, -1)) {
struct input_event ev; struct input_event ev;
int rc; int rc;
if (fds[1].revents) if (signalled)
break; break;
do { do {

View file

@ -23,7 +23,6 @@
#include "config.h" #include "config.h"
#include <sys/signalfd.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
@ -41,6 +40,8 @@
#define min(a, b) (((a) < (b)) ? (a) : (b)) #define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b))
static int signalled = 0;
static int static int
usage(void) { usage(void) {
printf("Usage: %s 12x34 /dev/input/eventX\n", program_invocation_short_name); 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; return 0;
} }
static void
signal_handler(__attribute__((__unused__)) int signal)
{
signalled++;
}
static int static int
mainloop(struct libevdev *dev, struct dimensions *dim) { mainloop(struct libevdev *dev, struct dimensions *dim) {
struct pollfd fds[2]; struct pollfd fds;
sigset_t mask;
fds[0].fd = libevdev_get_fd(dev); fds.fd = libevdev_get_fd(dev);
fds[0].events = POLLIN; fds.events = POLLIN;
sigemptyset(&mask); signal(SIGINT, signal_handler);
sigaddset(&mask, SIGINT);
fds[1].fd = signalfd(-1, &mask, SFD_NONBLOCK);
fds[1].events = POLLIN;
sigprocmask(SIG_BLOCK, &mask, NULL); while (poll(&fds, 1, -1)) {
while (poll(fds, 2, -1)) {
struct input_event ev; struct input_event ev;
int rc; int rc;
if (fds[1].revents) if (signalled)
break; break;
do { do {