Skip to content

Commit

Permalink
pid1: process zero-length notification messages again
Browse files Browse the repository at this point in the history
This undoes 531ac2b. I acked that patch without looking at the code
carefully enough. There are two problems:
- we want to process the fds anyway
- in principle empty notification messages are valid, and we should
  process them as usual, including logging using log_unit_debug().
  • Loading branch information
keszybz authored and martinpitt committed Sep 29, 2016
1 parent 9987750 commit 8523bf7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/core/manager.c
Expand Up @@ -1657,13 +1657,12 @@ static int manager_dispatch_cgroups_agent_fd(sd_event_source *source, int fd, ui
return 0; 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; _cleanup_strv_free_ char **tags = NULL;


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


tags = strv_split(buf, "\n\r"); tags = strv_split(buf, "\n\r");
if (!tags) { if (!tags) {
Expand Down Expand Up @@ -1725,10 +1724,6 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t
* example... */ * example... */
return 0; return 0;
} }
if (n == 0) {
log_debug("Got zero-length notification message. Ignoring.");
return 0;
}


CMSG_FOREACH(cmsg, &msghdr) { CMSG_FOREACH(cmsg, &msghdr) {
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
Expand Down Expand Up @@ -1765,25 +1760,27 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t
return 0; 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; buf[n] = 0;


/* Notify every unit that might be interested, but try /* Notify every unit that might be interested, but try
* to avoid notifying the same one multiple times. */ * to avoid notifying the same one multiple times. */
u1 = manager_get_unit_by_pid_cgroup(m, ucred->pid); u1 = manager_get_unit_by_pid_cgroup(m, ucred->pid);
if (u1) { 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; found = true;
} }


u2 = hashmap_get(m->watch_pids1, PID_TO_PTR(ucred->pid)); u2 = hashmap_get(m->watch_pids1, PID_TO_PTR(ucred->pid));
if (u2 && u2 != u1) { 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; found = true;
} }


u3 = hashmap_get(m->watch_pids2, PID_TO_PTR(ucred->pid)); u3 = hashmap_get(m->watch_pids2, PID_TO_PTR(ucred->pid));
if (u3 && u3 != u2 && u3 != u1) { 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; found = true;
} }


Expand Down

0 comments on commit 8523bf7

Please sign in to comment.