[dart:io] Always use O_CLOEXEC instead of FD_CLOEXEC on Linux.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/60252
Change-Id: Ide6d156d8a7c569984d4fa702dc32ac08f9ee9e1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426580
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak
2025-05-05 13:07:38 -07:00
committed by Commit Queue
parent 5d0d9e467c
commit 25dfb5420d
3 changed files with 6 additions and 34 deletions
+2 -12
View File
@@ -73,30 +73,20 @@ static void AddToEpollInstance(intptr_t epoll_fd_, DescriptorInfo* di) {
EventHandlerImplementation::EventHandlerImplementation()
: socket_map_(&SimpleHashMap::SamePointerValue, 16) {
intptr_t result;
result = NO_RETRY_EXPECTED(pipe(interrupt_fds_));
result = NO_RETRY_EXPECTED(pipe2(interrupt_fds_, O_CLOEXEC));
if (result != 0) {
FATAL("Pipe creation failed");
}
if (!FDUtils::SetNonBlocking(interrupt_fds_[0])) {
FATAL("Failed to set pipe fd non blocking\n");
}
if (!FDUtils::SetCloseOnExec(interrupt_fds_[0])) {
FATAL("Failed to set pipe fd close on exec\n");
}
if (!FDUtils::SetCloseOnExec(interrupt_fds_[1])) {
FATAL("Failed to set pipe fd close on exec\n");
}
shutdown_ = false;
// The initial size passed to epoll_create is ignore on newer (>=
// 2.6.8) Linux versions
const int kEpollInitialSize = 64;
epoll_fd_ = NO_RETRY_EXPECTED(epoll_create(kEpollInitialSize));
epoll_fd_ = NO_RETRY_EXPECTED(epoll_create1(O_CLOEXEC));
if (epoll_fd_ == -1) {
FATAL("Failed creating epoll file descriptor: %i", errno);
}
if (!FDUtils::SetCloseOnExec(epoll_fd_)) {
FATAL("Failed to set epoll fd close on exec\n");
}
// Register the interrupt_fd with the epoll instance.
struct epoll_event event;
event.events = EPOLLIN;
+2 -12
View File
@@ -18,18 +18,8 @@ namespace dart {
namespace bin {
bool FDUtils::SetCloseOnExec(intptr_t fd) {
intptr_t status;
status = NO_RETRY_EXPECTED(fcntl(fd, F_GETFD));
if (status < 0) {
perror("fcntl(F_GETFD) failed");
return false;
}
status |= FD_CLOEXEC;
if (NO_RETRY_EXPECTED(fcntl(fd, F_SETFD, status)) < 0) {
perror("fcntl(F_SETFD, FD_CLOEXEC) failed");
return false;
}
return true;
FATAL("Use O_CLOEXEC instead");
return false;
}
static bool SetBlockingHelper(intptr_t fd, bool blocking) {
+2 -10
View File
@@ -252,7 +252,8 @@ intptr_t ServerSocket::Accept(intptr_t fd) {
intptr_t socket;
struct sockaddr clientaddr;
socklen_t addrlen = sizeof(clientaddr);
socket = TEMP_FAILURE_RETRY(accept(fd, &clientaddr, &addrlen));
socket = TEMP_FAILURE_RETRY(
accept4(fd, &clientaddr, &addrlen, SOCK_NONBLOCK | SOCK_CLOEXEC));
if (socket == -1) {
if (IsTemporaryAcceptError(errno)) {
// We need to signal to the caller that this is actually not an
@@ -261,15 +262,6 @@ intptr_t ServerSocket::Accept(intptr_t fd) {
ASSERT(kTemporaryFailure != -1);
socket = kTemporaryFailure;
}
} else {
if (!FDUtils::SetCloseOnExec(socket)) {
FDUtils::SaveErrorAndClose(socket);
return -1;
}
if (!FDUtils::SetNonBlocking(socket)) {
FDUtils::SaveErrorAndClose(socket);
return -1;
}
}
return socket;
}