ntdll: Avoid the close-on-exec race with recvmsg() on kernels that support this.
authorAlexandre Julliard <julliard@winehq.org>
Wed, 1 Jul 2009 10:11:53 +0000 (12:11 +0200)
committerTest Robot <wine-patches-test@office.etersoft.ru>
Fri, 1 Apr 2011 17:27:02 +0000 (21:27 +0400)
dlls/ntdll/server.c

index 7651a1789904a2755afdbc52f93cb95909dba8b0..a2ba2cd8aaf5b240d42ab05cde0134480b4ef069 100644 (file)
@@ -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;