teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0412-pid1-process-zero-length-notification-messages-again.patch

a19bc6
From c7bcd6cf1967e401225c3d6057e0ee62cdc29f8c Mon Sep 17 00:00:00 2001
c79076
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
c79076
Date: Thu, 29 Sep 2016 16:06:02 +0200
c79076
Subject: [PATCH] pid1: process zero-length notification messages again
c79076
c79076
This undoes 531ac2b234. I acked that patch without looking at the code
c79076
carefully enough. There are two problems:
c79076
- we want to process the fds anyway
c79076
- in principle empty notification messages are valid, and we should
c79076
  process them as usual, including logging using log_unit_debug().
c79076
a19bc6
Cherry-picked from: 8523bf7dd514a3a2c6114b7b8fb8f308b4f09fc4
a19bc6
Resolves: #1380259
a19bc6
c79076
Cherry-picked from: a86b767
a19bc6
Resolves: #1380259
c79076
---
c79076
 src/core/manager.c | 15 ++++++---------
c79076
 1 file changed, 6 insertions(+), 9 deletions(-)
c79076
c79076
diff --git a/src/core/manager.c b/src/core/manager.c
181b3f
index ed8105955..0376c4d4b 100644
c79076
--- a/src/core/manager.c
c79076
+++ b/src/core/manager.c
c79076
@@ -1614,13 +1614,12 @@ static int manager_dispatch_cgroups_agent_fd(sd_event_source *source, int fd, ui
c79076
         return 0;
c79076
 }
c79076
 
c79076
-static void manager_invoke_notify_message(Manager *m, Unit *u, pid_t pid, char *buf, size_t n, FDSet *fds) {
c79076
+static void manager_invoke_notify_message(Manager *m, Unit *u, pid_t pid, const char *buf, FDSet *fds) {
c79076
         _cleanup_strv_free_ char **tags = NULL;
c79076
 
c79076
         assert(m);
c79076
         assert(u);
c79076
         assert(buf);
c79076
-        assert(n > 0);
c79076
 
c79076
         tags = strv_split(buf, "\n\r");
c79076
         if (!tags) {
c79076
@@ -1682,10 +1681,6 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t
c79076
                  * example... */
c79076
                 return 0;
c79076
         }
c79076
-        if (n == 0) {
c79076
-                log_debug("Got zero-length notification message. Ignoring.");
c79076
-                return 0;
c79076
-        }
c79076
 
c79076
         CMSG_FOREACH(cmsg, &msghdr) {
c79076
                 if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
c79076
@@ -1722,25 +1717,27 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t
c79076
                 return 0;
c79076
         }
c79076
 
c79076
+        /* The message should be a string. Here we make sure it's NUL-terminated,
c79076
+         * but only the part until first NUL will be used anyway. */
c79076
         buf[n] = 0;
c79076
 
c79076
         /* Notify every unit that might be interested, but try
c79076
          * to avoid notifying the same one multiple times. */
c79076
         u1 = manager_get_unit_by_pid(m, ucred->pid);
c79076
         if (u1) {
c79076
-                manager_invoke_notify_message(m, u1, ucred->pid, buf, n, fds);
c79076
+                manager_invoke_notify_message(m, u1, ucred->pid, buf, fds);
c79076
                 found = true;
c79076
         }
c79076
 
c79076
         u2 = hashmap_get(m->watch_pids1, LONG_TO_PTR(ucred->pid));
c79076
         if (u2 && u2 != u1) {
c79076
-                manager_invoke_notify_message(m, u2, ucred->pid, buf, n, fds);
c79076
+                manager_invoke_notify_message(m, u2, ucred->pid, buf, fds);
c79076
                 found = true;
c79076
         }
c79076
 
c79076
         u3 = hashmap_get(m->watch_pids2, LONG_TO_PTR(ucred->pid));
c79076
         if (u3 && u3 != u2 && u3 != u1) {
c79076
-                manager_invoke_notify_message(m, u3, ucred->pid, buf, n, fds);
c79076
+                manager_invoke_notify_message(m, u3, ucred->pid, buf, fds);
c79076
                 found = true;
c79076
         }
c79076