100 lines
4.7 KiB
Diff
100 lines
4.7 KiB
Diff
From 70af4d17dafe81acc96f71f4ec06fbea7386bc38 Mon Sep 17 00:00:00 2001
|
|
From: Lennart Poettering <lennart@poettering.net>
|
|
Date: Thu, 21 Aug 2014 16:52:41 +0200
|
|
Subject: [PATCH] manager: don#t dispatch sd_notify() messages and SIGCHLD
|
|
multiple times to the same units
|
|
|
|
---
|
|
src/core/manager.c | 44 +++++++++++++++++++++++---------------------
|
|
1 file changed, 23 insertions(+), 21 deletions(-)
|
|
|
|
diff --git a/src/core/manager.c b/src/core/manager.c
|
|
index e488aba5f8..c91ece116f 100644
|
|
--- a/src/core/manager.c
|
|
+++ b/src/core/manager.c
|
|
@@ -562,7 +562,7 @@ static int manager_setup_notify(Manager *m) {
|
|
strncpy(sa.un.sun_path, m->notify_socket, sizeof(sa.un.sun_path)-1);
|
|
r = bind(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path));
|
|
if (r < 0) {
|
|
- log_error("bind(@%s) failed: %m", sa.un.sun_path+1);
|
|
+ log_error("bind(%s) failed: %m", sa.un.sun_path);
|
|
return -errno;
|
|
}
|
|
|
|
@@ -1398,7 +1398,7 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t
|
|
.msg_controllen = sizeof(control),
|
|
};
|
|
struct ucred *ucred;
|
|
- Unit *u;
|
|
+ Unit *u1, *u2, *u3;
|
|
|
|
n = recvmsg(m->notify_fd, &msghdr, MSG_DONTWAIT);
|
|
if (n <= 0) {
|
|
@@ -1424,21 +1424,23 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t
|
|
assert((size_t) n < sizeof(buf));
|
|
buf[n] = 0;
|
|
|
|
- u = manager_get_unit_by_pid(m, ucred->pid);
|
|
- if (u) {
|
|
- manager_invoke_notify_message(m, u, ucred->pid, buf, n);
|
|
+ /* Notify every unit that might be interested, but try
|
|
+ * to avoid notifying the same one multiple times. */
|
|
+ u1 = manager_get_unit_by_pid(m, ucred->pid);
|
|
+ if (u1) {
|
|
+ manager_invoke_notify_message(m, u1, ucred->pid, buf, n);
|
|
found = true;
|
|
}
|
|
|
|
- u = hashmap_get(m->watch_pids1, LONG_TO_PTR(ucred->pid));
|
|
- if (u) {
|
|
- manager_invoke_notify_message(m, u, ucred->pid, buf, n);
|
|
+ u2 = hashmap_get(m->watch_pids1, LONG_TO_PTR(ucred->pid));
|
|
+ if (u2 && u2 != u1) {
|
|
+ manager_invoke_notify_message(m, u2, ucred->pid, buf, n);
|
|
found = true;
|
|
}
|
|
|
|
- u = hashmap_get(m->watch_pids2, LONG_TO_PTR(ucred->pid));
|
|
- if (u) {
|
|
- manager_invoke_notify_message(m, u, ucred->pid, buf, n);
|
|
+ u3 = hashmap_get(m->watch_pids2, LONG_TO_PTR(ucred->pid));
|
|
+ if (u3 && u3 != u2 && u3 != u1) {
|
|
+ manager_invoke_notify_message(m, u3, ucred->pid, buf, n);
|
|
found = true;
|
|
}
|
|
|
|
@@ -1485,7 +1487,7 @@ static int manager_dispatch_sigchld(Manager *m) {
|
|
|
|
if (si.si_code == CLD_EXITED || si.si_code == CLD_KILLED || si.si_code == CLD_DUMPED) {
|
|
_cleanup_free_ char *name = NULL;
|
|
- Unit *u;
|
|
+ Unit *u1, *u2, *u3;
|
|
|
|
get_process_comm(si.si_pid, &name);
|
|
|
|
@@ -1499,15 +1501,15 @@ static int manager_dispatch_sigchld(Manager *m) {
|
|
|
|
/* And now figure out the unit this belongs
|
|
* to, it might be multiple... */
|
|
- u = manager_get_unit_by_pid(m, si.si_pid);
|
|
- if (u)
|
|
- invoke_sigchld_event(m, u, &si);
|
|
- u = hashmap_get(m->watch_pids1, LONG_TO_PTR(si.si_pid));
|
|
- if (u)
|
|
- invoke_sigchld_event(m, u, &si);
|
|
- u = hashmap_get(m->watch_pids2, LONG_TO_PTR(si.si_pid));
|
|
- if (u)
|
|
- invoke_sigchld_event(m, u, &si);
|
|
+ u1 = manager_get_unit_by_pid(m, si.si_pid);
|
|
+ if (u1)
|
|
+ invoke_sigchld_event(m, u1, &si);
|
|
+ u2 = hashmap_get(m->watch_pids1, LONG_TO_PTR(si.si_pid));
|
|
+ if (u2 && u2 != u1)
|
|
+ invoke_sigchld_event(m, u2, &si);
|
|
+ u3 = hashmap_get(m->watch_pids2, LONG_TO_PTR(si.si_pid));
|
|
+ if (u3 && u3 != u2 && u3 != u1)
|
|
+ invoke_sigchld_event(m, u3, &si);
|
|
}
|
|
|
|
/* And now, we actually reap the zombie. */
|