Lines Matching defs:log

13 #include "log-error-buffer.h"
14 #include "log-connection.h"
23 log connection. */
25 /* If we keep being busy, log a warning every 60 seconds. */
58 log_connection_destroy(struct log_connection *log, bool shutting_down);
86 static struct log_client *log_client_get(struct log_connection *log, pid_t pid)
90 client = hash_table_lookup(log->clients, POINTER_CAST(pid));
93 hash_table_insert(log->clients, POINTER_CAST(pid), client);
98 static void log_client_free(struct log_connection *log,
101 hash_table_remove(log->clients, POINTER_CAST(pid));
107 static void log_parse_option(struct log_connection *log,
112 client = log_client_get(log, failure->pid);
122 client_log_ctx(struct log_connection *log,
143 log_error_buffer_add(log->errorbuf, &err);
154 client_log_fatal(struct log_connection *log, struct log_client *client,
159 const char *prefix = log->default_prefix;
174 client_log_ctx(log, &failure_ctx, log_time, prefix,
182 struct log_connection *const *logs, *log;
206 noticed the log fd closing */
213 log = logs[service_fd];
214 client = hash_table_lookup(log->clients, POINTER_CAST(pid));
222 log_client_free(log, client, pid);
224 client_log_fatal(log, client, cmd + 6, log_time, tm);
226 /* If the client has logged a fatal/panic, don't log this
229 client_log_fatal(log, client, cmd + 14, log_time, tm);
236 log_it(struct log_connection *log, const char *line,
244 if (log->master) {
256 client = log_client_get(log, failure.pid);
261 log_parse_option(log, &failure);
265 hash_table_lookup(log->clients,
279 client->prefix : log->default_prefix;
280 client_log_ctx(log, &failure_ctx, log_time, prefix, failure.text);
283 static int log_connection_handshake(struct log_connection *log)
292 message that we want to log. */
293 ret = i_stream_read(log->input);
295 i_error("read(log %s) failed: %s", log->default_prefix,
296 i_stream_get_error(log->input));
304 data = i_stream_get_data(log->input, &size);
317 i_free(log->default_prefix);
318 log->default_prefix = i_strndup(data + sizeof(handshake),
320 i_stream_skip(log->input, sizeof(handshake) + handshake.prefix_len);
322 if (strcmp(log->default_prefix, MASTER_LOG_PREFIX_NAME) == 0) {
323 if (log->listen_fd != MASTER_LISTEN_FD_FIRST) {
325 "from non-master fd %d", log->fd);
328 log->master = TRUE;
330 log->handshaked = TRUE;
334 static void log_connection_input(struct log_connection *log)
342 if (!log->handshaked) {
343 if (log_connection_handshake(log) < 0) {
344 log_connection_destroy(log, FALSE);
354 while ((ret = i_stream_read(log->input)) > 0 || ret == -2) {
359 while ((line = i_stream_next_line(log->input)) != NULL)
360 log_it(log, line, &now, &tm);
368 if (log->input->eof) {
369 if (log->input->stream_errno != 0)
370 i_error("read(log %s) failed: %m", log->default_prefix);
371 log_connection_destroy(log, FALSE);
373 i_assert(!log->input->closed);
375 if (log->pending_count > 0) {
376 log->pending_count = 0;
379 if (log == last_pending_log)
385 last_pending_log = log;
386 if (log->pending_count++ == 0) {
390 if (log->pending_count == LOG_WARN_PENDING_COUNT ||
391 (log->pending_count % LOG_WARN_PENDING_INTERVAL) == 0) {
393 log->fd, log->listen_fd, log->default_prefix);
401 struct log_connection *log;
403 log = i_new(struct log_connection, 1);
404 log->errorbuf = errorbuf;
405 log->fd = fd;
406 log->listen_fd = listen_fd;
407 log->io = io_add(fd, IO_READ, log_connection_input, log);
408 log->input = i_stream_create_fd(fd, PIPE_BUF);
409 log->default_prefix = i_strdup_printf("listen_fd %d", listen_fd);
410 hash_table_create_direct(&log->clients, default_pool, 0);
411 array_idx_set(&logs_by_fd, listen_fd, &log);
413 DLLIST_PREPEND(&log_connections, log);
414 log_connection_input(log);
418 log_connection_destroy(struct log_connection *log, bool shutting_down)
425 array_idx_clear(&logs_by_fd, log->listen_fd);
427 DLLIST_REMOVE(&log_connections, log);
429 iter = hash_table_iterate_init(log->clients);
430 while (hash_table_iterate(iter, log->clients, &key, &client)) {
435 hash_table_destroy(&log->clients);
439 log->default_prefix, client_count);
442 i_stream_unref(&log->input);
443 io_remove(&log->io);
444 if (close(log->fd) < 0)
445 i_error("close(log connection fd) failed: %m");
446 i_free(log->default_prefix);
447 i_free(log);
459 /* normally we don't exit until all log connections are gone,