From 6d04e12bea412089293e0fed902a37c345d74b98 Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Thu, 22 May 2025 18:41:16 -0600 Subject: [PATCH] ipc/client: Open socket with SOCK_CLOEXEC. Part-of: --- src/xrt/ipc/client/ipc_client_connection.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/xrt/ipc/client/ipc_client_connection.c b/src/xrt/ipc/client/ipc_client_connection.c index aef5617e3..c90188567 100644 --- a/src/xrt/ipc/client/ipc_client_connection.c +++ b/src/xrt/ipc/client/ipc_client_connection.c @@ -206,13 +206,21 @@ ipc_client_socket_connect(struct ipc_connection *ipc_c) static bool ipc_client_socket_connect(struct ipc_connection *ipc_c) { +#ifdef SOCK_CLOEXEC + // Make sure the socket is not inherited by child processes. For one, when there is an fd to the socket + // in the child process closing the client connection (or killing the connected process) + // may not be seen in the server as client disconnection. + const int flags = SOCK_CLOEXEC; +#else + const int flags = 0; +#endif struct sockaddr_un addr; int ret; // create our IPC socket - ret = socket(PF_UNIX, SOCK_STREAM, 0); + ret = socket(PF_UNIX, SOCK_STREAM | flags, 0); if (ret < 0) { IPC_ERROR(ipc_c, "Socket Create Error!"); return false; -- 2.51.2