use instance-name for syslog?

SATOH Fumiyasu fumiyas at osstech.co.jp
Wed May 30 19:08:16 EEST 2018


Hi!

On Thu, 31 May 2018 00:44:58 +0900,
A. Schulze wrote:
> When running multiple instances of dovecot on the same host (or running multiple docker container),
> it is hard to distinguish logs from different processes: the syslog entries are all prefixed with the same identifier "dovecot"
> It is hardcoded here:
> https://github.com/dovecot/core/blob/master/src/lib-master/master-service.c#L420
> 
> Would it make sense to use the already implemented instance-name as syslog ident?
> How do others solve that problem?

I have a patchset to implement that. Please see the attachment.

-- 
-- Name: SATOH Fumiyasu @ OSS Technology Corp. (fumiyas @ osstech co jp)
-- Business Home: https://www.OSSTech.co.jp/
-- GitHub Home: https://GitHub.com/fumiyas/
-- PGP Fingerprint: BBE1 A1C9 525A 292E 6729  CDEC ADC2 9DCA 5E1C CBCA
-------------- next part --------------
>From 958933cd0e98f1fda68a2d4d4fc51fb8058a7914 Mon Sep 17 00:00:00 2001
From: SATOH Fumiyasu <fumiyas at osstech.co.jp>
Date: Tue, 1 Jul 2014 19:20:30 +0900
Subject: [PATCH 1/2] master: Do not prepend "dovecot-" to a process name

---
 src/master/main.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/master/main.c b/src/master/main.c
index 752c253..733fc04 100644
--- a/src/master/main.c
+++ b/src/master/main.c
@@ -86,8 +86,6 @@ void process_exec(const char *cmd, const char *extra_args[])
 	/* prefix with dovecot/ */
 	argv[0] = t_strdup_printf("%s/%s", services->set->instance_name,
 				  argv[0]);
-	if (strncmp(argv[0], PACKAGE, strlen(PACKAGE)) != 0)
-		argv[0] = t_strconcat(PACKAGE"-", argv[0], NULL);
 	(void)execv_const(executable, argv);
 }
 
-- 
2.0.1

>From 36d052adbd04f8c8a89ba66e086e22c152a5a93c Mon Sep 17 00:00:00 2001
From: SATOH Fumiyasu <fumiyas at osstech.co.jp>
Date: Tue, 1 Jul 2014 19:22:56 +0900
Subject: [PATCH 2/2] lib-master: Set instance_name to the syslog name

---
 src/lib-master/master-service-settings.c | 2 ++
 src/lib-master/master-service-settings.h | 1 +
 src/lib-master/master-service.c          | 3 ++-
 src/lib/failures.c                       | 7 ++++++-
 src/master/service-process.c             | 1 +
 5 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/lib-master/master-service-settings.c b/src/lib-master/master-service-settings.c
index 30ad936..67fca19 100644
--- a/src/lib-master/master-service-settings.c
+++ b/src/lib-master/master-service-settings.c
@@ -36,6 +36,7 @@ master_service_settings_check(void *_set, pool_t pool, const char **error_r);
 static const struct setting_define master_service_setting_defines[] = {
 	DEF(SET_STR, base_dir),
 	DEF(SET_STR, state_dir),
+	DEF(SET_STR, instance_name),
 	DEF(SET_STR, log_path),
 	DEF(SET_STR, info_log_path),
 	DEF(SET_STR, debug_log_path),
@@ -52,6 +53,7 @@ static const struct setting_define master_service_setting_defines[] = {
 static const struct master_service_settings master_service_default_settings = {
 	.base_dir = PKG_RUNDIR,
 	.state_dir = PKG_STATEDIR,
+	.instance_name = PACKAGE,
 	.log_path = "syslog",
 	.info_log_path = "",
 	.debug_log_path = "",
diff --git a/src/lib-master/master-service-settings.h b/src/lib-master/master-service-settings.h
index e5b5ace..d7f1a80 100644
--- a/src/lib-master/master-service-settings.h
+++ b/src/lib-master/master-service-settings.h
@@ -10,6 +10,7 @@ struct master_service;
 struct master_service_settings {
 	const char *base_dir;
 	const char *state_dir;
+	const char *instance_name;
 	const char *log_path;
 	const char *info_log_path;
 	const char *debug_log_path;
diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c
index 65b2753..d3e5281 100644
--- a/src/lib-master/master-service.c
+++ b/src/lib-master/master-service.c
@@ -297,7 +297,8 @@ void master_service_init_log(struct master_service *service,
 		if (!syslog_facility_find(service->set->syslog_facility,
 					  &facility))
 			facility = LOG_MAIL;
-		i_set_failure_syslog("dovecot", LOG_NDELAY, facility);
+		i_set_failure_syslog(service->set->instance_name, LOG_NDELAY,
+		                     facility);
 		i_set_failure_prefix("%s", prefix);
 
 		if (strcmp(service->set->log_path, "syslog") != 0) {
diff --git a/src/lib/failures.c b/src/lib/failures.c
index 3023ba8..0ebba3d 100644
--- a/src/lib/failures.c
+++ b/src/lib/failures.c
@@ -443,7 +443,12 @@ void i_syslog_error_handler(const struct failure_context *ctx,
 
 void i_set_failure_syslog(const char *ident, int options, int facility)
 {
-	openlog(ident, options, facility);
+	static char *syslog_ident = NULL;
+
+	i_free(syslog_ident);
+	syslog_ident = i_strdup(ident);
+
+	openlog(syslog_ident, options, facility);
 
 	i_set_fatal_handler(i_syslog_fatal_handler);
 	i_set_error_handler(i_syslog_error_handler);
diff --git a/src/master/service-process.c b/src/master/service-process.c
index bc10df1..47ee7bf 100644
--- a/src/master/service-process.c
+++ b/src/master/service-process.c
@@ -222,6 +222,7 @@ static void service_process_setup_config_environment(struct service *service)
 		/* give the log's configuration directly, so it won't depend
 		   on config process */
 		env_put("DOVECONF_ENV=1");
+		env_put(t_strconcat("INSTANCE_NAME=", set->instance_name, NULL));
 		env_put(t_strconcat("LOG_PATH=", set->log_path, NULL));
 		env_put(t_strconcat("INFO_LOG_PATH=", set->info_log_path, NULL));
 		env_put(t_strconcat("DEBUG_LOG_PATH=", set->debug_log_path, NULL));
-- 
2.0.1



More information about the dovecot mailing list