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;