ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
923a60
From da4f4b5c330ad648c9ca9c33e1f0e65148042c12 Mon Sep 17 00:00:00 2001
923a60
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
923a60
Date: Sat, 6 Jun 2015 21:36:52 -0400
923a60
Subject: [PATCH] journald: simplify context handling
923a60
923a60
By using our homegrown function we can dispense with all the iffdefery.
923a60
923a60
Cherry-picked from: 2de56f7
923a60
Related: #1230190
923a60
---
923a60
 src/journal/journald-stream.c | 29 ++++++++---------------------
923a60
 1 file changed, 8 insertions(+), 21 deletions(-)
923a60
923a60
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
923a60
index 11b852d39d..15a554c34d 100644
923a60
--- a/src/journal/journald-stream.c
923a60
+++ b/src/journal/journald-stream.c
923a60
@@ -57,10 +57,7 @@ struct StdoutStream {
923a60
         int fd;
923a60
 
923a60
         struct ucred ucred;
923a60
-#ifdef HAVE_SELINUX
923a60
-        security_context_t security_context;
923a60
-#endif
923a60
-
923a60
+        char *label;
923a60
         char *identifier;
923a60
         char *unit_id;
923a60
         int priority;
923a60
@@ -84,8 +81,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
923a60
         char syslog_facility[sizeof("SYSLOG_FACILITY=")-1 + DECIMAL_STR_MAX(int) + 1];
923a60
         _cleanup_free_ char *message = NULL, *syslog_identifier = NULL;
923a60
         unsigned n = 0;
923a60
-        char *label = NULL;
923a60
-        size_t label_len = 0;
923a60
+        size_t label_len;
923a60
 
923a60
         assert(s);
923a60
         assert(p);
923a60
@@ -130,14 +126,8 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
923a60
         if (message)
923a60
                 IOVEC_SET_STRING(iovec[n++], message);
923a60
 
923a60
-#ifdef HAVE_SELINUX
923a60
-        if (s->security_context) {
923a60
-                label = (char*) s->security_context;
923a60
-                label_len = strlen((char*) s->security_context);
923a60
-        }
923a60
-#endif
923a60
-
923a60
-        server_dispatch_message(s->server, iovec, n, ELEMENTSOF(iovec), &s->ucred, NULL, label, label_len, s->unit_id, priority, 0);
923a60
+        label_len = s->label ? strlen(s->label) : 0;
923a60
+        server_dispatch_message(s->server, iovec, n, ELEMENTSOF(iovec), &s->ucred, NULL, s->label, label_len, s->unit_id, priority, 0);
923a60
         return 0;
923a60
 }
923a60
 
923a60
@@ -343,11 +333,7 @@ void stdout_stream_free(StdoutStream *s) {
923a60
 
923a60
         safe_close(s->fd);
923a60
 
923a60
-#ifdef HAVE_SELINUX
923a60
-        if (s->security_context)
923a60
-                freecon(s->security_context);
923a60
-#endif
923a60
-
923a60
+        free(s->label);
923a60
         free(s->identifier);
923a60
         free(s->unit_id);
923a60
         free(s);
923a60
@@ -396,8 +382,9 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
923a60
 
923a60
 #ifdef HAVE_SELINUX
923a60
         if (mac_selinux_use()) {
923a60
-                if (getpeercon(fd, &stream->security_context) < 0 && errno != ENOPROTOOPT)
923a60
-                        log_error_errno(errno, "Failed to determine peer security context: %m");
923a60
+                r = getpeersec(fd, &stream->label);
923a60
+                if (r < 0 && r != -EOPNOTSUPP)
923a60
+                        (void) log_warning_errno(r, "Failed to determine peer security context: %m");
923a60
         }
923a60
 #endif
923a60