Skip to content

Commit 537766e

Browse files
committed
apply only if not already done
1 parent 75bf3dd commit 537766e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ext/sockets/sockets.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,19 @@ static bool php_accept_connect(php_socket *in_sock, php_socket *out_sock, struct
274274
* accept4 could had been used but not all platforms support it (e.g. Haiku, solaris < 11.4, ...)
275275
* win32, not having any concept of child process, has no need to address it.
276276
*/
277+
int mode;
277278

278-
if (fcntl(out_sock->bsd_socket, F_GETFD, FD_CLOEXEC) < 0) {
279-
PHP_SOCKET_ERROR(out_sock, "unable to set cloexec mode on the socket", errno);
279+
if ((mode = fcntl(out_sock->bsd_socket, F_GETFD)) < 0) {
280+
PHP_SOCKET_ERROR(out_sock, "unable to get fcntl mode on the socket", errno);
280281
return 0;
281282
}
283+
284+
if (mode != (mode | FD_CLOEXEC)) {
285+
if (fcntl(out_sock->bsd_socket, F_SETFD, FD_CLOEXEC) < 0) {
286+
PHP_SOCKET_ERROR(out_sock, "unable to set cloexec mode on the socket", errno);
287+
return 0;
288+
}
289+
}
282290
#endif
283291

284292
out_sock->error = 0;

0 commit comments

Comments
 (0)