summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-08-16 14:51:20 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-08-16 14:51:20 +0200
commitda21895e937f4f0ae9603f80db7daa1155cf8cf4 (patch)
tree91e1abf2c0c026fe952bed4407adac464f4789d6
parent43136cc7bfb9a44db2800fdfb360e08e36e6f7c2 (diff)
Implemented POSIX signal handler.
-rw-r--r--main.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/main.c b/main.c
index bcf52d8..90eaf85 100644
--- a/main.c
+++ b/main.c
@@ -4,6 +4,15 @@
#include <glib.h>
#include <glib-object.h>
+#include <signal.h>
+
+GMainLoop *main_loop;
+
+static void sig_handler(int sig) {
+ g_debug("caught signal %d", sig);
+ g_main_loop_quit(main_loop);
+}
+
int main(int argc, char **argv) {
g_type_init();
@@ -12,8 +21,14 @@ int main(int argc, char **argv) {
httpd_start();
- GMainLoop *main_loop = g_main_loop_new(NULL, FALSE);
+ signal(SIGINT, sig_handler);
+
+ main_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(main_loop);
+ while(g_main_loop_is_running(main_loop) == TRUE) {
+ g_debug("main loop still running");
+ }
+ g_main_loop_unref(main_loop);
httpd_stop();
music_free();