]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
unit: Add LOG_CONTEXT_PUSH_UNIT() 26916/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 21 Mar 2023 13:57:29 +0000 (14:57 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 21 Mar 2023 13:59:16 +0000 (14:59 +0100)
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
src/core/unit.h

index 093d1ad5b474514cd96d69b180138ab3acf5e3b3..b448ad175e60306ef4059eb9fe35503ebf638d1f 100644 (file)
@@ -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) {
index d5a6d595e293778b5c51035648c2334a36660636..8f53773a119816d5a5baa57e43480ce1e22a576d 100644 (file)
@@ -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))