summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-03-21 14:57:29 +0100
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-03-21 14:59:16 +0100
commit4b2af439eb3f56ae309f26e7ce08a8eb573ca417 (patch)
tree7982b38356145acee792752f7ce114846a8c33e4 /src
parent81b3565efdb08df93596cc7a79ece57b528a69f3 (diff)
downloadsystemd-4b2af439eb3f56ae309f26e7ce08a8eb573ca417.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/core/execute.c2
-rw-r--r--src/core/unit.h10
2 files changed, 12 insertions, 0 deletions
diff --git a/src/core/execute.c b/src/core/execute.c
index 093d1ad5b4..b448ad175e 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 d5a6d595e2..8f53773a11 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))