From bd52bf542119f0cc71f7b676f9ed67d5001c40fc Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 1 Nov 2018 16:42:27 +1000 Subject: [PATCH] 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 --- tools/libinput-debug-events.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/libinput-debug-events.c b/tools/libinput-debug-events.c index 87c31690..4f2f9999 100644 --- a/tools/libinput-debug-events.c +++ b/tools/libinput-debug-events.c @@ -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;