From 78d3415365239b412845671472e2b48f737d047a Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Wed, 11 Oct 2017 12:40:59 +0200 Subject: ucad: handle SIGINT gracefully --- ucad.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ucad.c b/ucad.c index 35fb077..b97d9ac 100644 --- a/ucad.c +++ b/ucad.c @@ -18,16 +18,17 @@ #include #include #include +#include #include #include #include "uca-net-protocol.h" #include "config.h" +static GMainLoop *loop; typedef void (*MessageHandler) (GSocketConnection *connection, UcaCamera *camera, gpointer message, GError **error); typedef void (*CameraFunc) (UcaCamera *camera, GError **error); - typedef struct { UcaNetMessageType type; MessageHandler handler; @@ -413,10 +414,15 @@ run_callback (GSocketService *service, GSocketConnection *connection, GObject *s return FALSE; } +static void +sigint_handler (int unused) +{ + g_main_loop_quit (loop); +} + static void serve (UcaCamera *camera, guint16 port, GError **error) { - GMainLoop *loop; GSocketService *service; service = g_threaded_socket_service_new (1); @@ -427,6 +433,7 @@ serve (UcaCamera *camera, guint16 port, GError **error) g_signal_connect (service, "run", G_CALLBACK (run_callback), camera); loop = g_main_loop_new (NULL, TRUE); + signal (SIGINT, sigint_handler); g_main_loop_run (loop); } -- cgit v1.2.3