summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-04-21 20:05:00 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-21 23:49:01 +0200
commite5318d51e659214d8e4a6bbfb48dfe66c8af57c6 (patch)
tree446c8c90128c12eced1c6af1d96913d5f6280009
parentc41c41cc0f980bee54fd3b60045c02210d5ce399 (diff)
downloadserenity-e5318d51e659214d8e4a6bbfb48dfe66c8af57c6.zip
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.
-rw-r--r--Userland/Libraries/LibCore/EventLoop.cpp3
-rw-r--r--Userland/Libraries/LibCore/IODevice.cpp18
-rw-r--r--Userland/Libraries/LibCore/SyscallUtils.h57
-rw-r--r--Userland/Libraries/LibIPC/Connection.h18
4 files changed, 22 insertions, 74 deletions
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 <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)) {
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 <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;
}
-
}
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 <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;
- }
-}
-
-}
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 <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;
}