mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 09:41:54 +00:00
Flock: filedescriptor cleanups in hypervisor
This commit is contained in:
parent
eba15c08d3
commit
90ffd2e3d3
@ -471,7 +471,7 @@ container_start(void)
|
||||
|
||||
/* create socketpair before forking to do communication */
|
||||
int fds[2];
|
||||
int e = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
|
||||
int e = socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fds);
|
||||
if (e < 0)
|
||||
die("Failed to create internal socketpair: %m");
|
||||
|
||||
@ -1161,7 +1161,7 @@ hypervisor_container_fork(void)
|
||||
int fds[2], e;
|
||||
|
||||
/* create socketpair before forking to do communication */
|
||||
e = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
|
||||
e = socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fds);
|
||||
if (e < 0)
|
||||
die("Failed to create internal socketpair: %m");
|
||||
|
||||
@ -1196,6 +1196,7 @@ hypervisor_container_fork(void)
|
||||
|
||||
/* noreturn child side */
|
||||
close(fds[0]);
|
||||
hexp_cleanup_after_fork();
|
||||
container_forker_fd = fds[1];
|
||||
|
||||
this_thread_id |= 0xf000;
|
||||
|
@ -285,15 +285,15 @@ main(int argc, char **argv, char **argh UNUSED)
|
||||
* let's spawn a child to do external communication before unsharing */
|
||||
hypervisor_exposed_fork();
|
||||
|
||||
/* We also need to prepare all the hypervisor-init stuff */
|
||||
hypervisor_control_socket();
|
||||
|
||||
/* And now finally we can go for unsharing the networks */
|
||||
/* And now we can unshare the networks */
|
||||
SYSCALL(unshare, CLONE_NEWNET);
|
||||
|
||||
/* Before resuming, we also need to fork the container forker */
|
||||
/* Before running in multiple threads, we also need to fork the container forker */
|
||||
hypervisor_container_fork();
|
||||
|
||||
/* Control socket needs to exist */
|
||||
hypervisor_control_socket();
|
||||
|
||||
/* Set signal handlers as this process is init in its PID namespace */
|
||||
signal(SIGTERM, hypervisor_poweroff_sighandler);
|
||||
signal(SIGINT, hypervisor_poweroff_sighandler);
|
||||
|
@ -50,6 +50,8 @@ void hypervisor_container_request(sock *s, const char *name, const char *basedir
|
||||
void hypervisor_container_shutdown(sock *s, const char *name);
|
||||
int container_ctl_fd(const char *name);
|
||||
|
||||
void hexp_cleanup_after_fork(void);
|
||||
|
||||
extern event reboot_event, poweroff_event;
|
||||
extern event_list shutdown_event_list;
|
||||
|
||||
|
@ -356,7 +356,7 @@ hypervisor_exposed_fork(void)
|
||||
int fds[2], e;
|
||||
|
||||
/* create socketpair before forking to do communication */
|
||||
e = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
|
||||
e = socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fds);
|
||||
if (e < 0)
|
||||
die("Failed to create internal socketpair: %m");
|
||||
|
||||
@ -402,6 +402,14 @@ hypervisor_exposed_fork(void)
|
||||
birdloop_minimalist_main();
|
||||
}
|
||||
|
||||
void
|
||||
hexp_cleanup_after_fork(void)
|
||||
{
|
||||
birdloop_enter(he.loop);
|
||||
rp_free(he.p);
|
||||
birdloop_leave(he.loop);
|
||||
birdloop_free(he.loop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hypervisor's mapping between external ports and names
|
||||
|
Loading…
Reference in New Issue
Block a user