]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/service: set unit log context in helper processes that bypass cgroup
authorMike Yuan <me@yhndnzj.com>
Sat, 13 Dec 2025 16:56:51 +0000 (17:56 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 16 Dec 2025 11:49:06 +0000 (12:49 +0100)
Since these helper processes aren't spawned in the unit cgroup,
let's explicitly attach unit log context so that all logging gets
attributed to the unit, including the ones done in library calls.

src/core/service.c

index 31f481a7f08f0107abdb69c9d487be1733c57b7b..7098e2744a9369df45f70b918c98f8daed1b8443 100644 (file)
@@ -2888,8 +2888,9 @@ static void service_enter_refresh_extensions(Service *s) {
                 goto fail;
         }
         if (r == 0) {
-                PidRef *unit_pid = &s->main_pid;
-                assert(pidref_is_set(unit_pid));
+                LOG_CONTEXT_PUSH_UNIT(UNIT(s));
+
+                assert(pidref_is_set(&s->main_pid));
 
                 _cleanup_free_ char *propagate_dir = path_join("/run/systemd/propagate/", UNIT(s)->id);
                 if (!propagate_dir) {
@@ -2912,7 +2913,7 @@ static void service_enter_refresh_extensions(Service *s) {
                 /* Only reload confext, and not sysext as they also typically contain the executable(s) used
                  * by the service and a simply reload cannot meaningfully handle that. */
                 r = refresh_extensions_in_namespace(
-                                unit_pid,
+                                &s->main_pid,
                                 "SYSTEMD_CONFEXT_HIERARCHIES",
                                 &p);
                 if (r < 0)
@@ -5593,6 +5594,8 @@ static int service_live_mount(
                 goto fail;
         }
         if (r == 0) {
+                LOG_CONTEXT_PUSH_UNIT(u);
+
                 if (flags & MOUNT_IN_NAMESPACE_IS_IMAGE)
                         r = mount_image_in_namespace(
                                         &s->main_pid,