From: Timo Sirainen Date: Tue, 10 Feb 2009 17:19:05 +0000 (-0500) Subject: pop3/imap: When master closes our log fd, don't die when trying to log disconnect... X-Git-Tag: 1.2.beta1~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2421fd34d51fed6da985c62b5e078d7e96640653;p=thirdparty%2Fdovecot%2Fcore.git pop3/imap: When master closes our log fd, don't die when trying to log disconnect reason. --HG-- branch : HEAD --- diff --git a/src/dict/main.c b/src/dict/main.c index 55429a79eb..7666820e50 100644 --- a/src/dict/main.c +++ b/src/dict/main.c @@ -34,6 +34,9 @@ static void sig_die(int signo, void *context ATTR_UNUSED) 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 --git a/src/imap/main.c b/src/imap/main.c index 13420dd27e..a1a351dc96 100644 --- a/src/imap/main.c +++ b/src/imap/main.c @@ -63,6 +63,9 @@ static void sig_die(int signo, void *context ATTR_UNUSED) 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 --git a/src/lib/failures.c b/src/lib/failures.c index 8c24e1cbb8..a4de26c795 100644 --- a/src/lib/failures.c +++ b/src/lib/failures.c @@ -35,6 +35,7 @@ static void (*failure_exit_callback)(int *) = NULL; 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 fd, const char *format, va_list args) 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 @@ internal_handler(char log_type, const char *format, va_list args) 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 @@ 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 --git a/src/lib/failures.h b/src/lib/failures.h index 1570e73ecf..1c7c3a3235 100644 --- a/src/lib/failures.h +++ b/src/lib/failures.h @@ -73,6 +73,9 @@ void i_set_failure_file(const char *path, const char *prefix); /* 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 --git a/src/pop3/main.c b/src/pop3/main.c index 55873501a4..0aeb51c957 100644 --- a/src/pop3/main.c +++ b/src/pop3/main.c @@ -63,6 +63,9 @@ static void sig_die(int signo, void *context ATTR_UNUSED) 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); }