diff --git a/runtime/bin/eventhandler_linux.cc b/runtime/bin/eventhandler_linux.cc index 11354e0ef59..dd3aaa247fe 100644 --- a/runtime/bin/eventhandler_linux.cc +++ b/runtime/bin/eventhandler_linux.cc @@ -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; diff --git a/runtime/bin/fdutils_linux.cc b/runtime/bin/fdutils_linux.cc index c13a07b1b36..84fe559d71b 100644 --- a/runtime/bin/fdutils_linux.cc +++ b/runtime/bin/fdutils_linux.cc @@ -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) { diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_linux.cc index addd7f3cc9c..b0e4aec307e 100644 --- a/runtime/bin/socket_linux.cc +++ b/runtime/bin/socket_linux.cc @@ -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; }