Skip to content

set CLOEXEC on diagnostic server FDs #55850

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

Merged
merged 4 commits into from
Jul 18, 2021
Merged
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
26 changes: 23 additions & 3 deletions src/native/eventpipe/ds-ipc-pal-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,22 @@ ipc_socket_create_uds (DiagnosticsIpc *ipc)
EP_ASSERT (ipc->server_address_family == AF_UNIX);

ds_ipc_socket_t new_socket = DS_IPC_INVALID_SOCKET;
int socket_type = SOCK_STREAM;
#ifdef SOCK_CLOEXEC
socket_type |= SOCK_CLOEXEC;
#endif // SOCK_CLOEXEC
DS_ENTER_BLOCKING_PAL_SECTION;
new_socket = socket (ipc->server_address_family, SOCK_STREAM, 0);
new_socket = socket (ipc->server_address_family, socket_type, 0);
#ifndef SOCK_CLOEXEC
if (new_socket != DS_IPC_INVALID_SOCKET) {
if (fcntl (new_socket, F_SETFD, FD_CLOEXEC) == -1) {
EP_ASSERT (!"Failed to set CLOEXEC");
}
}
#endif // SOCK_CLOEXEC
DS_EXIT_BLOCKING_PAL_SECTION;
return new_socket;
#endif
#endif // DS_IPC_PAL_AF_UNIX
return DS_IPC_INVALID_SOCKET;
}

Expand All @@ -337,9 +348,18 @@ ipc_socket_create_tcp (DiagnosticsIpc *ipc)
#endif

ds_ipc_socket_t new_socket = DS_IPC_INVALID_SOCKET;
int socket_type = SOCK_STREAM;
#ifdef SOCK_CLOEXEC
socket_type |= SOCK_CLOEXEC;
#endif // SOCK_CLOEXEC
DS_ENTER_BLOCKING_PAL_SECTION;
new_socket = socket (ipc->server_address_family, SOCK_STREAM, IPPROTO_TCP);
new_socket = socket (ipc->server_address_family, socket_type, IPPROTO_TCP);
if (new_socket != DS_IPC_INVALID_SOCKET) {
#ifndef SOCK_CLOEXEC
if (fcntl (new_socket, F_SETFD, FD_CLOEXEC) == -1) {
EP_ASSERT (!"Failed to set CLOEXEC");
}
#endif // SOCK_CLOEXEC
int option_value = 1;
setsockopt (new_socket, IPPROTO_TCP, TCP_NODELAY, (const char*)&option_value, sizeof (option_value));
if (ipc->mode == DS_IPC_CONNECTION_MODE_LISTEN) {
Expand Down