]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib, lib-master: Add service:<name> category for all events
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 5 Sep 2019 09:02:16 +0000 (12:02 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 5 Sep 2019 13:29:28 +0000 (13:29 +0000)
src/lib-master/master-service.c
src/lib/lib-event.c

index 0d836941938efeb0e11f31b46acfd03018843e66..737a3c15940c2d7308bbab5c27f19027608713d1 100644 (file)
@@ -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"
 
 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:<name> 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();
index aa08e4636435eee326a55327483ff1ce741323d9..55af8176aefe2330210eca76402f621ea321d46f 100644 (file)
@@ -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:<name> 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";