From eaf067fa589ea75b5646d3e8f052e234a8c77fb2 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 10 Aug 2022 16:42:40 +0100 Subject: [PATCH] server: vsock: Use fallback path for creating socket without SOCK_CLOEXEC macOS lacks SOCK_CLOEXEC but surprisingly does define AF_VSOCK etc. (I have no idea if it actually works). Use the usual fallback path and remove the incorrect comment. --- server/sockets.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/sockets.c b/server/sockets.c index 5a8dc9f9..08f46e6b 100644 --- a/server/sockets.c +++ b/server/sockets.c @@ -293,10 +293,14 @@ bind_vsock (sockets *socks) exit (EXIT_FAILURE); } - /* Any platform with AF_VSOCK also supports SOCK_CLOEXEC so there is - * no fallback path. - */ +#ifdef SOCK_CLOEXEC sock = socket (AF_VSOCK, SOCK_STREAM|SOCK_CLOEXEC, 0); +#else + /* Fortunately, this code is only run at startup, so there is no + * risk of the fd leaking to a plugin's fork() + */ + sock = set_cloexec (socket (AF_VSOCK, SOCK_STREAM, 0)); +#endif if (sock == -1) { perror ("bind_vsock: socket"); exit (EXIT_FAILURE); -- 2.11.4.GIT