From ddbfc5557bdd689e9442a79f6e4822f631a3f3e6 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Wed, 2 Oct 2024 15:03:18 +0200 Subject: [PATCH] Flock: more filedes cleanup --- flock/container.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/flock/container.c b/flock/container.c index 597e6c42..f9622762 100644 --- a/flock/container.c +++ b/flock/container.c @@ -24,6 +24,7 @@ static struct hypervisor_container_forker { struct birdloop *loop; HASH(struct container_runtime) hash; struct container_runtime *cur_crt; + int ctl[2]; /* socketpair filedescriptors */ } hcf; static struct container_config { @@ -524,7 +525,10 @@ container_start(void) if (!pid) { + /* Cleanup in control sockets */ + close(hcf.ctl[1]); close(fds[0]); + ASSERT_DIE(container_counter < 0x6000); this_thread_id -= (container_counter << 1) + 0x3000 ; container_mainloop(fds[1]); /* this never returns */ @@ -556,10 +560,13 @@ container_start(void) c->cmsg_len = CMSG_LEN(sizeof fds[0]); memcpy(CMSG_DATA(c), &fds[0], sizeof fds[0]); + log(L_INFO "Sending socket"); + e = sendmsg(container_forker_fd, &m, 0); if (e < 0) log(L_ERR "Failed to send socket: %m"); + log(L_INFO "Socket sent"); exit(0); } @@ -1158,7 +1165,7 @@ hcf_parse(byte *buf, int size) void hypervisor_container_fork(void) { - int fds[2], e; + int e, *fds = hcf.ctl; /* create socketpair before forking to do communication */ e = socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fds); @@ -1226,4 +1233,3 @@ hypervisor_container_fork(void) hcf_parse(buf, rx); } } -