From e5318d51e659214d8e4a6bbfb48dfe66c8af57c6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 21 Apr 2021 20:05:00 +0200 Subject: LibCore: Remove the barely-used Core::safe_syscall() This was a helper that would call a syscall repeatedly until it either succeeded or failed with a non-EINTR error. It was only used in two places, so I don't think we need this helper. --- Userland/Libraries/LibCore/EventLoop.cpp | 3 -- Userland/Libraries/LibCore/IODevice.cpp | 18 +++++----- Userland/Libraries/LibCore/SyscallUtils.h | 57 ------------------------------- Userland/Libraries/LibIPC/Connection.h | 18 ++++++---- 4 files changed, 22 insertions(+), 74 deletions(-) delete mode 100644 Userland/Libraries/LibCore/SyscallUtils.h diff --git a/Userland/Libraries/LibCore/EventLoop.cpp b/Userland/Libraries/LibCore/EventLoop.cpp index db32272d3f..897bd76588 100644 --- a/Userland/Libraries/LibCore/EventLoop.cpp +++ b/Userland/Libraries/LibCore/EventLoop.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -658,8 +657,6 @@ try_select_again: goto try_select_again; } dbgln_if(EVENTLOOP_DEBUG, "Core::EventLoop::wait_for_event: {} ({}: {})", marked_fd_count, saved_errno, strerror(saved_errno)); - - // Blow up, similar to Core::safe_syscall. VERIFY_NOT_REACHED(); } if (FD_ISSET(s_wake_pipe_fds[0], &rfds)) { diff --git a/Userland/Libraries/LibCore/IODevice.cpp b/Userland/Libraries/LibCore/IODevice.cpp index e3df3a743e..847349012c 100644 --- a/Userland/Libraries/LibCore/IODevice.cpp +++ b/Userland/Libraries/LibCore/IODevice.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -106,17 +105,21 @@ ByteBuffer IODevice::read(size_t max_size) bool IODevice::can_read_from_fd() const { // FIXME: Can we somehow remove this once Core::Socket is implemented using non-blocking sockets? - fd_set rfds; + fd_set rfds {}; FD_ZERO(&rfds); FD_SET(m_fd, &rfds); struct timeval timeout { 0, 0 }; - int rc = Core::safe_syscall(select, m_fd + 1, &rfds, nullptr, nullptr, &timeout); - if (rc < 0) { - // NOTE: We don't set m_error here. - perror("IODevice::can_read: select"); - return false; + + for (;;) { + if (select(m_fd + 1, &rfds, nullptr, nullptr, &timeout) < 0) { + if (errno == EINTR) + continue; + perror("IODevice::can_read_from_fd: select"); + return false; + } + break; } return FD_ISSET(m_fd, &rfds); } @@ -332,5 +335,4 @@ LineIterator& LineIterator::operator++() m_buffer = m_device->read_line(); return *this; } - } diff --git a/Userland/Libraries/LibCore/SyscallUtils.h b/Userland/Libraries/LibCore/SyscallUtils.h deleted file mode 100644 index 07ca9f0aa4..0000000000 --- a/Userland/Libraries/LibCore/SyscallUtils.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace Core { - -template -inline int safe_syscall(Syscall syscall, Args&&... args) -{ - for (;;) { - int sysret = syscall(forward(args)...); - if (sysret == -1) { - if constexpr (SAFE_SYSCALL_DEBUG) { - int saved_errno = errno; - dbgln_if(SAFE_SYSCALL_DEBUG, "Core::safe_syscall: {} ({}: {})", sysret, saved_errno, strerror(saved_errno)); - } - - if (errno == EINTR) - continue; - VERIFY_NOT_REACHED(); - } - return sysret; - } -} - -} diff --git a/Userland/Libraries/LibIPC/Connection.h b/Userland/Libraries/LibIPC/Connection.h index fe0b19f1f7..69f9ef705c 100644 --- a/Userland/Libraries/LibIPC/Connection.h +++ b/Userland/Libraries/LibIPC/Connection.h @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -167,12 +166,19 @@ protected: fd_set rfds; FD_ZERO(&rfds); FD_SET(m_socket->fd(), &rfds); - int rc = Core::safe_syscall(select, m_socket->fd() + 1, &rfds, nullptr, nullptr, nullptr); - if (rc < 0) { - perror("select"); + for (;;) { + if (auto rc = select(m_socket->fd() + 1, &rfds, nullptr, nullptr, nullptr); rc < 0) { + if (errno == EINTR) + continue; + perror("wait_for_specific_endpoint_message: select"); + VERIFY_NOT_REACHED(); + } else { + VERIFY(rc > 0); + VERIFY(FD_ISSET(m_socket->fd(), &rfds)); + break; + } } - VERIFY(rc > 0); - VERIFY(FD_ISSET(m_socket->fd(), &rfds)); + if (!drain_messages_from_peer()) break; } -- cgit v1.2.3