fbcli: Quit main loop on CTRL-C / SIGTERM

This makes sure we invoke the cleanup function correctly and allows
to test running event handling.
This commit is contained in:
Guido Günther
2020-06-02 16:36:24 +00:00
committed by Guido Gunther
parent 49dab605c2
commit 58c370407f
+13
View File
@@ -8,6 +8,7 @@
#include <glib.h>
#include <gio/gio.h>
#include <glib-unix.h>
#include <locale.h>
@@ -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);