Mercurial > dovecot > original-hg > dovecot-1.2
changeset 9367:eb4ea59e4657 HEAD
master: Log startup errors as well as writing them to stderr.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 06 Sep 2009 22:16:55 -0400 |
parents | 38e491ff24d0 |
children | 597e18c0bc7e |
files | src/master/main.c |
diffstat | 1 files changed, 54 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ 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 @@ 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."); @@ -139,6 +139,46 @@ 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) { struct server_settings *old_set = settings_root; @@ -222,7 +262,7 @@ 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) { @@ -232,12 +272,6 @@ fd_close_on_exec(null_fd, TRUE); } - if (!IS_INETD()) { - T_BEGIN { - listeners_open_fds(NULL, FALSE); - } T_END; - } - /* close stdin and stdout. */ if (dup2(null_fd, 0) < 0) i_fatal("dup2(0) failed: %m"); @@ -580,6 +614,8 @@ 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 @@ 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();