Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward more messages on the sd-notify socket #469

Merged
merged 1 commit into from
Dec 12, 2023
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
53 changes: 44 additions & 9 deletions src/conn_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,17 +432,52 @@ static gboolean read_remote_sock(struct remote_sock_s *sock)
sock->off = 0;

if (SOCK_IS_NOTIFY(sock->sock_type)) {
/* Do what OCI runtime does - only pass READY=1 */
/* We pass a limited amount of safe messages here, as some existing or
future ones could be security sensitive */
const char *passon_line[] = {
"READY=1", "RELOADING=1", "STOPPING=1", "WATCHDOG=1", "WATCHDOG=trigger",
};
const char *passon_prefix[] = {
"STATUS=",
"ERRNO=",
"BUSERROR=",
"MONOTONIC_USEC=",
};
char **lines;

sock->buf[num_read] = '\0';
if (strstr(sock->buf, "READY=1")) {
strncpy(sock->buf, "READY=1", 8);
sock->remaining = 7;
} else if (strstr(sock->buf, "WATCHDOG=1")) {
strncpy(sock->buf, "WATCHDOG=1", 11);
sock->remaining = 10;
} else {
sock->remaining = 0;
lines = g_strsplit_set(sock->buf, "\n\r", -1);
sock->remaining = 0;

for (size_t i = 0; lines[i] != NULL; i++) {
const char *line = lines[i];
gboolean pass_line = FALSE;

for (size_t j = 0; j < G_N_ELEMENTS(passon_line); j++) {
if (strcmp(line, passon_line[j]) == 0) {
pass_line = TRUE;
break;
}
}

for (size_t j = 0; !pass_line && j < G_N_ELEMENTS(passon_prefix); j++) {
if (g_str_has_prefix(line, passon_prefix[j])) {
pass_line = TRUE;
break;
}
}

/* This will always fit in sock->buf as we only pass through exact
bytes from an existing sock->buf */
if (pass_line) {
if (sock->remaining > 0)
sock->buf[sock->remaining++] = '\n';

memcpy(sock->buf + sock->remaining, line, strlen(line));
alexlarsson marked this conversation as resolved.
Show resolved Hide resolved
sock->remaining += strlen(line);
}
}
g_strfreev(lines);
}

if (sock->remaining)
Expand Down
Loading