aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-05-10 13:15:52 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-05-10 13:15:52 +0200
commit0328e2a1f7d452bb33e6125552f15c0a049a1016 (patch)
treeff4fb5530a4ec9d1d4e1d996e3e41a95d716fc9a
parent6f89dc3650847e970dd9d0d5c986793e22b73a00 (diff)
downloadpasst-0328e2a1f7d452bb33e6125552f15c0a049a1016.tar
passt-0328e2a1f7d452bb33e6125552f15c0a049a1016.tar.gz
passt-0328e2a1f7d452bb33e6125552f15c0a049a1016.tar.bz2
passt-0328e2a1f7d452bb33e6125552f15c0a049a1016.tar.lz
passt-0328e2a1f7d452bb33e6125552f15c0a049a1016.tar.xz
passt-0328e2a1f7d452bb33e6125552f15c0a049a1016.tar.zst
passt-0328e2a1f7d452bb33e6125552f15c0a049a1016.zip
passt: Don't fork into background until the UNIX domain socket isn't listening
Once passt forks to background, it should be guaranteed that the UNIX domain socket is available, otherwise, if qemu is started right after it, it might fail to connect. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--passt.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/passt.c b/passt.c
index 1fa9ce2..228a886 100644
--- a/passt.c
+++ b/passt.c
@@ -757,10 +757,6 @@ int main(int argc, char **argv)
openlog("passt", LOG_PERROR, LOG_DAEMON);
#else
openlog("passt", 0, LOG_DAEMON);
- if (daemon(0, 0)) {
- fprintf(stderr, "Failed to fork into background\n");
- exit(EXIT_FAILURE);
- }
#endif
get_routes(&c);
@@ -812,6 +808,13 @@ listen:
info(" kvm ... -net socket,connect="
UNIX_SOCK_PATH " -net nic,model=virtio");
+#ifndef DEBUG
+ if (daemon(0, 0)) {
+ fprintf(stderr, "Failed to fork into background\n");
+ exit(EXIT_FAILURE);
+ }
+#endif
+
c.fd_unix = accept(fd_unix, NULL, NULL);
ev.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP;
ev.data.fd = c.fd_unix;