Skip to content
Draft
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/conmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ int main(int argc, char *argv[])
error_msg = buf;
}
/* Always report failure to parent, even if we couldn't read stderr */
if (sync_pipe_fd > 0) {
if (sync_pipe_fd >= 0) {
int to_report = -1;
if (opt_exec && container_status > 0) {
to_report = -1 * container_status;
Expand All @@ -389,7 +389,7 @@ int main(int argc, char *argv[])
}

if (opt_terminal && mainfd_stdout == -1) {
if (sync_pipe_fd > 0)
if (sync_pipe_fd >= 0)
write_or_close_sync_fd(&sync_pipe_fd, -1, "Runtime did not set up terminal");
nexit("Runtime did not set up terminal");
}
Expand All @@ -398,6 +398,8 @@ int main(int argc, char *argv[])
_cleanup_free_ char *contents = NULL;
if (!g_file_get_contents(opt_container_pid_file, &contents, NULL, &err)) {
nwarnf("Failed to read pidfile: %s", err->message);
if (sync_pipe_fd >= 0)
write_or_close_sync_fd(&sync_pipe_fd, -1, err->message);
exit(1);
}

Expand Down
6 changes: 5 additions & 1 deletion src/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "cmsg.h"
#include "cli.h" // opt_bundle_path
#include "seccomp_notify.h"
#include "parent_pipe_fd.h"

#include <sys/ioctl.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -47,7 +48,10 @@ gboolean terminal_accept_cb(int fd, G_GNUC_UNUSED GIOCondition condition, G_GNUC
struct file_t console = recvfd(connfd);

if (console.fd < 0) {
pexit("Failed to receive console file descriptor");
if (sync_pipe_fd >= 0) {
write_or_close_sync_fd(&sync_pipe_fd, -1, "Failed to receive console file descriptor");
}
nexit("Failed to receive console file descriptor");
}

ndebugf("console = {.name = '%s'; .fd = %d}", console.name, console.fd);
Expand Down
7 changes: 5 additions & 2 deletions src/parent_pipe_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ void write_or_close_sync_fd(int *fd, int res, const char *message)

ssize_t len;

if (*fd == -1)
if (*fd == -1) {
return;
}

_cleanup_free_ char *json = NULL;
if (message && strlen(message) > 0) {
Expand All @@ -62,8 +63,10 @@ void write_or_close_sync_fd(int *fd, int res, const char *message)
}

len = strlen(json);
if (write_all(*fd, json, len) != len) {
ssize_t written = write_all(*fd, json, len);
if (written != len) {
if (errno == EPIPE) {
nwarnf("Got EPIPE when writing to sync_pipe_fd, closing it");
close(*fd);
*fd = -1;
return;
Expand Down
Loading