From: Timo Sirainen Date: Thu, 8 Dec 2011 03:53:55 +0000 (+0200) Subject: Added a new "FATAL" log command, which master uses to log all abnormal process exits. X-Git-Tag: 2.1.rc2~84 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=800fc30be46bc6f8380f6de04aea7c19ea839ddf;p=thirdparty%2Fdovecot%2Fcore.git Added a new "FATAL" log command, which master uses to log all abnormal process exits. The log process adds the process's log prefix or IP address to the message if available. --- diff --git a/src/log/log-connection.c b/src/log/log-connection.c index e7039d92c1..0d7865c7d4 100644 --- a/src/log/log-connection.c +++ b/src/log/log-connection.c @@ -76,7 +76,34 @@ static void log_parse_option(struct log_connection *log, } } -static void log_parse_master_line(const char *line) +static void +client_log_fatal(struct log_connection *log, struct log_client *client, + const char *line, const struct tm *tm) +{ + struct failure_context failure_ctx; + const char *prefix = log->default_prefix; + + memset(&failure_ctx, 0, sizeof(failure_ctx)); + failure_ctx.type = LOG_TYPE_FATAL; + failure_ctx.timestamp = tm; + + if (client != NULL) { + if (client->prefix != NULL) + prefix = client->prefix; + else if (client->ip.family != 0) { + line = t_strdup_printf("%s [last ip=%s]", + line, net_ip2addr(&client->ip)); + } + } + prefix = client != NULL && client->prefix != NULL ? + client->prefix : log->default_prefix; + i_set_failure_prefix(prefix); + i_log_type(&failure_ctx, "master: %s", line); + i_set_failure_prefix("log: "); +} + +static void +log_parse_master_line(const char *line, const struct tm *tm) { struct log_connection *const *logs, *log; struct log_client *client; @@ -110,11 +137,13 @@ static void log_parse_master_line(const char *line) return; } log_client_free(log, client, pid); + } else if (strncmp(line, "FATAL ", 6) == 0) { + client_log_fatal(log, client, line + 6, tm); } else if (strncmp(line, "DEFAULT-FATAL ", 14) == 0) { /* If the client has logged a fatal/panic, don't log this message. */ if (client == NULL || !client->fatal_logged) - i_error("%s", line + 14); + client_log_fatal(log, client, line + 14, tm); } else { i_error("Received unknown command from master: %s", line); } @@ -129,7 +158,9 @@ log_it(struct log_connection *log, const char *line, const struct tm *tm) const char *prefix; if (log->master) { - log_parse_master_line(line); + T_BEGIN { + log_parse_master_line(line, tm); + } T_END; return; } diff --git a/src/master/service-process.c b/src/master/service-process.c index 41dc31b134..eaa30d3d85 100644 --- a/src/master/service-process.c +++ b/src/master/service-process.c @@ -479,16 +479,17 @@ static void service_process_log(struct service_process *process, { const char *data; - if (!default_fatal || process->service->log_fd[1] == -1) { + if (process->service->log_fd[1] == -1) { i_error("%s", str); return; } /* log it via the log process in charge of handling this process's logging */ - data = t_strdup_printf("%d %s DEFAULT-FATAL %s\n", + data = t_strdup_printf("%d %s %s %s\n", process->service->log_process_internal_fd, - dec2str(process->pid), str); + dec2str(process->pid), + default_fatal ? "DEFAULT-FATAL" : "FATAL", str); if (write(process->service->list->master_log_fd[1], data, strlen(data)) < 0) { i_error("write(log process) failed: %m");