[lldb] Add missing EINTR handling

Differential Revision: https://reviews.llvm.org/D59606

llvm-svn: 356703
This commit is contained in:
Michal Gorny 2019-03-21 19:35:55 +00:00
parent c56872589f
commit 2819136f0a
15 changed files with 52 additions and 26 deletions

View File

@ -147,7 +147,7 @@ bool PseudoTerminal::OpenSlave(int oflag, char *error_str, size_t error_len) {
if (slave_name == nullptr)
return false;
m_slave_fd = ::open(slave_name, oflag);
m_slave_fd = llvm::sys::RetryAfterSignal(-1, ::open, slave_name, oflag);
if (m_slave_fd < 0) {
if (error_str)

View File

@ -18,6 +18,7 @@
#include "lldb/Utility/RegularExpression.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Errno.h"
#ifndef LLDB_DISABLE_POSIX
#include "lldb/Host/posix/DomainSocket.h"
@ -450,9 +451,11 @@ NativeSocket Socket::AcceptSocket(NativeSocket sockfd, struct sockaddr *addr,
if (!child_processes_inherit) {
flags |= SOCK_CLOEXEC;
}
NativeSocket fd = ::accept4(sockfd, addr, addrlen, flags);
NativeSocket fd = llvm::sys::RetryAfterSignal(-1, ::accept4,
sockfd, addr, addrlen, flags);
#else
NativeSocket fd = ::accept(sockfd, addr, addrlen);
NativeSocket fd = llvm::sys::RetryAfterSignal(-1, ::accept,
sockfd, addr, addrlen);
#endif
if (fd == kInvalidSocketValue)
SetLastError(error);

View File

@ -17,6 +17,7 @@
#include "lldb/Utility/Log.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/raw_ostream.h"
#ifndef LLDB_DISABLE_POSIX
@ -150,8 +151,8 @@ Status TCPSocket::Connect(llvm::StringRef name) {
address.SetPort(port);
if (-1 == ::connect(GetNativeSocket(), &address.sockaddr(),
address.GetLength())) {
if (-1 == llvm::sys::RetryAfterSignal(-1, ::connect,
GetNativeSocket(), &address.sockaddr(), address.GetLength())) {
CLOSE_SOCKET(GetNativeSocket());
continue;
}

View File

@ -262,7 +262,7 @@ ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path,
options.c_cc[VMIN] = 1;
options.c_cc[VTIME] = 0;
::tcsetattr(fd, TCSANOW, &options);
llvm::sys::RetryAfterSignal(-1, ::tcsetattr, fd, TCSANOW, &options);
}
int flags = ::fcntl(fd, F_GETFL, 0);

View File

@ -8,6 +8,7 @@
#include "lldb/Host/posix/DomainSocket.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/FileSystem.h"
#include <stddef.h>
@ -81,8 +82,8 @@ Status DomainSocket::Connect(llvm::StringRef name) {
m_socket = CreateSocket(kDomain, kType, 0, m_child_processes_inherit, error);
if (error.Fail())
return error;
if (::connect(GetNativeSocket(), (struct sockaddr *)&saddr_un, saddr_un_len) <
0)
if (llvm::sys::RetryAfterSignal(-1, ::connect, GetNativeSocket(),
(struct sockaddr *)&saddr_un, saddr_un_len) < 0)
SetLastError(error);
return error;

View File

@ -25,6 +25,7 @@
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/FileSystem.h"
using namespace lldb;
@ -71,9 +72,9 @@ Status FileSystem::ResolveSymbolicLink(const FileSpec &src, FileSpec &dst) {
}
FILE *FileSystem::Fopen(const char *path, const char *mode) {
return ::fopen(path, mode);
return llvm::sys::RetryAfterSignal(nullptr, ::fopen, path, mode);
}
int FileSystem::Open(const char *path, int flags, int mode) {
return ::open(path, flags, mode);
return llvm::sys::RetryAfterSignal(-1, ::open, path, flags, mode);
}

View File

@ -8,6 +8,8 @@
#include "lldb/Host/posix/LockFilePosix.h"
#include "llvm/Support/Errno.h"
#include <fcntl.h>
#include <unistd.h>
@ -27,7 +29,7 @@ Status fileLock(int fd, int cmd, int lock_type, const uint64_t start,
fl.l_pid = ::getpid();
Status error;
if (::fcntl(fd, cmd, &fl) == -1)
if (llvm::sys::RetryAfterSignal(-1, ::fcntl, fd, cmd, &fl) == -1)
error.SetErrorToErrno();
return error;

View File

@ -10,6 +10,7 @@
#include "lldb/Host/HostInfo.h"
#include "lldb/Utility/SelectHelper.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/FileSystem.h"
#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8))
@ -157,7 +158,7 @@ Status PipePosix::OpenAsReader(llvm::StringRef name,
flags |= O_CLOEXEC;
Status error;
int fd = ::open(name.data(), flags);
int fd = llvm::sys::RetryAfterSignal(-1, ::open, name.data(), flags);
if (fd != -1)
m_fds[READ] = fd;
else
@ -192,7 +193,7 @@ PipePosix::OpenAsWriterWithTimeout(llvm::StringRef name,
if (fd == -1) {
const auto errno_copy = errno;
// We may get ENXIO if a reader side of the pipe hasn't opened yet.
if (errno_copy != ENXIO)
if (errno_copy != ENXIO && errno_copy != EINTR)
return Status(errno_copy, eErrorTypePOSIX);
std::this_thread::sleep_for(
@ -275,6 +276,8 @@ Status PipePosix::ReadWithTimeout(void *buf, size_t size,
bytes_read += result;
if (bytes_read == size || result == 0)
break;
} else if (errno == EINTR) {
continue;
} else {
error.SetErrorToErrno();
break;
@ -305,6 +308,8 @@ Status PipePosix::Write(const void *buf, size_t size, size_t &bytes_written) {
bytes_written += result;
if (bytes_written == size)
break;
} else if (errno == EINTR) {
continue;
} else {
error.SetErrorToErrno();
}

View File

@ -72,7 +72,8 @@ static void DisableASLRIfRequested(int error_fd, const ProcessLaunchInfo &info)
static void DupDescriptor(int error_fd, const FileSpec &file_spec, int fd,
int flags) {
int target_fd = ::open(file_spec.GetCString(), flags, 0666);
int target_fd = llvm::sys::RetryAfterSignal(-1, ::open,
file_spec.GetCString(), flags, 0666);
if (target_fd == -1)
ExitWithError(error_fd, "DupDescriptor-open");
@ -211,7 +212,7 @@ ProcessLauncherPosixFork::LaunchProcess(const ProcessLaunchInfo &launch_info,
error.SetErrorString(buf);
waitpid(pid, nullptr, 0);
llvm::sys::RetryAfterSignal(-1, waitpid, pid, nullptr, 0);
return HostProcess();
}

View File

@ -1387,7 +1387,8 @@ lldb_private::Status ProcessMonitor::Detach(lldb::tid_t tid) {
bool ProcessMonitor::DupDescriptor(const FileSpec &file_spec, int fd,
int flags) {
int target_fd = open(file_spec.GetCString(), flags, 0666);
int target_fd = llvm::sys::RetryAfterSignal(-1, open,
file_spec.GetCString(), flags, 0666);
if (target_fd == -1)
return false;

View File

@ -51,8 +51,10 @@ struct ChildDeleter {
~ChildDeleter() {
int status;
kill(pid, SIGKILL); // Kill the child.
waitpid(pid, &status, __WALL); // Pick up the remains.
// Kill the child.
kill(pid, SIGKILL);
// Pick up the remains.
llvm::sys::RetryAfterSignal(-1, waitpid, pid, &status, __WALL);
}
};
@ -81,7 +83,8 @@ bool WorkaroundNeeded() {
}
int status;
::pid_t wpid = waitpid(child_pid, &status, __WALL);
::pid_t wpid = llvm::sys::RetryAfterSignal(-1, waitpid,
child_pid, &status, __WALL);
if (wpid != child_pid || !WIFSTOPPED(status)) {
LLDB_LOG(log, "waitpid() failed (status = {0:x}): {1}", status,
Status(errno, eErrorTypePOSIX));
@ -110,7 +113,8 @@ bool WorkaroundNeeded() {
break;
}
wpid = waitpid(child_pid, &status, __WALL);
wpid = llvm::sys::RetryAfterSignal(-1, waitpid,
child_pid, &status, __WALL);
if (wpid != child_pid || !WIFSTOPPED(status)) {
LLDB_LOG(log, "waitpid() failed (status = {0:x}): {1}", status,
Status(errno, eErrorTypePOSIX));

View File

@ -665,7 +665,8 @@ Status NativeProcessNetBSD::Attach() {
int wstatus;
// Need to use WALLSIG otherwise we receive an error with errno=ECHLD At this
// point we should have a thread stopped if waitpid succeeds.
if ((wstatus = waitpid(m_pid, NULL, WALLSIG)) < 0)
if ((wstatus = llvm::sys::RetryAfterSignal(-1, waitpid,
m_pid, NULL, WALLSIG)) < 0)
return Status(errno, eErrorTypePOSIX);
/* Initialize threads */

View File

@ -21,6 +21,7 @@
#include "lldb/Utility/Stream.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/Errno.h"
#include <stdio.h>
@ -39,7 +40,7 @@ void StructuredPythonObject::Dump(Stream &s, bool pretty_print) const {
void PythonObject::Dump(Stream &strm) const {
if (m_py_obj) {
FILE *file = ::tmpfile();
FILE *file = llvm::sys::RetryAfterSignal(nullptr, ::tmpfile);
if (file) {
::PyObject_Print(m_py_obj, file, 0);
const long length = ftell(file);

View File

@ -18,6 +18,7 @@
#include "lldb/Host/FileSystem.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/Errno.h"
//++
//------------------------------------------------------------------------------------
@ -83,7 +84,8 @@ bool CMIUtilFileStd::CreateWrite(const CMIUtilString &vFileNamePath,
#if !defined(_MSC_VER)
// Open with 'write' and 'binary' mode
m_pFileHandle = ::fopen(vFileNamePath.c_str(), "wb");
m_pFileHandle = llvm::sys::RetryAfterSignal(nullptr, ::fopen,
vFileNamePath.c_str(), "wb");
#else
// Open a file with exclusive write and shared read permissions
std::wstring path;
@ -226,7 +228,8 @@ bool CMIUtilFileStd::IsFileExist(const CMIUtilString &vFileNamePath) const {
return false;
FILE *pTmp = nullptr;
pTmp = ::fopen(vFileNamePath.c_str(), "wb");
pTmp = llvm::sys::RetryAfterSignal(nullptr, ::fopen,
vFileNamePath.c_str(), "wb");
if (pTmp != nullptr) {
::fclose(pTmp);
return true;

View File

@ -41,6 +41,7 @@
#include <thread>
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"
@ -90,7 +91,8 @@ SOCKET AcceptConnection(int portno) {
} else {
listen(sockfd, 5);
socklen_t clilen = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
newsockfd = llvm::sys::RetryAfterSignal(-1, accept,
sockfd, (struct sockaddr *)&cli_addr, &clilen);
if (newsockfd < 0)
if (g_vsc.log)
*g_vsc.log << "error: accept (" << strerror(errno) << ")"
@ -1074,7 +1076,7 @@ void request_initialize(const llvm::json::Object &request) {
// before we are given an executable to launch in a "launch" request, or a
// executable when attaching to a process by process ID in a "attach"
// request.
FILE *out = fopen(dev_null_path, "w");
FILE *out = llvm::sys::RetryAfterSignal(nullptr, fopen, dev_null_path, "w");
if (out) {
// Set the output and error file handles to redirect into nothing otherwise
// if any code in LLDB prints to the debugger file handles, the output and