Skip to content

ext/sockets: socket_accept setting fcntl's FD_CLOEXEC on unixes. #14606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,28 @@ static bool php_accept_connect(php_socket *in_sock, php_socket *out_sock, struct
return 0;
}

#if !defined(PHP_WIN32)
/**
* accept4 could had been used but not all platforms support it (e.g. Haiku, solaris < 11.4, ...)
* win32, not having any concept of child process, has no need to address it.
*/
int mode;

if ((mode = fcntl(out_sock->bsd_socket, F_GETFD)) < 0) {
PHP_SOCKET_ERROR(out_sock, "unable to get fcntl mode on the socket", errno);
return 0;
}

int cloexec = (mode | FD_CLOEXEC);

if (mode != cloexec) {
if (fcntl(out_sock->bsd_socket, F_SETFD, cloexec) < 0) {
PHP_SOCKET_ERROR(out_sock, "unable to set cloexec mode on the socket", errno);
return 0;
}
}
#endif

out_sock->error = 0;
out_sock->blocking = 1;
out_sock->type = la->sa_family;
Expand Down
Loading