#include <libudev.h>
#include "linux/input.h"
#include <sys/ioctl.h>
-#include <sys/signalfd.h>
#include <libinput.h>
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)
}
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;
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