forked from OSchip/llvm-project
[lldb] Add missing EINTR handling
Differential Revision: https://reviews.llvm.org/D59606 llvm-svn: 356703
This commit is contained in:
parent
c56872589f
commit
2819136f0a
|
@ -147,7 +147,7 @@ bool PseudoTerminal::OpenSlave(int oflag, char *error_str, size_t error_len) {
|
||||||
if (slave_name == nullptr)
|
if (slave_name == nullptr)
|
||||||
return false;
|
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 (m_slave_fd < 0) {
|
||||||
if (error_str)
|
if (error_str)
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "lldb/Utility/RegularExpression.h"
|
#include "lldb/Utility/RegularExpression.h"
|
||||||
|
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
|
#include "llvm/Support/Errno.h"
|
||||||
|
|
||||||
#ifndef LLDB_DISABLE_POSIX
|
#ifndef LLDB_DISABLE_POSIX
|
||||||
#include "lldb/Host/posix/DomainSocket.h"
|
#include "lldb/Host/posix/DomainSocket.h"
|
||||||
|
@ -450,9 +451,11 @@ NativeSocket Socket::AcceptSocket(NativeSocket sockfd, struct sockaddr *addr,
|
||||||
if (!child_processes_inherit) {
|
if (!child_processes_inherit) {
|
||||||
flags |= SOCK_CLOEXEC;
|
flags |= SOCK_CLOEXEC;
|
||||||
}
|
}
|
||||||
NativeSocket fd = ::accept4(sockfd, addr, addrlen, flags);
|
NativeSocket fd = llvm::sys::RetryAfterSignal(-1, ::accept4,
|
||||||
|
sockfd, addr, addrlen, flags);
|
||||||
#else
|
#else
|
||||||
NativeSocket fd = ::accept(sockfd, addr, addrlen);
|
NativeSocket fd = llvm::sys::RetryAfterSignal(-1, ::accept,
|
||||||
|
sockfd, addr, addrlen);
|
||||||
#endif
|
#endif
|
||||||
if (fd == kInvalidSocketValue)
|
if (fd == kInvalidSocketValue)
|
||||||
SetLastError(error);
|
SetLastError(error);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "lldb/Utility/Log.h"
|
#include "lldb/Utility/Log.h"
|
||||||
|
|
||||||
#include "llvm/Config/llvm-config.h"
|
#include "llvm/Config/llvm-config.h"
|
||||||
|
#include "llvm/Support/Errno.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
|
||||||
#ifndef LLDB_DISABLE_POSIX
|
#ifndef LLDB_DISABLE_POSIX
|
||||||
|
@ -150,8 +151,8 @@ Status TCPSocket::Connect(llvm::StringRef name) {
|
||||||
|
|
||||||
address.SetPort(port);
|
address.SetPort(port);
|
||||||
|
|
||||||
if (-1 == ::connect(GetNativeSocket(), &address.sockaddr(),
|
if (-1 == llvm::sys::RetryAfterSignal(-1, ::connect,
|
||||||
address.GetLength())) {
|
GetNativeSocket(), &address.sockaddr(), address.GetLength())) {
|
||||||
CLOSE_SOCKET(GetNativeSocket());
|
CLOSE_SOCKET(GetNativeSocket());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,7 +262,7 @@ ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path,
|
||||||
options.c_cc[VMIN] = 1;
|
options.c_cc[VMIN] = 1;
|
||||||
options.c_cc[VTIME] = 0;
|
options.c_cc[VTIME] = 0;
|
||||||
|
|
||||||
::tcsetattr(fd, TCSANOW, &options);
|
llvm::sys::RetryAfterSignal(-1, ::tcsetattr, fd, TCSANOW, &options);
|
||||||
}
|
}
|
||||||
|
|
||||||
int flags = ::fcntl(fd, F_GETFL, 0);
|
int flags = ::fcntl(fd, F_GETFL, 0);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "lldb/Host/posix/DomainSocket.h"
|
#include "lldb/Host/posix/DomainSocket.h"
|
||||||
|
|
||||||
|
#include "llvm/Support/Errno.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
|
|
||||||
#include <stddef.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);
|
m_socket = CreateSocket(kDomain, kType, 0, m_child_processes_inherit, error);
|
||||||
if (error.Fail())
|
if (error.Fail())
|
||||||
return error;
|
return error;
|
||||||
if (::connect(GetNativeSocket(), (struct sockaddr *)&saddr_un, saddr_un_len) <
|
if (llvm::sys::RetryAfterSignal(-1, ::connect, GetNativeSocket(),
|
||||||
0)
|
(struct sockaddr *)&saddr_un, saddr_un_len) < 0)
|
||||||
SetLastError(error);
|
SetLastError(error);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "lldb/Utility/Status.h"
|
#include "lldb/Utility/Status.h"
|
||||||
#include "lldb/Utility/StreamString.h"
|
#include "lldb/Utility/StreamString.h"
|
||||||
|
|
||||||
|
#include "llvm/Support/Errno.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
|
|
||||||
using namespace lldb;
|
using namespace lldb;
|
||||||
|
@ -71,9 +72,9 @@ Status FileSystem::ResolveSymbolicLink(const FileSpec &src, FileSpec &dst) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *FileSystem::Fopen(const char *path, const char *mode) {
|
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) {
|
int FileSystem::Open(const char *path, int flags, int mode) {
|
||||||
return ::open(path, flags, mode);
|
return llvm::sys::RetryAfterSignal(-1, ::open, path, flags, mode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
#include "lldb/Host/posix/LockFilePosix.h"
|
#include "lldb/Host/posix/LockFilePosix.h"
|
||||||
|
|
||||||
|
#include "llvm/Support/Errno.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.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();
|
fl.l_pid = ::getpid();
|
||||||
|
|
||||||
Status error;
|
Status error;
|
||||||
if (::fcntl(fd, cmd, &fl) == -1)
|
if (llvm::sys::RetryAfterSignal(-1, ::fcntl, fd, cmd, &fl) == -1)
|
||||||
error.SetErrorToErrno();
|
error.SetErrorToErrno();
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "lldb/Host/HostInfo.h"
|
#include "lldb/Host/HostInfo.h"
|
||||||
#include "lldb/Utility/SelectHelper.h"
|
#include "lldb/Utility/SelectHelper.h"
|
||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
|
#include "llvm/Support/Errno.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
|
|
||||||
#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8))
|
#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8))
|
||||||
|
@ -157,7 +158,7 @@ Status PipePosix::OpenAsReader(llvm::StringRef name,
|
||||||
flags |= O_CLOEXEC;
|
flags |= O_CLOEXEC;
|
||||||
|
|
||||||
Status error;
|
Status error;
|
||||||
int fd = ::open(name.data(), flags);
|
int fd = llvm::sys::RetryAfterSignal(-1, ::open, name.data(), flags);
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
m_fds[READ] = fd;
|
m_fds[READ] = fd;
|
||||||
else
|
else
|
||||||
|
@ -192,7 +193,7 @@ PipePosix::OpenAsWriterWithTimeout(llvm::StringRef name,
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
const auto errno_copy = errno;
|
const auto errno_copy = errno;
|
||||||
// We may get ENXIO if a reader side of the pipe hasn't opened yet.
|
// 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);
|
return Status(errno_copy, eErrorTypePOSIX);
|
||||||
|
|
||||||
std::this_thread::sleep_for(
|
std::this_thread::sleep_for(
|
||||||
|
@ -275,6 +276,8 @@ Status PipePosix::ReadWithTimeout(void *buf, size_t size,
|
||||||
bytes_read += result;
|
bytes_read += result;
|
||||||
if (bytes_read == size || result == 0)
|
if (bytes_read == size || result == 0)
|
||||||
break;
|
break;
|
||||||
|
} else if (errno == EINTR) {
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
error.SetErrorToErrno();
|
error.SetErrorToErrno();
|
||||||
break;
|
break;
|
||||||
|
@ -305,6 +308,8 @@ Status PipePosix::Write(const void *buf, size_t size, size_t &bytes_written) {
|
||||||
bytes_written += result;
|
bytes_written += result;
|
||||||
if (bytes_written == size)
|
if (bytes_written == size)
|
||||||
break;
|
break;
|
||||||
|
} else if (errno == EINTR) {
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
error.SetErrorToErrno();
|
error.SetErrorToErrno();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
static void DupDescriptor(int error_fd, const FileSpec &file_spec, int fd,
|
||||||
int flags) {
|
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)
|
if (target_fd == -1)
|
||||||
ExitWithError(error_fd, "DupDescriptor-open");
|
ExitWithError(error_fd, "DupDescriptor-open");
|
||||||
|
@ -211,7 +212,7 @@ ProcessLauncherPosixFork::LaunchProcess(const ProcessLaunchInfo &launch_info,
|
||||||
|
|
||||||
error.SetErrorString(buf);
|
error.SetErrorString(buf);
|
||||||
|
|
||||||
waitpid(pid, nullptr, 0);
|
llvm::sys::RetryAfterSignal(-1, waitpid, pid, nullptr, 0);
|
||||||
|
|
||||||
return HostProcess();
|
return HostProcess();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1387,7 +1387,8 @@ lldb_private::Status ProcessMonitor::Detach(lldb::tid_t tid) {
|
||||||
|
|
||||||
bool ProcessMonitor::DupDescriptor(const FileSpec &file_spec, int fd,
|
bool ProcessMonitor::DupDescriptor(const FileSpec &file_spec, int fd,
|
||||||
int flags) {
|
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)
|
if (target_fd == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -51,8 +51,10 @@ struct ChildDeleter {
|
||||||
|
|
||||||
~ChildDeleter() {
|
~ChildDeleter() {
|
||||||
int status;
|
int status;
|
||||||
kill(pid, SIGKILL); // Kill the child.
|
// Kill the child.
|
||||||
waitpid(pid, &status, __WALL); // Pick up the remains.
|
kill(pid, SIGKILL);
|
||||||
|
// Pick up the remains.
|
||||||
|
llvm::sys::RetryAfterSignal(-1, waitpid, pid, &status, __WALL);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -81,7 +83,8 @@ bool WorkaroundNeeded() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int status;
|
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)) {
|
if (wpid != child_pid || !WIFSTOPPED(status)) {
|
||||||
LLDB_LOG(log, "waitpid() failed (status = {0:x}): {1}", status,
|
LLDB_LOG(log, "waitpid() failed (status = {0:x}): {1}", status,
|
||||||
Status(errno, eErrorTypePOSIX));
|
Status(errno, eErrorTypePOSIX));
|
||||||
|
@ -110,7 +113,8 @@ bool WorkaroundNeeded() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
wpid = waitpid(child_pid, &status, __WALL);
|
wpid = llvm::sys::RetryAfterSignal(-1, waitpid,
|
||||||
|
child_pid, &status, __WALL);
|
||||||
if (wpid != child_pid || !WIFSTOPPED(status)) {
|
if (wpid != child_pid || !WIFSTOPPED(status)) {
|
||||||
LLDB_LOG(log, "waitpid() failed (status = {0:x}): {1}", status,
|
LLDB_LOG(log, "waitpid() failed (status = {0:x}): {1}", status,
|
||||||
Status(errno, eErrorTypePOSIX));
|
Status(errno, eErrorTypePOSIX));
|
||||||
|
|
|
@ -665,7 +665,8 @@ Status NativeProcessNetBSD::Attach() {
|
||||||
int wstatus;
|
int wstatus;
|
||||||
// Need to use WALLSIG otherwise we receive an error with errno=ECHLD At this
|
// Need to use WALLSIG otherwise we receive an error with errno=ECHLD At this
|
||||||
// point we should have a thread stopped if waitpid succeeds.
|
// 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);
|
return Status(errno, eErrorTypePOSIX);
|
||||||
|
|
||||||
/* Initialize threads */
|
/* Initialize threads */
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "lldb/Utility/Stream.h"
|
#include "lldb/Utility/Stream.h"
|
||||||
|
|
||||||
#include "llvm/Support/ConvertUTF.h"
|
#include "llvm/Support/ConvertUTF.h"
|
||||||
|
#include "llvm/Support/Errno.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ void StructuredPythonObject::Dump(Stream &s, bool pretty_print) const {
|
||||||
|
|
||||||
void PythonObject::Dump(Stream &strm) const {
|
void PythonObject::Dump(Stream &strm) const {
|
||||||
if (m_py_obj) {
|
if (m_py_obj) {
|
||||||
FILE *file = ::tmpfile();
|
FILE *file = llvm::sys::RetryAfterSignal(nullptr, ::tmpfile);
|
||||||
if (file) {
|
if (file) {
|
||||||
::PyObject_Print(m_py_obj, file, 0);
|
::PyObject_Print(m_py_obj, file, 0);
|
||||||
const long length = ftell(file);
|
const long length = ftell(file);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "lldb/Host/FileSystem.h"
|
#include "lldb/Host/FileSystem.h"
|
||||||
|
|
||||||
#include "llvm/Support/ConvertUTF.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)
|
#if !defined(_MSC_VER)
|
||||||
// Open with 'write' and 'binary' mode
|
// 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
|
#else
|
||||||
// Open a file with exclusive write and shared read permissions
|
// Open a file with exclusive write and shared read permissions
|
||||||
std::wstring path;
|
std::wstring path;
|
||||||
|
@ -226,7 +228,8 @@ bool CMIUtilFileStd::IsFileExist(const CMIUtilString &vFileNamePath) const {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
FILE *pTmp = nullptr;
|
FILE *pTmp = nullptr;
|
||||||
pTmp = ::fopen(vFileNamePath.c_str(), "wb");
|
pTmp = llvm::sys::RetryAfterSignal(nullptr, ::fopen,
|
||||||
|
vFileNamePath.c_str(), "wb");
|
||||||
if (pTmp != nullptr) {
|
if (pTmp != nullptr) {
|
||||||
::fclose(pTmp);
|
::fclose(pTmp);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
#include "llvm/ADT/ArrayRef.h"
|
||||||
|
#include "llvm/Support/Errno.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
|
||||||
|
@ -90,7 +91,8 @@ SOCKET AcceptConnection(int portno) {
|
||||||
} else {
|
} else {
|
||||||
listen(sockfd, 5);
|
listen(sockfd, 5);
|
||||||
socklen_t clilen = sizeof(cli_addr);
|
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 (newsockfd < 0)
|
||||||
if (g_vsc.log)
|
if (g_vsc.log)
|
||||||
*g_vsc.log << "error: accept (" << strerror(errno) << ")"
|
*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
|
// 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"
|
// executable when attaching to a process by process ID in a "attach"
|
||||||
// request.
|
// request.
|
||||||
FILE *out = fopen(dev_null_path, "w");
|
FILE *out = llvm::sys::RetryAfterSignal(nullptr, fopen, dev_null_path, "w");
|
||||||
if (out) {
|
if (out) {
|
||||||
// Set the output and error file handles to redirect into nothing otherwise
|
// 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
|
// if any code in LLDB prints to the debugger file handles, the output and
|
||||||
|
|
Loading…
Reference in New Issue