changeset 8741:d74fdb84ab8b HEAD

pop3/imap: When master closes our log fd, don't die when trying to log disconnect reason.
author Timo Sirainen <tss@iki.fi>
date Tue, 10 Feb 2009 12:19:05 -0500
parents 743cc6ff3d89
children 37e118a32cd0
files src/dict/main.c src/imap/main.c src/lib/failures.c src/lib/failures.h src/pop3/main.c
diffstat 5 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/dict/main.c	Tue Feb 10 12:01:41 2009 -0500
+++ b/src/dict/main.c	Tue Feb 10 12:19:05 2009 -0500
@@ -34,6 +34,9 @@
 
 static void log_error_callback(void *context ATTR_UNUSED)
 {
+	/* the log fd is closed, don't die when trying to log later */
+	i_set_failure_ignore_errors(TRUE);
+
 	io_loop_stop(ioloop);
 }
 
--- a/src/imap/main.c	Tue Feb 10 12:01:41 2009 -0500
+++ b/src/imap/main.c	Tue Feb 10 12:19:05 2009 -0500
@@ -63,6 +63,9 @@
 
 static void log_error_callback(void *context ATTR_UNUSED)
 {
+	/* the log fd is closed, don't die when trying to log later */
+	i_set_failure_ignore_errors(TRUE);
+
 	io_loop_stop(ioloop);
 }
 
--- a/src/lib/failures.c	Tue Feb 10 12:01:41 2009 -0500
+++ b/src/lib/failures.c	Tue Feb 10 12:19:05 2009 -0500
@@ -35,6 +35,7 @@
 
 static int log_fd = STDERR_FILENO, log_info_fd = STDERR_FILENO;
 static char *log_prefix = NULL, *log_stamp_format = NULL;
+static bool failure_ignore_errors = FALSE;
 
 /* kludgy .. we want to trust log_stamp_format with -Wformat-nonliteral */
 static const char *get_log_stamp_format(const char *unused)
@@ -133,6 +134,9 @@
 		ret = log_fd_write(fd, str_data(str), str_len(str));
 	} T_END;
 
+	if (ret < 0 && failure_ignore_errors)
+		ret = 0;
+
 	recursed--;
 	return ret;
 }
@@ -413,6 +417,9 @@
 		ret = write_full(2, str_data(str), str_len(str));
 	} T_END;
 
+	if (ret < 0 && failure_ignore_errors)
+		ret = 0;
+
 	recursed--;
 	return ret;
 }
@@ -442,6 +449,11 @@
 	i_set_info_handler(i_internal_error_handler);
 }
 
+void i_set_failure_ignore_errors(bool ignore)
+{
+	failure_ignore_errors = ignore;
+}
+
 void i_set_info_file(const char *path)
 {
 	if (log_info_fd == log_fd)
--- a/src/lib/failures.h	Tue Feb 10 12:01:41 2009 -0500
+++ b/src/lib/failures.h	Tue Feb 10 12:19:05 2009 -0500
@@ -73,6 +73,9 @@
 
 /* Send errors to stderr using internal error protocol. */
 void i_set_failure_internal(void);
+/* If writing to log fails, ignore it instead of existing with
+   FATAL_LOGWRITE or FATAL_LOGERROR. */
+void i_set_failure_ignore_errors(bool ignore);
 
 /* Send informational messages to specified log file. i_set_failure_*()
    functions modify the info file too, so call this function after them. */
--- a/src/pop3/main.c	Tue Feb 10 12:01:41 2009 -0500
+++ b/src/pop3/main.c	Tue Feb 10 12:19:05 2009 -0500
@@ -63,6 +63,9 @@
 
 static void log_error_callback(void *context ATTR_UNUSED)
 {
+	/* the log fd is closed, don't die when trying to log later */
+	i_set_failure_ignore_errors(TRUE);
+
 	io_loop_stop(ioloop);
 }