summaryrefslogtreecommitdiffstats
path: root/src/log/main.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
commitf7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch)
treea3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/log/main.c
parentInitial commit. (diff)
downloaddovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz
dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/log/main.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/log/main.c b/src/log/main.c
new file mode 100644
index 0000000..a6ac950
--- /dev/null
+++ b/src/log/main.c
@@ -0,0 +1,97 @@
+/* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "lib-signals.h"
+#include "hostpid.h"
+#include "restrict-access.h"
+#include "master-interface.h"
+#include "master-service-private.h"
+#include "master-service-settings.h"
+#include "log-error-buffer.h"
+#include "log-connection.h"
+#include "doveadm-connection.h"
+
+#include <unistd.h>
+
+bool verbose_proctitle;
+char *global_log_prefix;
+static struct log_error_buffer *errorbuf;
+
+static void
+sig_reopen_logs(const siginfo_t *si ATTR_UNUSED, void *context ATTR_UNUSED)
+{
+ master_service->log_initialized = FALSE;
+ master_service_init_log_with_prefix(master_service, global_log_prefix);
+}
+
+static void main_init(void)
+{
+ lib_signals_set_handler(SIGUSR1, LIBSIG_FLAGS_SAFE,
+ sig_reopen_logs, NULL);
+
+ errorbuf = log_error_buffer_init();
+ log_connections_init();
+}
+
+static void main_deinit(void)
+{
+ log_connections_deinit();
+ log_error_buffer_deinit(&errorbuf);
+ i_free(global_log_prefix);
+}
+
+static void client_connected(struct master_service_connection *conn)
+{
+ if (conn->fifo) {
+ log_connection_create(errorbuf, conn->fd, conn->listen_fd);
+ /* kludge: normally FIFOs aren't counted as connections,
+ but here we want log process to stay open until all writers
+ have closed */
+ conn->fifo = FALSE;
+ } else if (strcmp(conn->name, "log-errors") == 0)
+ doveadm_connection_create(errorbuf, conn->fd);
+ else {
+ i_error("Unknown listener name: %s", conn->name);
+ return;
+ }
+
+ master_service_client_connection_accept(conn);
+}
+
+int main(int argc, char *argv[])
+{
+ const enum master_service_flags service_flags =
+ MASTER_SERVICE_FLAG_DONT_SEND_STATS;
+ const char *error;
+
+ master_service = master_service_init("log", service_flags,
+ &argc, &argv, "");
+
+ /* use log prefix and log to stderr until we've configured the real
+ logging */
+ global_log_prefix = i_strdup_printf("log(%s): ", my_pid);
+ i_set_failure_file("/dev/stderr", global_log_prefix);
+
+ if (master_getopt(master_service) > 0)
+ return FATAL_DEFAULT;
+
+ if (master_service_settings_read_simple(master_service,
+ NULL, &error) < 0)
+ i_fatal("Error reading configuration: %s", error);
+ master_service_init_log_with_prefix(master_service, global_log_prefix);
+
+ verbose_proctitle = master_service_settings_get(master_service)->verbose_proctitle;
+
+ restrict_access_by_env(RESTRICT_ACCESS_FLAG_ALLOW_ROOT, NULL);
+ restrict_access_allow_coredumps(TRUE);
+
+ /* logging should never die if there are some clients */
+ master_service_set_die_with_master(master_service, FALSE);
+
+ main_init();
+ master_service_init_finish(master_service);
+ master_service_run(master_service, client_connected);
+ main_deinit();
+ master_service_deinit(&master_service);
+ return 0;
+}