Skip to content

Commit

Permalink
tools: debug-events: install the signal handler before any libinput o…
Browse files Browse the repository at this point in the history
…perations

On a CI container, we will time out trying to find the udev device for our
device node. This takes 2s, a SIGINT during this time should be treated the
same as one during the mainloop.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Nov 7, 2018
1 parent 22890a4 commit bd52bf5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tools/libinput-debug-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,22 +878,11 @@ static void
mainloop(struct libinput *li)
{
struct pollfd fds;
struct sigaction act;

fds.fd = libinput_get_fd(li);
fds.events = POLLIN;
fds.revents = 0;

memset(&act, 0, sizeof(act));
act.sa_sigaction = sighandler;
act.sa_flags = SA_SIGINFO;

if (sigaction(SIGINT, &act, NULL) == -1) {
fprintf(stderr, "Failed to set up signal handling (%s)\n",
strerror(errno));
return;
}

/* Handle already-pending device added events */
if (handle_and_print_events(li))
fprintf(stderr, "Expected device added events on startup but got none. "
Expand All @@ -919,6 +908,7 @@ main(int argc, char **argv)
const char *seat_or_device = "seat0";
bool grab = false;
bool verbose = false;
struct sigaction act;

clock_gettime(CLOCK_MONOTONIC, &tp);
start_time = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
Expand Down Expand Up @@ -995,6 +985,16 @@ main(int argc, char **argv)
return 1;
}

memset(&act, 0, sizeof(act));
act.sa_sigaction = sighandler;
act.sa_flags = SA_SIGINFO;

if (sigaction(SIGINT, &act, NULL) == -1) {
fprintf(stderr, "Failed to set up signal handling (%s)\n",
strerror(errno));
return EXIT_FAILURE;
}

li = tools_open_backend(backend, seat_or_device, verbose, &grab);
if (!li)
return 1;
Expand Down

0 comments on commit bd52bf5

Please sign in to comment.