From 64e6d5b2597541c85a9a83395467ccee713f1b57 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 1 Jul 2009 12:11:53 +0200 Subject: [PATCH] ntdll: Avoid the close-on-exec race with recvmsg() on kernels that support this. --- dlls/ntdll/server.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c index 7651a17899..a2ba2cd8aa 100644 --- a/dlls/ntdll/server.c +++ b/dlls/ntdll/server.c @@ -81,6 +81,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(server); #define SCM_RIGHTS 1 #endif +#ifndef MSG_CMSG_CLOEXEC +#define MSG_CMSG_CLOEXEC 0 +#endif + #define SOCKETNAME "socket" /* name of the socket file */ #define LOCKNAME "lock" /* name of the lock file */ @@ -406,12 +410,12 @@ static int receive_fd( obj_handle_t *handle ) for (;;) { - if ((ret = recvmsg( fd_socket, &msghdr, 0 )) > 0) + if ((ret = recvmsg( fd_socket, &msghdr, MSG_CMSG_CLOEXEC )) > 0) { #ifndef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS fd = cmsg.fd; #endif - if (fd != -1) fcntl( fd, F_SETFD, 1 ); /* set close on exec flag */ + if (fd != -1) fcntl( fd, F_SETFD, FD_CLOEXEC ); /* in case MSG_CMSG_CLOEXEC is not supported */ return fd; } if (!ret) break; -- 2.33.8