mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-20 09:10:05 +01:00
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:
parent
7ce82709aa
commit
cca9093887
2 changed files with 28 additions and 26 deletions
|
|
@ -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;
|
||||
struct pollfd fds;
|
||||
|
||||
fds[0].fd = libevdev_get_fd(dev);
|
||||
fds[0].events = POLLIN;
|
||||
fds.fd = libevdev_get_fd(dev);
|
||||
fds.events = POLLIN;
|
||||
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGINT);
|
||||
fds[1].fd = signalfd(-1, &mask, SFD_NONBLOCK);
|
||||
fds[1].events = POLLIN;
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
sigprocmask(SIG_BLOCK, &mask, NULL);
|
||||
|
||||
while (poll(fds, 2, -1)) {
|
||||
while (poll(&fds, 1, -1)) {
|
||||
struct input_event ev;
|
||||
int rc;
|
||||
|
||||
if (fds[1].revents)
|
||||
if (signalled)
|
||||
break;
|
||||
|
||||
do {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <sys/signalfd.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
|
|
@ -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;
|
||||
struct pollfd fds;
|
||||
|
||||
fds[0].fd = libevdev_get_fd(dev);
|
||||
fds[0].events = POLLIN;
|
||||
fds.fd = libevdev_get_fd(dev);
|
||||
fds.events = POLLIN;
|
||||
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGINT);
|
||||
fds[1].fd = signalfd(-1, &mask, SFD_NONBLOCK);
|
||||
fds[1].events = POLLIN;
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
sigprocmask(SIG_BLOCK, &mask, NULL);
|
||||
|
||||
while (poll(fds, 2, -1)) {
|
||||
while (poll(&fds, 1, -1)) {
|
||||
struct input_event ev;
|
||||
int rc;
|
||||
|
||||
if (fds[1].revents)
|
||||
if (signalled)
|
||||
break;
|
||||
|
||||
do {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue