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.
This commit is contained in:
Andreas Kling 2021-04-21 20:05:00 +02:00
parent c41c41cc0f
commit e5318d51e6
Notes: sideshowbarker 2024-07-18 19:16:43 +09:00
4 changed files with 22 additions and 74 deletions

View file

@ -41,7 +41,6 @@
#include <LibCore/LocalSocket.h>
#include <LibCore/Notifier.h>
#include <LibCore/Object.h>
#include <LibCore/SyscallUtils.h>
#include <LibThread/Lock.h>
#include <errno.h>
#include <fcntl.h>
@ -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)) {

View file

@ -27,7 +27,6 @@
#include <AK/ByteBuffer.h>
#include <AK/PrintfImplementation.h>
#include <LibCore/IODevice.h>
#include <LibCore/SyscallUtils.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
@ -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;
}
}

View file

@ -1,57 +0,0 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* 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 <AK/Debug.h>
#include <AK/StdLibExtras.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
namespace Core {
template<typename Syscall, class... Args>
inline int safe_syscall(Syscall syscall, Args&&... args)
{
for (;;) {
int sysret = syscall(forward<Args>(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;
}
}
}

View file

@ -32,7 +32,6 @@
#include <LibCore/EventLoop.h>
#include <LibCore/LocalSocket.h>
#include <LibCore/Notifier.h>
#include <LibCore/SyscallUtils.h>
#include <LibCore/Timer.h>
#include <LibIPC/Message.h>
#include <stdint.h>
@ -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;
}