anitazha / rpms / systemd

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