dcavalca / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone
36e8a3
From 7c52627446e32df64ad4cd3ac56ad515d0233cea Mon Sep 17 00:00:00 2001
36e8a3
From: Michal Sekletar <msekleta@redhat.com>
36e8a3
Date: Fri, 14 Dec 2018 15:17:27 +0100
36e8a3
Subject: [PATCH] journald: correctly attribute log messages also with
36e8a3
 cgroupsv1
36e8a3
36e8a3
With cgroupsv1 a zombie process is migrated to root cgroup in all
36e8a3
hierarchies. This was changed for unified hierarchy and /proc/PID/cgroup
36e8a3
reports cgroup to which process belonged before it exited.
36e8a3
36e8a3
Be more suspicious about cgroup path reported by the kernel and use
36e8a3
unit_id provided by the log client if the kernel reports that process is
36e8a3
running in the root cgroup.
36e8a3
36e8a3
Users tend to care the most about 'log->unit_id' mapping so systemctl
36e8a3
status can correctly report last log lines. Also we wouldn't be able to
36e8a3
infer anything useful from "/" path anyway.
36e8a3
36e8a3
See: https://github.com/torvalds/linux/commit/2e91fa7f6d451e3ea9fec999065d2fd199691f9d
36e8a3
36e8a3
(cherry picked from commit 672773b63a4ebf95242b27e63071b93073ebc1f5)
36e8a3
36e8a3
Resolves: #1658115
36e8a3
---
36e8a3
 src/journal/journald-context.c | 8 ++++++--
36e8a3
 1 file changed, 6 insertions(+), 2 deletions(-)
36e8a3
36e8a3
diff --git a/src/journal/journald-context.c b/src/journal/journald-context.c
4bff0a
index 51f79fd803..dba3525ed8 100644
36e8a3
--- a/src/journal/journald-context.c
36e8a3
+++ b/src/journal/journald-context.c
36e8a3
@@ -13,6 +13,8 @@
36e8a3
 #include "io-util.h"
36e8a3
 #include "journal-util.h"
36e8a3
 #include "journald-context.h"
36e8a3
+#include "parse-util.h"
36e8a3
+#include "path-util.h"
36e8a3
 #include "process-util.h"
36e8a3
 #include "procfs-util.h"
36e8a3
 #include "string-util.h"
36e8a3
@@ -281,9 +283,11 @@ static int client_context_read_cgroup(Server *s, ClientContext *c, const char *u
36e8a3
 
36e8a3
         /* Try to acquire the current cgroup path */
36e8a3
         r = cg_pid_get_path_shifted(c->pid, s->cgroup_root, &t);
36e8a3
-        if (r < 0) {
36e8a3
+        if (r < 0 || empty_or_root(t)) {
36e8a3
 
36e8a3
-                /* If that didn't work, we use the unit ID passed in as fallback, if we have nothing cached yet */
36e8a3
+                /* We use the unit ID passed in as fallback if we have nothing cached yet and cg_pid_get_path_shifted()
36e8a3
+                 * failed or process is running in a root cgroup. Zombie processes are automatically migrated to root cgroup
36e8a3
+                 * on cgroupsv1 and we want to be able to map log messages from them too. */
36e8a3
                 if (unit_id && !c->unit) {
36e8a3
                         c->unit = strdup(unit_id);
36e8a3
                         if (c->unit)