dovecot-1.2: master: Log startup errors as well as writing them ...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Sep 7 05:16:59 EEST 2009
details: http://hg.dovecot.org/dovecot-1.2/rev/eb4ea59e4657
changeset: 9367:eb4ea59e4657
user: Timo Sirainen <tss at iki.fi>
date: Sun Sep 06 22:16:55 2009 -0400
description:
master: Log startup errors as well as writing them to stderr.
diffstat:
1 file changed, 54 insertions(+), 12 deletions(-)
src/master/main.c | 66 +++++++++++++++++++++++++++++++++++++++++++----------
diffs (121 lines):
diff -r 38e491ff24d0 -r eb4ea59e4657 src/master/main.c
--- a/src/master/main.c Sun Sep 06 21:47:35 2009 -0400
+++ b/src/master/main.c Sun Sep 06 22:16:55 2009 -0400
@@ -95,8 +95,8 @@ static void fatal_log_check(void)
i_error("read(%s) failed: %m", path);
else {
buf[ret] = '\0';
- i_warning("Last died with error (see error log for more "
- "information): %s", buf);
+ fprintf(stderr, "Last died with error (see error log for more "
+ "information): %s", buf);
}
close(fd);
@@ -111,7 +111,7 @@ static void auth_warning_print(const str
auth_success_written = stat(AUTH_SUCCESS_PATH, &st) == 0;
if (!auth_success_written && !set->auths->debug &&
strcmp(set->defaults->protocols, "none") != 0) {
- i_info(
+ fprintf(stderr,
"If you have trouble with authentication failures,\n"
"enable auth_debug setting. See http://wiki.dovecot.org/WhyDoesItNotWork\n"
"This message goes away after the first successful login.");
@@ -137,6 +137,46 @@ static void set_logfile(struct settings
i_set_info_file(set->info_log_path);
i_set_failure_timestamp_format(set->log_timestamp);
+}
+
+static void ATTR_NORETURN
+tee_fatal_handler(enum log_type type, int status, const char *fmt, va_list args)
+{
+ const struct settings *set = settings_root->defaults;
+
+ fputs("Fatal: ", stderr);
+ vfprintf(stderr, fmt, args);
+ fputc('\n', stderr);
+
+ if (*set->log_path == '\0') {
+ i_syslog_fatal_handler(type, status, fmt, args);
+ } else {
+ default_fatal_handler(type, status, fmt, args);
+ }
+}
+
+static void
+tee_error_handler(enum log_type type, const char *fmt, va_list args)
+{
+ const struct settings *set = settings_root->defaults;
+
+ fputs("Error: ", stderr);
+ vfprintf(stderr, fmt, args);
+ fputc('\n', stderr);
+
+ if (*set->log_path == '\0') {
+ i_syslog_error_handler(type, fmt, args);
+ } else {
+ default_error_handler(type, fmt, args);
+ }
+}
+
+static void set_tee_logfile(struct settings *set)
+{
+ set_logfile(set);
+
+ i_set_fatal_handler(tee_fatal_handler);
+ i_set_error_handler(tee_error_handler);
}
static void settings_reload(void)
@@ -222,7 +262,7 @@ static void open_null_fd(void)
fd_close_on_exec(null_fd, TRUE);
}
-static void open_fds(void)
+static void open_std_fds(void)
{
/* make sure all fds between 0..3 are used. */
while (null_fd < 4) {
@@ -230,12 +270,6 @@ static void open_fds(void)
if (null_fd == -1)
i_fatal("dup(null_fd) failed: %m");
fd_close_on_exec(null_fd, TRUE);
- }
-
- if (!IS_INETD()) {
- T_BEGIN {
- listeners_open_fds(NULL, FALSE);
- } T_END;
}
/* close stdin and stdout. */
@@ -580,6 +614,8 @@ int main(int argc, char *argv[])
sizeof(ssl_manual_key_password));
} T_END;
+ open_std_fds();
+
/* save TZ environment. AIX depends on it to get the timezone
correctly. */
env_tz = getenv("TZ");
@@ -600,11 +636,17 @@ int main(int argc, char *argv[])
mail_process_exec(exec_protocol, exec_args);
}
- if (!log_error)
- open_fds();
+ /* log all errors to both stderr and log file until we've finished
+ startup. */
+ set_tee_logfile(settings_root->defaults);
fatal_log_check();
auth_warning_print(settings_root);
+
+ if (!log_error && !IS_INETD()) T_BEGIN {
+ listeners_open_fds(NULL, FALSE);
+ } T_END;
+
if (!foreground)
daemonize(settings_root->defaults);
master_original_pid = getpid();
More information about the dovecot-cvs
mailing list