tools: debug-events: install the signal handler before any libinput operations

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>
This commit is contained in:
Peter Hutterer 2018-11-01 16:42:27 +10:00
parent 22890a4719
commit bd52bf5421

View file

@ -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. "
@ -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;
@ -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;