dovecot-2.1: Added a new "FATAL" log command, which master uses ...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Dec 8 05:55:33 EET 2011
details: http://hg.dovecot.org/dovecot-2.1/rev/e534d2bfda7f
changeset: 13816:e534d2bfda7f
user: Timo Sirainen <tss at iki.fi>
date: Thu Dec 08 05:53:55 2011 +0200
description:
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.
diffstat:
src/log/log-connection.c | 37 ++++++++++++++++++++++++++++++++++---
src/master/service-process.c | 7 ++++---
2 files changed, 38 insertions(+), 6 deletions(-)
diffs (89 lines):
diff -r 279a48aa9dc6 -r e534d2bfda7f src/log/log-connection.c
--- a/src/log/log-connection.c Thu Dec 08 05:24:48 2011 +0200
+++ b/src/log/log-connection.c Thu Dec 08 05:53:55 2011 +0200
@@ -76,7 +76,34 @@
}
}
-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 @@
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 @@
const char *prefix;
if (log->master) {
- log_parse_master_line(line);
+ T_BEGIN {
+ log_parse_master_line(line, tm);
+ } T_END;
return;
}
diff -r 279a48aa9dc6 -r e534d2bfda7f src/master/service-process.c
--- a/src/master/service-process.c Thu Dec 08 05:24:48 2011 +0200
+++ b/src/master/service-process.c Thu Dec 08 05:53:55 2011 +0200
@@ -479,16 +479,17 @@
{
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");
More information about the dovecot-cvs
mailing list