anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0192-journald-simplify-context-handling.patch

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