Skip to content

Commit 73616c3

Browse files
committed
CDRIVER-2875 bug fix for FD_CLOEXEC
1 parent 0cfb52c commit 73616c3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/libmongoc/src/mongoc/mongoc-socket.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,17 @@ _mongoc_socket_setflags (int sd)
102102

103103
flags = fcntl (sd, F_GETFL, sd);
104104

105+
if (-1 == fcntl (sd, F_SETFL, (flags | O_NONBLOCK))) {
106+
return false;
107+
}
108+
105109
#ifdef FD_CLOEXEC
106-
return (-1 != fcntl (sd, F_SETFL, (flags | O_NONBLOCK | FD_CLOEXEC)));
107-
#else
108-
return (-1 != fcntl (sd, F_SETFL, (flags | O_NONBLOCK)));
110+
flags = fcntl (sd, F_GETFD, sd);
111+
if (-1 == fcntl (sd, F_SETFD, (flags | FD_CLOEXEC))) {
112+
return false;
113+
}
109114
#endif
110-
115+
return true;
111116
#endif
112117
}
113118

0 commit comments

Comments
 (0)