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:
committed by
Guido Gunther
parent
49dab605c2
commit
58c370407f
+13
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
|
#include <glib-unix.h>
|
||||||
|
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
@@ -15,6 +16,15 @@
|
|||||||
|
|
||||||
static GMainLoop *loop;
|
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
|
static gboolean
|
||||||
on_watch_expired (gpointer unused)
|
on_watch_expired (gpointer unused)
|
||||||
{
|
{
|
||||||
@@ -55,6 +65,9 @@ trigger_event(const char *name, gint timeout)
|
|||||||
g_autoptr(GIOChannel) input = NULL;
|
g_autoptr(GIOChannel) input = NULL;
|
||||||
int success = FALSE;
|
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);
|
g_print("Triggering feedback for event '%s'\n", name);
|
||||||
event = lfb_event_new (name);
|
event = lfb_event_new (name);
|
||||||
lfb_event_set_timeout (event, timeout);
|
lfb_event_set_timeout (event, timeout);
|
||||||
|
|||||||
Reference in New Issue
Block a user