From: Timo Sirainen Date: Thu, 5 Sep 2019 09:02:16 +0000 (+0300) Subject: lib, lib-master: Add service: category for all events X-Git-Tag: 2.3.9~169 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7bc9149b7f6f422eeef62b6fc8ecace5d25a092f;p=thirdparty%2Fdovecot%2Fcore.git lib, lib-master: Add service: category for all events --- diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index 0d83694193..737a3c1594 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -2,6 +2,7 @@ #include "lib.h" #include "lib-signals.h" +#include "lib-event-private.h" #include "event-filter.h" #include "ioloop.h" #include "path-util.h" @@ -44,6 +45,11 @@ struct master_service *master_service; +static struct event_category master_service_category = { + .name = NULL, /* set dynamically later */ +}; +static char *master_service_category_name; + static void master_service_io_listeners_close(struct master_service *service); static void master_service_refresh_login_state(struct master_service *service); static void @@ -120,6 +126,22 @@ sig_state_changed(const siginfo_t *si ATTR_UNUSED, void *context) master_service_refresh_login_state(service); } +static bool +master_service_event_callback(struct event *event, + enum event_callback_type type, + struct failure_context *ctx ATTR_UNUSED, + const char *fmt ATTR_UNUSED, + va_list args ATTR_UNUSED) +{ + if (type == EVENT_CALLBACK_TYPE_CREATE && event->parent == NULL) { + /* Add service: category for all events. It's enough + to do it only for root events, because all other events + inherit the category from them. */ + event_add_category(event, &master_service_category); + } + return TRUE; +} + static void master_service_verify_version_string(struct master_service *service) { if (service->version_string != NULL && @@ -279,6 +301,11 @@ master_service_init(const char *name, enum master_service_flags flags, else i_set_failure_prefix("%s: ", name); + master_service_category_name = + i_strdup_printf("service:%s", service->name); + master_service_category.name = master_service_category_name; + event_register_callback(master_service_event_callback); + /* Initialize debug logging */ value = getenv(DOVECOT_LOG_DEBUG_ENV); if (value != NULL) { @@ -1030,6 +1057,9 @@ void master_service_deinit(struct master_service **_service) settings_parser_deinit(&service->set_parser); pool_unref(&service->set_pool); } + i_free(master_service_category_name); + master_service_category.name = NULL; + event_unregister_callback(master_service_event_callback); lib_signals_deinit(); /* run atexit callbacks before destroying ioloop */ lib_atexit_run(); diff --git a/src/lib/lib-event.c b/src/lib/lib-event.c index aa08e46364..55af8176ae 100644 --- a/src/lib/lib-event.c +++ b/src/lib/lib-event.c @@ -947,6 +947,12 @@ bool event_import_unescaped(struct event *event, const char *const *args, { const char *error; + /* Event's create callback has already added service: category. + This imported event may be coming from another service process + though, so clear it out. */ + if (array_is_created(&event->categories)) + array_clear(&event->categories); + /* required fields: */ if (args[0] == NULL) { *error_r = "Missing required fields";