From 4b2af439eb3f56ae309f26e7ce08a8eb573ca417 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 21 Mar 2023 14:57:29 +0100 Subject: [PATCH] unit: Add LOG_CONTEXT_PUSH_UNIT() A helper macro to push all unit related fields onto the log context. We also modify exec_spawn() to use it. --- src/core/execute.c | 2 ++ src/core/unit.h | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/core/execute.c b/src/core/execute.c index 093d1ad5b47..b448ad175e6 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -5474,6 +5474,8 @@ int exec_spawn(Unit *unit, assert(params); assert(params->fds || (params->n_socket_fds + params->n_storage_fds <= 0)); + LOG_CONTEXT_PUSH_UNIT(unit); + if (context->std_input == EXEC_INPUT_SOCKET || context->std_output == EXEC_OUTPUT_SOCKET || context->std_error == EXEC_OUTPUT_SOCKET) { diff --git a/src/core/unit.h b/src/core/unit.h index d5a6d595e29..8f53773a119 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -1208,3 +1208,13 @@ typedef struct UnitForEachDependencyData { /* Note: this matches deps that have *any* of the atoms specified in match_atom set */ #define UNIT_FOREACH_DEPENDENCY(other, u, match_atom) \ _UNIT_FOREACH_DEPENDENCY(other, u, match_atom, UNIQ_T(data, UNIQ)) + +#define _LOG_CONTEXT_PUSH_UNIT(unit, u, c) \ + const Unit *u = (unit); \ + const ExecContext *c = unit_get_exec_context(u); \ + LOG_CONTEXT_PUSH_KEY_VALUE(u->manager->unit_log_field, u->id); \ + LOG_CONTEXT_PUSH_KEY_VALUE(u->manager->invocation_log_field, u->invocation_id_string); \ + LOG_CONTEXT_PUSH_IOV(c ? c->log_extra_fields : NULL, c ? c->n_log_extra_fields : 0) + +#define LOG_CONTEXT_PUSH_UNIT(unit) \ + _LOG_CONTEXT_PUSH_UNIT(unit, UNIQ_T(u, UNIQ), UNIQ_T(c, UNIQ)) -- 2.47.3