33
33
struct istream *input;
35
35
char *default_prefix;
36
/* pid -> struct log_client* */
37
struct hash_table *clients;
36
HASH_TABLE(void *, struct log_client *) clients;
39
38
unsigned int master:1;
40
39
unsigned int handshaked:1;
43
42
static struct log_connection *log_connections = NULL;
44
static ARRAY_DEFINE(logs_by_fd, struct log_connection *);
43
static ARRAY(struct log_connection *) logs_by_fd;
45
static void log_connection_destroy(struct log_connection *log);
46
47
static struct log_client *log_client_get(struct log_connection *log, pid_t pid)
103
104
log_error_buffer_add(log->errorbuf, &err);
106
i_set_failure_prefix(prefix);
107
i_set_failure_prefix("%s", prefix);
107
108
i_log_type(ctx, "%s", text);
108
109
i_set_failure_prefix("log: ");
203
204
switch (failure.log_type) {
204
205
case LOG_TYPE_FATAL:
205
206
case LOG_TYPE_PANIC:
206
client = log_client_get(log, failure.pid);
207
client->fatal_logged = TRUE;
207
if (failure.pid != 0) {
208
client = log_client_get(log, failure.pid);
209
client->fatal_logged = TRUE;
209
212
case LOG_TYPE_OPTION:
210
213
log_parse_option(log, &failure);
213
client = hash_table_lookup(log->clients,
214
POINTER_CAST(failure.pid));
216
client = failure.pid == 0 ? NULL :
217
hash_table_lookup(log->clients,
218
POINTER_CAST(failure.pid));
217
221
i_assert(failure.log_type < LOG_TYPE_COUNT);
307
struct log_connection *
308
log_connection_create(struct log_error_buffer *errorbuf, int fd, int listen_fd)
311
void log_connection_create(struct log_error_buffer *errorbuf,
312
int fd, int listen_fd)
310
314
struct log_connection *log;
315
319
log->listen_fd = listen_fd;
316
320
log->io = io_add(fd, IO_READ, log_connection_input, log);
317
321
log->input = i_stream_create_fd(fd, PIPE_BUF, FALSE);
318
log->clients = hash_table_create(default_pool, default_pool, 0,
322
hash_table_create_direct(&log->clients, default_pool, 0);
320
323
array_idx_set(&logs_by_fd, listen_fd, &log);
322
325
DLLIST_PREPEND(&log_connections, log);
323
326
log_connection_input(log);
327
void log_connection_destroy(struct log_connection *log)
329
static void log_connection_destroy(struct log_connection *log)
329
331
struct hash_iterate_context *iter;
333
struct log_client *client;
332
335
array_idx_clear(&logs_by_fd, log->listen_fd);
334
337
DLLIST_REMOVE(&log_connections, log);
336
339
iter = hash_table_iterate_init(log->clients);
337
while (hash_table_iterate(iter, &key, &value))
340
while (hash_table_iterate(iter, log->clients, &key, &client))
339
342
hash_table_iterate_deinit(&iter);
340
343
hash_table_destroy(&log->clients);