a52f674
From 66d0783137db1d37f0cdc904773087878da469ce Mon Sep 17 00:00:00 2001
b12ff75
From: Dan McGee <dan@archlinux.org>
b12ff75
Date: Sun, 8 Dec 2013 13:27:05 -0600
b12ff75
Subject: [PATCH] Ensure unit is journaled for short-lived or oneshot processes
b12ff75
b12ff75
In the time it takes to process incoming log messages, the process we
b12ff75
are logging details for may exit. This means the cgroup data is no
b12ff75
longer available from '/proc'. Unfortunately, the way the code was
b12ff75
structured before, we never log _SYSTEMD_UNIT if we don't have this
b12ff75
cgroup information.
b12ff75
b12ff75
Add an else if case that allows the passed in unit_id to be logged even
b12ff75
if we couldn't capture cgroup information. This ensures a command like
b12ff75
`journalctl -u run-XXX` will return all log messages from a oneshot
b12ff75
process.
a52f674
a52f674
(cherry picked from commit 2d43b190901902dbd98ccea77c1d1ddc9e2a9955)
b12ff75
---
b12ff75
 src/journal/journald-server.c | 3 +++
b12ff75
 1 file changed, 3 insertions(+)
b12ff75
b12ff75
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
1cc3df3
index a0a8e9c468..1fcb3d5783 100644
b12ff75
--- a/src/journal/journald-server.c
b12ff75
+++ b/src/journal/journald-server.c
b12ff75
@@ -626,6 +626,9 @@ static void dispatch_message_real(
b12ff75
                         }
b12ff75
 
b12ff75
                         free(c);
b12ff75
+                } else if (unit_id) {
b12ff75
+                        x = strappenda("_SYSTEMD_UNIT=", unit_id);
b12ff75
+                        IOVEC_SET_STRING(iovec[n++], x);
b12ff75
                 }
b12ff75
 
b12ff75
 #ifdef HAVE_SELINUX