dovecot-1.1: pop3/imap: When master closes our log fd, don't die...

dovecot at dovecot.org dovecot at dovecot.org
Tue Feb 10 19:19:30 EET 2009


details:   http://hg.dovecot.org/dovecot-1.1/rev/4044df5a4d12
changeset: 8161:4044df5a4d12
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Feb 10 12:19:05 2009 -0500
description:
pop3/imap: When master closes our log fd, don't die when trying to log disconnect reason.

diffstat:

5 files changed, 24 insertions(+)
src/dict/main.c    |    3 +++
src/imap/main.c    |    3 +++
src/lib/failures.c |   12 ++++++++++++
src/lib/failures.h |    3 +++
src/pop3/main.c    |    3 +++

diffs (95 lines):

diff -r 9ac5ffcfb5a7 -r 4044df5a4d12 src/dict/main.c
--- a/src/dict/main.c	Mon Feb 09 22:43:47 2009 -0500
+++ b/src/dict/main.c	Tue Feb 10 12:19:05 2009 -0500
@@ -34,6 +34,9 @@ static void sig_die(int signo, void *con
 
 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);
 }
 
diff -r 9ac5ffcfb5a7 -r 4044df5a4d12 src/imap/main.c
--- a/src/imap/main.c	Mon Feb 09 22:43:47 2009 -0500
+++ b/src/imap/main.c	Tue Feb 10 12:19:05 2009 -0500
@@ -63,6 +63,9 @@ static void sig_die(int signo, void *con
 
 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);
 }
 
diff -r 9ac5ffcfb5a7 -r 4044df5a4d12 src/lib/failures.c
--- a/src/lib/failures.c	Mon Feb 09 22:43:47 2009 -0500
+++ b/src/lib/failures.c	Tue Feb 10 12:19:05 2009 -0500
@@ -35,6 +35,7 @@ static void (*failure_exit_callback)(int
 
 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 @@ default_handler(const char *prefix, int 
 		ret = log_fd_write(fd, str_data(str), str_len(str));
 	} T_END;
 
+	if (ret < 0 && failure_ignore_errors)
+		ret = 0;
+
 	recursed--;
 	return ret;
 }
@@ -416,6 +420,9 @@ internal_handler(char log_type, const ch
 		ret = write_full(2, str_data(str), str_len(str));
 	} T_END;
 
+	if (ret < 0 && failure_ignore_errors)
+		ret = 0;
+
 	recursed--;
 	return ret;
 }
@@ -445,6 +452,11 @@ void i_set_failure_internal(void)
 	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)
diff -r 9ac5ffcfb5a7 -r 4044df5a4d12 src/lib/failures.h
--- a/src/lib/failures.h	Mon Feb 09 22:43:47 2009 -0500
+++ b/src/lib/failures.h	Tue Feb 10 12:19:05 2009 -0500
@@ -73,6 +73,9 @@ void i_set_failure_file(const char *path
 
 /* 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. */
diff -r 9ac5ffcfb5a7 -r 4044df5a4d12 src/pop3/main.c
--- a/src/pop3/main.c	Mon Feb 09 22:43:47 2009 -0500
+++ b/src/pop3/main.c	Tue Feb 10 12:19:05 2009 -0500
@@ -62,6 +62,9 @@ static void sig_die(int signo, void *con
 
 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);
 }
 


More information about the dovecot-cvs mailing list