annotate src/master/log.c @ 9490:fd84592e817b HEAD

dovecot-example.conf: Updated dict comments.
author Timo Sirainen <tss@iki.fi>
date Mon, 23 Nov 2009 13:08:47 -0500
parents 194b80691980
children 00cd9aacd03c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
b9faf4db2a9f Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents: 7226
diff changeset
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "ioloop.h"
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "istream.h"
4650
4ff5080c5325 When shutting down do one last read from log fds to see if there's something
Timo Sirainen <tss@iki.fi>
parents: 4641
diff changeset
6 #include "fd-set-nonblock.h"
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "fd-close-on-exec.h"
6542
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
8 #include "child-process.h"
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "log.h"
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include <unistd.h>
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 struct log_io {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 struct log_io *prev, *next;
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
15 int refcount;
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
16
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 struct io *io;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 struct istream *stream;
6542
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
19 pid_t pid;
8628
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
20 struct ip_addr ip;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 time_t log_stamp;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 unsigned int log_counter;
3083
a20882c4f092 Disable log throttlong for auth process, and for login processes if
Timo Sirainen <tss@iki.fi>
parents: 2775
diff changeset
24 unsigned int max_lines_per_sec;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 char *prefix;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 char next_log_type;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 unsigned int throttle_msg:1;
2775
e6e73d1db27c Log flushing fixes.
Timo Sirainen <tss@iki.fi>
parents: 2046
diff changeset
29 unsigned int destroying:1;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 };
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 static struct log_io *log_ios;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 static struct timeout *to;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 static unsigned int throttle_count;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3083
diff changeset
36 static int log_it(struct log_io *log_io, const char *line, bool continues);
4660
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
37 static int log_read(struct log_io *log_io);
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 static void log_throttle_timeout(void *context);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3083
diff changeset
40 static bool log_write_pending(struct log_io *log_io)
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 const char *line;
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6542
diff changeset
43 bool ret;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 if (log_io->log_stamp != ioloop_time) {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 log_io->log_stamp = ioloop_time;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 log_io->log_counter = 0;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 while ((line = i_stream_next_line(log_io->stream)) != NULL) {
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
51 T_BEGIN {
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6542
diff changeset
52 ret = log_it(log_io, line, FALSE);
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
53 } T_END;
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6542
diff changeset
54 if (!ret)
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 return FALSE;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 return TRUE;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 static void log_throttle(struct log_io *log_io)
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 if (!log_io->throttle_msg) {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 log_io->throttle_msg = TRUE;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 log_it(log_io, "Sending log messages too fast, throttling..",
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 FALSE);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68
4641
Timo Sirainen <tss@iki.fi>
parents: 4393
diff changeset
69 if (log_io->io == NULL) {
Timo Sirainen <tss@iki.fi>
parents: 4393
diff changeset
70 i_assert(to != NULL);
Timo Sirainen <tss@iki.fi>
parents: 4393
diff changeset
71 return;
Timo Sirainen <tss@iki.fi>
parents: 4393
diff changeset
72 }
Timo Sirainen <tss@iki.fi>
parents: 4393
diff changeset
73
Timo Sirainen <tss@iki.fi>
parents: 4393
diff changeset
74 io_remove(&log_io->io);
Timo Sirainen <tss@iki.fi>
parents: 4393
diff changeset
75 throttle_count++;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 if (to == NULL)
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 to = timeout_add(1000, log_throttle_timeout, NULL);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80
4907
5b4c9b20eba0 Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents: 4660
diff changeset
81 static void log_read_callback(struct log_io *log_io)
4660
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
82 {
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
83 (void)log_read(log_io);
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
84 }
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
85
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 static void log_unthrottle(struct log_io *log_io)
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 if (log_io->io != NULL)
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 return;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
91 if (--throttle_count == 0 && to != NULL)
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
92 timeout_remove(&to);
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 log_io->io = io_add(i_stream_get_fd(log_io->stream),
4660
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
94 IO_READ, log_read_callback, log_io);
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3083
diff changeset
97 static int log_it(struct log_io *log_io, const char *line, bool continues)
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 {
6542
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
99 struct child_process *process;
2046
6ae973f60f43 logging cleanups.
Timo Sirainen <tss@iki.fi>
parents: 2000
diff changeset
100 const char *prefix;
6541
56d6a891c41c Log fatal/panic messages coming from child processes as such, instead of
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
101 enum log_type log_type;
2046
6ae973f60f43 logging cleanups.
Timo Sirainen <tss@iki.fi>
parents: 2000
diff changeset
102
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 if (log_io->next_log_type == '\0') {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 if (line[0] == 1 && line[1] != '\0') {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 /* our internal protocol.
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 \001 + log_type */
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 log_io->next_log_type = line[1];
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 line += 2;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 } else {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110 log_io->next_log_type = 'E';
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113
2046
6ae973f60f43 logging cleanups.
Timo Sirainen <tss@iki.fi>
parents: 2000
diff changeset
114 prefix = log_io->prefix != NULL ? log_io->prefix : "";
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 switch (log_io->next_log_type) {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 case 'I':
6541
56d6a891c41c Log fatal/panic messages coming from child processes as such, instead of
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
117 log_type = LOG_TYPE_INFO;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 break;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 case 'W':
6541
56d6a891c41c Log fatal/panic messages coming from child processes as such, instead of
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
120 log_type = LOG_TYPE_WARNING;
56d6a891c41c Log fatal/panic messages coming from child processes as such, instead of
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
121 break;
56d6a891c41c Log fatal/panic messages coming from child processes as such, instead of
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
122 case 'E':
56d6a891c41c Log fatal/panic messages coming from child processes as such, instead of
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
123 log_type = LOG_TYPE_ERROR;
56d6a891c41c Log fatal/panic messages coming from child processes as such, instead of
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
124 break;
56d6a891c41c Log fatal/panic messages coming from child processes as such, instead of
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
125 case 'F':
56d6a891c41c Log fatal/panic messages coming from child processes as such, instead of
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
126 case 'P':
6542
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
127 log_type = log_io->next_log_type == 'F' ?
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
128 LOG_TYPE_FATAL : LOG_TYPE_PANIC;
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
129 process = child_process_lookup(log_io->pid);
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
130 if (process != NULL)
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
131 process->seen_fatal = TRUE;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132 break;
8628
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
133 case 'O':
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
134 /* logging option. ignore unknown ones. */
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
135 if (strncmp(line, "ip=", 3) == 0) {
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
136 process = child_process_lookup(log_io->pid);
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
137 if (process != NULL &&
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
138 (process->allow_change_ip ||
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
139 process->ip.family == 0)) {
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
140 if (process->ip.family != 0)
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
141 process->ip_changed = TRUE;
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
142 net_addr2ip(line + 3, &process->ip);
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
143 }
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
144 }
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
145 log_io->next_log_type = '\0';
e85c7cb22ad7 If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
146 return 1;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147 default:
6541
56d6a891c41c Log fatal/panic messages coming from child processes as such, instead of
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
148 log_type = LOG_TYPE_ERROR;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149 break;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150 }
9032
194b80691980 Add "dovecot: " log prefix only for messages from master process.
Timo Sirainen <tss@iki.fi>
parents: 8628
diff changeset
151 i_set_failure_prefix(prefix);
194b80691980 Add "dovecot: " log prefix only for messages from master process.
Timo Sirainen <tss@iki.fi>
parents: 8628
diff changeset
152 i_log_type(log_type, "%s", line);
194b80691980 Add "dovecot: " log prefix only for messages from master process.
Timo Sirainen <tss@iki.fi>
parents: 8628
diff changeset
153 i_set_failure_prefix("dovecot: ");
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 if (!continues)
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 log_io->next_log_type = '\0';
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157
3083
a20882c4f092 Disable log throttlong for auth process, and for login processes if
Timo Sirainen <tss@iki.fi>
parents: 2775
diff changeset
158 if (++log_io->log_counter > log_io->max_lines_per_sec &&
2775
e6e73d1db27c Log flushing fixes.
Timo Sirainen <tss@iki.fi>
parents: 2046
diff changeset
159 !log_io->destroying) {
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 log_throttle(log_io);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 return 0;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163 return 1;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165
4660
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
166 static int log_read(struct log_io *log_io)
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167 {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 const unsigned char *data;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 const char *line;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170 size_t size;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 int ret;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173 if (!log_write_pending(log_io))
4660
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
174 return 0;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176 ret = i_stream_read(log_io->stream);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 if (ret < 0) {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 if (ret == -1) {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 /* closed */
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
180 log_unref(log_io);
4660
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
181 return -1;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 /* buffer full. treat it as one line */
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 data = i_stream_get_data(log_io->stream, &size);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186 line = t_strndup(data, size);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187 i_stream_skip(log_io->stream, size);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 if (!log_it(log_io, line, TRUE))
4660
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
190 return 0;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
192
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 if (!log_write_pending(log_io))
4660
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
194 return 0;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195
3083
a20882c4f092 Disable log throttlong for auth process, and for login processes if
Timo Sirainen <tss@iki.fi>
parents: 2775
diff changeset
196 if (log_io->log_counter < log_io->max_lines_per_sec)
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
197 log_unthrottle(log_io);
4660
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
198 return 0;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200
3083
a20882c4f092 Disable log throttlong for auth process, and for login processes if
Timo Sirainen <tss@iki.fi>
parents: 2775
diff changeset
201 int log_create_pipe(struct log_io **log_r, unsigned int max_lines_per_sec)
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
202 {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203 struct log_io *log_io;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
204 int fd[2];
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206 if (pipe(fd) < 0) {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207 i_error("pipe() failed: %m");
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
208 return -1;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
209 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
210
4650
4ff5080c5325 When shutting down do one last read from log fds to see if there's something
Timo Sirainen <tss@iki.fi>
parents: 4641
diff changeset
211 fd_set_nonblock(fd[0], TRUE);
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
212 fd_close_on_exec(fd[0], TRUE);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213 fd_close_on_exec(fd[1], TRUE);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
214
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215 log_io = i_new(struct log_io, 1);
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
216 log_io->refcount = 1;
6542
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
217 log_io->pid = (pid_t)-1;
6162
896cc473c1f0 Renamed i_stream_create_file() to i_stream_create_fd().
Timo Sirainen <tss@iki.fi>
parents: 6142
diff changeset
218 log_io->stream = i_stream_create_fd(fd[0], 1024, TRUE);
3083
a20882c4f092 Disable log throttlong for auth process, and for login processes if
Timo Sirainen <tss@iki.fi>
parents: 2775
diff changeset
219 log_io->max_lines_per_sec =
a20882c4f092 Disable log throttlong for auth process, and for login processes if
Timo Sirainen <tss@iki.fi>
parents: 2775
diff changeset
220 max_lines_per_sec != 0 ? max_lines_per_sec : (unsigned int)-1;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
221
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
222 throttle_count++;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
223 log_unthrottle(log_io);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
224
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
225 if (log_ios != NULL)
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
226 log_ios->prev = log_io;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
227 log_io->next = log_ios;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
228 log_ios = log_io;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
229
2046
6ae973f60f43 logging cleanups.
Timo Sirainen <tss@iki.fi>
parents: 2000
diff changeset
230 if (log_r != NULL)
6ae973f60f43 logging cleanups.
Timo Sirainen <tss@iki.fi>
parents: 2000
diff changeset
231 *log_r = log_io;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232 return fd[1];
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
234
2046
6ae973f60f43 logging cleanups.
Timo Sirainen <tss@iki.fi>
parents: 2000
diff changeset
235 void log_set_prefix(struct log_io *log, const char *prefix)
6ae973f60f43 logging cleanups.
Timo Sirainen <tss@iki.fi>
parents: 2000
diff changeset
236 {
6ae973f60f43 logging cleanups.
Timo Sirainen <tss@iki.fi>
parents: 2000
diff changeset
237 i_free(log->prefix);
6ae973f60f43 logging cleanups.
Timo Sirainen <tss@iki.fi>
parents: 2000
diff changeset
238 log->prefix = i_strdup(prefix);
6ae973f60f43 logging cleanups.
Timo Sirainen <tss@iki.fi>
parents: 2000
diff changeset
239 }
6ae973f60f43 logging cleanups.
Timo Sirainen <tss@iki.fi>
parents: 2000
diff changeset
240
6542
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
241 void log_set_pid(struct log_io *log, pid_t pid)
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
242 {
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
243 log->pid = pid;
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
244 }
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6541
diff changeset
245
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
246 void log_ref(struct log_io *log_io)
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
247 {
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
248 log_io->refcount++;
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
249 }
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
250
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
251 static void log_close(struct log_io *log_io)
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
252 {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 const unsigned char *data;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
254 size_t size;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
255
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
256 if (log_io->destroying)
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
257 return;
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
258
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
259 /* if there was something in buffer, write it */
2775
e6e73d1db27c Log flushing fixes.
Timo Sirainen <tss@iki.fi>
parents: 2046
diff changeset
260 log_io->destroying = TRUE;
e6e73d1db27c Log flushing fixes.
Timo Sirainen <tss@iki.fi>
parents: 2046
diff changeset
261 (void)log_write_pending(log_io);
e6e73d1db27c Log flushing fixes.
Timo Sirainen <tss@iki.fi>
parents: 2046
diff changeset
262
e6e73d1db27c Log flushing fixes.
Timo Sirainen <tss@iki.fi>
parents: 2046
diff changeset
263 /* write partial data as well */
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
264 data = i_stream_get_data(log_io->stream, &size);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 if (size != 0) {
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
266 T_BEGIN {
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6542
diff changeset
267 log_it(log_io, t_strndup(data, size), TRUE);
7226
e6693a0ec8e1 Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
268 } T_END;
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
269 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
270
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
271 if (log_io == log_ios)
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
272 log_ios = log_io->next;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
273 else
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
274 log_io->prev->next = log_io->next;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
275 if (log_io->next != NULL)
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276 log_io->next->prev = log_io->prev;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278 if (log_io->io != NULL)
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
279 io_remove(&log_io->io);
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
280 else
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281 throttle_count--;
4070
71b8faa84ec6 Added i_stream_destroy() and o_stream_destroy() and used them instead of
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
282 i_stream_destroy(&log_io->stream);
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
283 }
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
284
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
285 void log_unref(struct log_io *log_io)
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
286 {
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
287 i_assert(log_io->refcount > 0);
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
288
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
289 log_close(log_io);
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
290
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
291 if (--log_io->refcount > 0)
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
292 return;
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
293
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
294 i_free(log_io->prefix);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
295 i_free(log_io);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
296 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
297
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6162
diff changeset
298 static void log_throttle_timeout(void *context ATTR_UNUSED)
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299 {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
300 struct log_io *log, *next;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
301 unsigned int left = throttle_count;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
302
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
303 i_assert(left > 0);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
304
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
305 for (log = log_ios; log != NULL; log = next) {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
306 next = log->next;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
307
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
308 if (log->io == NULL) {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
309 if (log_write_pending(log))
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
310 log_unthrottle(log);
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
311
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
312 if (--left == 0)
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
313 break;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
315 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
316 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
317
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
318 void log_init(void)
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
319 {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
320 log_ios = NULL;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
321 throttle_count = 0;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
322 to = NULL;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
323 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
324
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
325 void log_deinit(void)
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
326 {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
327 struct log_io *next;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
328
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
329 while (log_ios != NULL) {
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
330 next = log_ios->next;
4650
4ff5080c5325 When shutting down do one last read from log fds to see if there's something
Timo Sirainen <tss@iki.fi>
parents: 4641
diff changeset
331 /* do one final log read in case there's still something
4ff5080c5325 When shutting down do one last read from log fds to see if there's something
Timo Sirainen <tss@iki.fi>
parents: 4641
diff changeset
332 waiting */
4660
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
333 if (log_read(log_ios) == 0)
60ae03cf7412 Don't crash in log deinitialization.
Timo Sirainen <tss@iki.fi>
parents: 4650
diff changeset
334 log_unref(log_ios);
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335 log_ios = next;
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
336 }
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
337
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338 if (to != NULL)
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
339 timeout_remove(&to);
2000
c7c19f5071c3 Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
340 }