[PATCH libinput] tools: switch signal handler in event-debug
Jonas Ådahl
jadahl at gmail.com
Wed Jan 7 18:55:30 PST 2015
On Thu, Jan 08, 2015 at 10:05:34AM +1000, Peter Hutterer wrote:
> Under gdb, signalfd will still deliver the signal when gdb itself is
> interrupted and quit event-debug. For a debugging tool, that's not optimal.
> Switch to a normal signal handler instead, signalfd is overkill here anyway.
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
> tools/event-debug.c | 37 +++++++++++++++++--------------------
> 1 file changed, 17 insertions(+), 20 deletions(-)
>
> diff --git a/tools/event-debug.c b/tools/event-debug.c
> index c567550..a57d914 100644
> --- a/tools/event-debug.c
> +++ b/tools/event-debug.c
> @@ -42,6 +42,7 @@ uint32_t start_time;
> static const uint32_t screen_width = 100;
> static const uint32_t screen_height = 100;
> struct tools_options options;
> +unsigned int stop;
Should be static. Initialize for clarity?
>
> static int
> open_restricted(const char *path, int flags, void *user_data)
> @@ -331,24 +332,26 @@ handle_and_print_events(struct libinput *li)
> }
>
> static void
> +sighandler(int signal, siginfo_t *siginfo, void *userdata)
> +{
> + stop = 1;
> +}
> +
> +static void
> mainloop(struct libinput *li)
> {
> - struct pollfd fds[2];
> - sigset_t mask;
> + struct pollfd fds;
> + struct sigaction act;
>
> - fds[0].fd = libinput_get_fd(li);
> - fds[0].events = POLLIN;
> - fds[0].revents = 0;
> + fds.fd = libinput_get_fd(li);
> + fds.events = POLLIN;
> + fds.revents = 0;
>
> - sigemptyset(&mask);
> - sigaddset(&mask, SIGINT);
> + memset(&act, 0, sizeof(act));
> + act.sa_sigaction = sighandler;
> + act.sa_flags = SA_SIGINFO;
>
> - fds[1].fd = signalfd(-1, &mask, SFD_NONBLOCK);
> - fds[1].events = POLLIN;
> - fds[1].revents = 0;
> -
> - 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;
> @@ -359,14 +362,8 @@ mainloop(struct libinput *li)
> 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
> --
> 2.1.0
Can remove the #include <signalfd.h> now as well I suppose.
With those two fixed, consider this patch Reviewed-by: Jonas Ådahl
<jadahl at gmail.com>
Jonas
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list