From: Daan De Meyer Date: Tue, 21 Mar 2023 13:57:29 +0000 (+0100) Subject: unit: Add LOG_CONTEXT_PUSH_UNIT() X-Git-Tag: v254-rc1~952^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4b2af439eb3f56ae309f26e7ce08a8eb573ca417;p=thirdparty%2Fsystemd.git 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. --- 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))