Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/core/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1657,13 +1657,12 @@ static int manager_dispatch_cgroups_agent_fd(sd_event_source *source, int fd, ui
return 0;
}

static void manager_invoke_notify_message(Manager *m, Unit *u, pid_t pid, const char *buf, size_t n, FDSet *fds) {
static void manager_invoke_notify_message(Manager *m, Unit *u, pid_t pid, const char *buf, FDSet *fds) {
_cleanup_strv_free_ char **tags = NULL;

assert(m);
assert(u);
assert(buf);
assert(n > 0);

tags = strv_split(buf, "\n\r");
if (!tags) {
Expand All @@ -1673,8 +1672,14 @@ static void manager_invoke_notify_message(Manager *m, Unit *u, pid_t pid, const

if (UNIT_VTABLE(u)->notify_message)
UNIT_VTABLE(u)->notify_message(u, pid, tags, fds);
else
log_unit_debug(u, "Got notification message for unit. Ignoring.");
else if (_unlikely_(log_get_max_level() >= LOG_DEBUG)) {
_cleanup_free_ char *x = NULL, *y = NULL;

x = cescape(buf);
if (x)
y = ellipsize(x, 20, 90);
log_unit_debug(u, "Got notification message \"%s\", ignoring.", strnull(y));
}
}

static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
Expand Down Expand Up @@ -1721,10 +1726,6 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t

return -errno;
}
if (n == 0) {
log_debug("Got zero-length notification message. Ignoring.");
return 0;
}

CMSG_FOREACH(cmsg, &msghdr) {
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
Expand Down Expand Up @@ -1760,25 +1761,27 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t
return 0;
}

/* The message should be a string. Here we make sure it's NUL-terminated,
* but only the part until first NUL will be used anyway. */
buf[n] = 0;

/* Notify every unit that might be interested, but try
* to avoid notifying the same one multiple times. */
u1 = manager_get_unit_by_pid_cgroup(m, ucred->pid);
if (u1) {
manager_invoke_notify_message(m, u1, ucred->pid, buf, n, fds);
manager_invoke_notify_message(m, u1, ucred->pid, buf, fds);
found = true;
}

u2 = hashmap_get(m->watch_pids1, PID_TO_PTR(ucred->pid));
if (u2 && u2 != u1) {
manager_invoke_notify_message(m, u2, ucred->pid, buf, n, fds);
manager_invoke_notify_message(m, u2, ucred->pid, buf, fds);
found = true;
}

u3 = hashmap_get(m->watch_pids2, PID_TO_PTR(ucred->pid));
if (u3 && u3 != u2 && u3 != u1) {
manager_invoke_notify_message(m, u3, ucred->pid, buf, n, fds);
manager_invoke_notify_message(m, u3, ucred->pid, buf, fds);
found = true;
}

Expand Down