diff --git a/src/core/manager.c b/src/core/manager.c index 501e37339b82f..415b411889f4e 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2285,16 +2285,35 @@ static int manager_dispatch_cgroups_agent_fd(sd_event_source *source, int fd, ui } static bool manager_process_barrier_fd(const char *buf, FDSet *fds) { + const char *p; + assert(buf); /* nothing else must be sent when using BARRIER=1 */ - if (STR_IN_SET(buf, "BARRIER=1", "BARRIER=1\n")) { - if (fdset_size(fds) != 1) - log_warning("Got incorrect number of fds with BARRIER=1, closing them."); - return true; - } else if (startswith(buf, "BARRIER=1\n") || strstr(buf, "\nBARRIER=1\n") || endswith(buf, "\nBARRIER=1")) - log_warning("Extra notification messages sent with BARRIER=1, ignoring everything."); + p = strstr(buf, "BARRIER=1"); + if (p != NULL) { + int barrier_found = -1; + + if (p == buf) { + /* Check there is nothing after BARRIER=1 */ + p += STRLEN("BARRIER=1"); + if ((p[0] == '\0') || (p[0] == '\n' && p[1] == '\0')) + barrier_found = 1; + } else { + /* Check BARRIER=1 is not at the beginning of a new line */ + if (p[-1] != '\n') + barrier_found = 0; + } + + if (barrier_found > 0) { + if (fdset_size(fds) != 1) + log_warning("Got incorrect number of fds with BARRIER=1, closing them."); + } else if (barrier_found < 0) + log_warning("Extra notification messages sent with BARRIER=1, ignoring everything."); + /* Drop the message if BARRIER=1 was found */ + return (barrier_found != 0); + } return false; }