[tracker-miner-chatlog] main: Add SIGTERM/SIGINT handler
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miner-chatlog] main: Add SIGTERM/SIGINT handler
- Date: Sun, 17 Jan 2016 20:40:05 +0000 (UTC)
commit 36263aa4ced7ed75c93e8019f68104c6f831da74
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Jan 17 20:28:48 2016 +0100
main: Add SIGTERM/SIGINT handler
So we can just quit the main loop. Helps when tracking lost
memory in valgrind.
src/main.c | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/src/main.c b/src/main.c
index 10fd4c8..56ba5a6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,8 +19,35 @@
* Author: Carlos Garnacho <carlosg gnome org>
*/
+#include <glib-unix.h>
#include "miner.h"
+static gboolean
+signal_handler (gpointer user_data)
+{
+ GMainLoop *loop = user_data;
+ static gboolean in_loop = FALSE;
+
+ /* Die if we get re-entrant signals handler calls */
+ if (in_loop) {
+ _exit (EXIT_FAILURE);
+ }
+
+ in_loop = TRUE;
+ g_main_loop_quit (loop);
+
+ return G_SOURCE_CONTINUE;
+}
+
+static void
+initialize_signal_handler (GMainLoop *loop)
+{
+#ifndef G_OS_WIN32
+ g_unix_signal_add (SIGTERM, signal_handler, loop);
+ g_unix_signal_add (SIGINT, signal_handler, loop);
+#endif /* G_OS_WIN32 */
+}
+
int
main (int argc,
char *argv[])
@@ -38,6 +65,7 @@ main (int argc,
}
loop = g_main_loop_new (NULL, FALSE);
+ initialize_signal_handler (loop);
g_main_loop_run (loop);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]