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