changeset 4390:f0ac35961ae2 HEAD

Make sure the process dies when the master process dies.
author Timo Sirainen <tss@iki.fi>
date Sat, 17 Jun 2006 14:24:10 +0300
parents 16b28625cb79
children ec5a8b1523a3
files src/dict/main.c
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/dict/main.c	Fri Jun 16 21:37:06 2006 +0300
+++ b/src/dict/main.c	Sat Jun 17 14:24:10 2006 +0300
@@ -13,12 +13,14 @@
 #include "module-dir.h"
 
 #include <stdlib.h>
+#include <unistd.h>
 #include <syslog.h>
 
 #define DICT_MASTER_LISTENER_FD 3
 
 struct ioloop *ioloop;
 
+static struct io *log_io;
 static struct module *modules;
 static struct dict_server *dict_server;
 
@@ -31,6 +33,11 @@
 	io_loop_stop(ioloop);
 }
 
+static void log_error_callback(void *context __attr_unused__)
+{
+	io_loop_stop(ioloop);
+}
+
 static void drop_privileges(void)
 {
 	/* Log file or syslog opening probably requires roots */
@@ -58,6 +65,9 @@
         lib_signals_ignore(SIGPIPE);
         lib_signals_set_handler(SIGALRM, FALSE, NULL, NULL);
 
+	/* If master dies, the log fd gets closed and we'll quit */
+	log_io = io_add(STDERR_FILENO, IO_ERROR, log_error_callback, NULL);
+
 	dict_client_register();
 	dict_sql_register();
 
@@ -74,6 +84,7 @@
 
 static void main_deinit(void)
 {
+	io_remove(&log_io);
 	dict_server_deinit(dict_server);
 
 	module_dir_unload(&modules);