tools: debug-events: install the signal handler before any libinput operations
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 1 Nov 2018 06:42:27 +0000 (16:42 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 7 Nov 2018 05:03:52 +0000 (05:03 +0000)
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>
tools/libinput-debug-events.c

index 87c3169..4f2f999 100644 (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;