diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2019-10-08 07:32:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-08 07:32:11 +0200 |
| commit | 02d75f99b96e5d060b537863644c9b6679737b49 (patch) | |
| tree | c53c37e848d59c188eb600a2317557ca0a77d963 /drivers/unix/net_socket_posix.cpp | |
| parent | 9215e2ddf5dc5f006e00b57a46e440f02f33d150 (diff) | |
| parent | 9c91b2051a61758c8ebfb5be7f2a81dc32c5de33 (diff) | |
| download | redot-engine-02d75f99b96e5d060b537863644c9b6679737b49.tar.gz | |
Merge pull request #32616 from Faless/net/fix_close_exec
Disable socket descriptor sharing with subprocs.
Diffstat (limited to 'drivers/unix/net_socket_posix.cpp')
| -rw-r--r-- | drivers/unix/net_socket_posix.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp index 7a7d286c4d..da46b393c6 100644 --- a/drivers/unix/net_socket_posix.cpp +++ b/drivers/unix/net_socket_posix.cpp @@ -281,6 +281,21 @@ void NetSocketPosix::_set_socket(SOCKET_TYPE p_sock, IP::Type p_ip_type, bool p_ _sock = p_sock; _ip_type = p_ip_type; _is_stream = p_is_stream; + // Disable descriptor sharing with subprocesses. + _set_close_exec_enabled(true); +} + +void NetSocketPosix::_set_close_exec_enabled(bool p_enabled) { +#ifndef WINDOWS_ENABLED + // Enable close on exec to avoid sharing with subprocesses. Off by default on Windows. +#if defined(NO_FCNTL) + unsigned long par = p_enabled ? 1 : 0; + SOCK_IOCTL(_sock, FIOCLEX, &par); +#else + int opts = fcntl(_sock, F_GETFD); + fcntl(_sock, F_SETFD, opts | FD_CLOEXEC); +#endif +#endif } Error NetSocketPosix::open(Type p_sock_type, IP::Type &ip_type) { @@ -321,6 +336,9 @@ Error NetSocketPosix::open(Type p_sock_type, IP::Type &ip_type) { _is_stream = p_sock_type == TYPE_TCP; + // Disable descriptor sharing with subprocesses. + _set_close_exec_enabled(true); + #if defined(WINDOWS_ENABLED) if (!_is_stream) { // Disable windows feature/bug reporting WSAECONNRESET/WSAENETRESET when |
