]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added a new "FATAL" log command, which master uses to log all abnormal process exits.
authorTimo Sirainen <tss@iki.fi>
Thu, 8 Dec 2011 03:53:55 +0000 (05:53 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 8 Dec 2011 03:53:55 +0000 (05:53 +0200)
The log process adds the process's log prefix or IP address to the message
if available.

src/log/log-connection.c
src/master/service-process.c

index e7039d92c1d0818b4c98406f838c098549280413..0d7865c7d4a5d12a33e45f9801f228c6d2a59f57 100644 (file)
@@ -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;
        }
 
index 41dc31b134f07bcca6fbe73fe1dbdae0546354de..eaa30d3d859f10c33fd86c2f33009bc1277c7e35 100644 (file)
@@ -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");