chiark / gitweb /
Ensure unit is journaled for short-lived or oneshot processes
authorDan McGee <dan@archlinux.org>
Sun, 8 Dec 2013 19:27:05 +0000 (13:27 -0600)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 10 Dec 2013 12:40:55 +0000 (07:40 -0500)
In the time it takes to process incoming log messages, the process we
are logging details for may exit. This means the cgroup data is no
longer available from '/proc'. Unfortunately, the way the code was
structured before, we never log _SYSTEMD_UNIT if we don't have this
cgroup information.

Add an else if case that allows the passed in unit_id to be logged even
if we couldn't capture cgroup information. This ensures a command like
`journalctl -u run-XXX` will return all log messages from a oneshot
process.

src/journal/journald-server.c

index 01e75b6629621dff8d3d3b3a6d4b89bbf553daff..fc8115c31c29922225e004fcffc63b9398f395c8 100644 (file)
@@ -626,6 +626,9 @@ static void dispatch_message_real(
                         }
 
                         free(c);
+                } else if (unit_id) {
+                        x = strappenda("_SYSTEMD_UNIT=", unit_id);
+                        IOVEC_SET_STRING(iovec[n++], x);
                 }
 
 #ifdef HAVE_SELINUX