summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2017-10-11 12:40:59 +0200
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2017-10-11 12:40:59 +0200
commit78d3415365239b412845671472e2b48f737d047a (patch)
treecf6ba45ce254894400e674d5f9389048eba3e5ac
parentdb1ab668e8ff1518db2c5f8834cbb65e1d667894 (diff)
downloaduca-net-78d3415365239b412845671472e2b48f737d047a.tar.gz
uca-net-78d3415365239b412845671472e2b48f737d047a.tar.bz2
uca-net-78d3415365239b412845671472e2b48f737d047a.tar.xz
uca-net-78d3415365239b412845671472e2b48f737d047a.zip
ucad: handle SIGINT gracefully
-rw-r--r--ucad.c11
1 files 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 <glib-object.h>
#include <gio/gio.h>
#include <string.h>
+#include <signal.h>
#include <uca/uca-camera.h>
#include <uca/uca-plugin-manager.h>
#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;
@@ -414,9 +415,14 @@ run_callback (GSocketService *service, GSocketConnection *connection, GObject *s
}
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);
}