/* 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");
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");
/* noreturn child side */
close(fds[0]);
+ hexp_cleanup_after_fork();
container_forker_fd = fds[1];
this_thread_id |= 0xf000;
* 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);
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;
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");
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