From 58c370407fca6a570970c81b482b724d4fbacef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Fri, 29 May 2020 11:51:16 +0200 Subject: [PATCH] fbcli: Quit main loop on CTRL-C / SIGTERM This makes sure we invoke the cleanup function correctly and allows to test running event handling. --- cli/fbcli.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cli/fbcli.c b/cli/fbcli.c index d4cb312..34fc14d 100644 --- a/cli/fbcli.c +++ b/cli/fbcli.c @@ -8,6 +8,7 @@ #include #include +#include #include @@ -15,6 +16,15 @@ static GMainLoop *loop; +static gboolean +on_shutdown_signal (gpointer unused) +{ + /* End right away, lfb_uninit will end running feedback */ + g_main_loop_quit (loop); + + return FALSE; +} + static gboolean on_watch_expired (gpointer unused) { @@ -55,6 +65,9 @@ trigger_event(const char *name, gint timeout) g_autoptr(GIOChannel) input = NULL; int success = FALSE; + g_unix_signal_add (SIGTERM, on_shutdown_signal, NULL); + g_unix_signal_add (SIGINT, on_shutdown_signal, NULL); + g_print("Triggering feedback for event '%s'\n", name); event = lfb_event_new (name); lfb_event_set_timeout (event, timeout);