struct master_service *service;
data_stack_frame_t datastack_frame_id = 0;
unsigned int count;
- const char *value;
+ const char *service_configured_name, *value;
i_assert(name != NULL);
/* NOTE: we start rooted, so keep the code minimal until
restrict_access_by_env() is called */
lib_init();
+ /* Get the service name from environment. This usually differs from the
+ service name parameter if the executable is used for multiple
+ services. For example "auth" vs "auth-worker". It can also be a
+ service with slightly different settings, like "lmtp" vs
+ "lmtp-no-quota". We don't want to use the configured name as the
+ service's primary name, because that could break some lookups (e.g.
+ auth would suddenly see service=lmtp-no-quota. However, this can be
+ very useful in events to differentiate e.g. auth master and
+ auth-worker events which might otherwise look very similar. It's
+ also useful in log prefixes. */
+ service_configured_name = getenv(MASTER_SERVICE_ENV);
+ if (service_configured_name == NULL)
+ service_configured_name = name;
/* Set a logging prefix temporarily. This will be ignored once the log
is properly initialized */
- i_set_failure_prefix("%s(init): ", name);
+ i_set_failure_prefix("%s(init): ", service_configured_name);
/* make sure all the data stack allocations during init will be freed
before we get to ioloop. the corresponding t_pop() is in
process_title_init(*argc, argv);
+ /* process_title_init() might destroy all environments.
+ Need to look this up again. */
+ service_configured_name = getenv(MASTER_SERVICE_ENV);
+ if (service_configured_name == NULL)
+ service_configured_name = name;
+
service = i_new(struct master_service, 1);
service->argc = *argc;
service->argv = *argv;
service->name = i_strdup(name);
+ service->configured_name = i_strdup(service_configured_name);
/* keep getopt_str first in case it contains "+" */
service->getopt_str = *getopt_str == '\0' ?
i_strdup(master_service_getopt_string()) :
we want to log */
if (getenv("LOG_SERVICE") != NULL)
i_set_failure_internal();
- if (getenv("USER") != NULL)
- i_set_failure_prefix("%s(%s): ", name, getenv("USER"));
- else
- i_set_failure_prefix("%s: ", name);
+ if (getenv("USER") != NULL) {
+ i_set_failure_prefix("%s(%s): ", service->configured_name,
+ getenv("USER"));
+ } else {
+ i_set_failure_prefix("%s: ", service->configured_name);
+ }
master_service_category_name =
- i_strdup_printf("service:%s", service->name);
+ i_strdup_printf("service:%s", service->configured_name);
master_service_category.name = master_service_category_name;
event_register_callback(master_service_event_callback);
return service->name;
}
+const char *master_service_get_configured_name(struct master_service *service)
+{
+ return service->configured_name;
+}
+
void master_service_run(struct master_service *service,
master_service_connection_callback_t *callback)
{
i_free(service->listeners[i].name);
i_free(service->listeners);
i_free(service->getopt_str);
+ i_free(service->configured_name);
i_free(service->name);
i_free(service->config_path);
i_free(service);