Code above this attempted to load loginuid, if this failed for whatever reason, we'd still end up using that value (0) in place of realuid. Fix this by setting a bool when we know the loginuid is valid.
This fixes journal messages showing up in per-user journals in gnome-ostree (not configured with loginuid, but I'll shortly fix that). Signed-off-by: Colin Walters <[email protected]> --- src/journal/journald-server.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-)
>From 36b3d81d7ae53136a07e363b9246581ef1c2fa0d Mon Sep 17 00:00:00 2001 From: Colin Walters <[email protected]> Date: Tue, 12 Feb 2013 12:24:30 -0500 Subject: [PATCH] journal: Don't use loginuid if it's not valid Code above this attempted to load loginuid, if this failed for whatever reason, we'd still end up using that value (0) in place of realuid. Fix this by setting a bool when we know the loginuid is valid. This fixes journal messages showing up in per-user journals in gnome-ostree (not configured with loginuid, but I'll shortly fix that). Signed-off-by: Colin Walters <[email protected]> --- src/journal/journald-server.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 12a46e6..1375d7a 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -515,6 +515,8 @@ static void dispatch_message_real( int r; char *t; uid_t loginuid = 0, realuid = 0; + uid_t journal_uid; + bool loginuid_valid = false; assert(s); assert(iovec); @@ -571,9 +573,11 @@ static void dispatch_message_real( IOVEC_SET_STRING(iovec[n++], audit_session); r = audit_loginuid_from_pid(ucred->pid, &loginuid); - if (r >= 0) + if (r >= 0) { + loginuid_valid = true; if (asprintf(&audit_loginuid, "_AUDIT_LOGINUID=%lu", (unsigned long) loginuid) >= 0) IOVEC_SET_STRING(iovec[n++], audit_loginuid); + } t = shortened_cgroup_path(ucred->pid); if (t) { @@ -666,10 +670,14 @@ static void dispatch_message_real( assert(n <= m); - write_to_journal(s, - s->split_mode == SPLIT_NONE ? 0 : - (s->split_mode == SPLIT_UID ? realuid : - (realuid == 0 ? 0 : loginuid)), iovec, n); + if (s->split_mode == SPLIT_NONE) + journal_uid = 0; + else if (s->split_mode == SPLIT_UID || realuid == 0 || !loginuid_valid) + journal_uid = realuid; + else + journal_uid = loginuid; + + write_to_journal(s, journal_uid, iovec, n); } void server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...) { -- 1.7.1
_______________________________________________ systemd-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/systemd-devel
