Author: mgorny Date: Thu Mar 21 12:35:55 2019 New Revision: 356703 URL: http://llvm.org/viewvc/llvm-project?rev=356703&view=rev Log: [lldb] Add missing EINTR handling
Differential Revision: https://reviews.llvm.org/D59606 Modified: lldb/trunk/source/Host/common/PseudoTerminal.cpp lldb/trunk/source/Host/common/Socket.cpp lldb/trunk/source/Host/common/TCPSocket.cpp lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp lldb/trunk/source/Host/posix/DomainSocket.cpp lldb/trunk/source/Host/posix/FileSystem.cpp lldb/trunk/source/Host/posix/LockFilePosix.cpp lldb/trunk/source/Host/posix/PipePosix.cpp lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp lldb/trunk/source/Plugins/Process/Linux/SingleStepCheck.cpp lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp lldb/trunk/tools/lldb-mi/MIUtilFileStd.cpp lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp Modified: lldb/trunk/source/Host/common/PseudoTerminal.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/PseudoTerminal.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Host/common/PseudoTerminal.cpp (original) +++ lldb/trunk/source/Host/common/PseudoTerminal.cpp Thu Mar 21 12:35:55 2019 @@ -147,7 +147,7 @@ bool PseudoTerminal::OpenSlave(int oflag 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) Modified: lldb/trunk/source/Host/common/Socket.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Socket.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Host/common/Socket.cpp (original) +++ lldb/trunk/source/Host/common/Socket.cpp Thu Mar 21 12:35:55 2019 @@ -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(Native 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); Modified: lldb/trunk/source/Host/common/TCPSocket.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/TCPSocket.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Host/common/TCPSocket.cpp (original) +++ lldb/trunk/source/Host/common/TCPSocket.cpp Thu Mar 21 12:35:55 2019 @@ -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::StringRe 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; } Modified: lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp (original) +++ lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp Thu Mar 21 12:35:55 2019 @@ -262,7 +262,7 @@ ConnectionStatus ConnectionFileDescripto 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); Modified: lldb/trunk/source/Host/posix/DomainSocket.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/DomainSocket.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Host/posix/DomainSocket.cpp (original) +++ lldb/trunk/source/Host/posix/DomainSocket.cpp Thu Mar 21 12:35:55 2019 @@ -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::Strin 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; Modified: lldb/trunk/source/Host/posix/FileSystem.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/FileSystem.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Host/posix/FileSystem.cpp (original) +++ lldb/trunk/source/Host/posix/FileSystem.cpp Thu Mar 21 12:35:55 2019 @@ -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(c } 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); } Modified: lldb/trunk/source/Host/posix/LockFilePosix.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/LockFilePosix.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Host/posix/LockFilePosix.cpp (original) +++ lldb/trunk/source/Host/posix/LockFilePosix.cpp Thu Mar 21 12:35:55 2019 @@ -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 loc 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; Modified: lldb/trunk/source/Host/posix/PipePosix.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/PipePosix.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Host/posix/PipePosix.cpp (original) +++ lldb/trunk/source/Host/posix/PipePosix.cpp Thu Mar 21 12:35:55 2019 @@ -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::Str 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: 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 * 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, bytes_written += result; if (bytes_written == size) break; + } else if (errno == EINTR) { + continue; } else { error.SetErrorToErrno(); } Modified: lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp (original) +++ lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp Thu Mar 21 12:35:55 2019 @@ -72,7 +72,8 @@ static void DisableASLRIfRequested(int e 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( error.SetErrorString(buf); - waitpid(pid, nullptr, 0); + llvm::sys::RetryAfterSignal(-1, waitpid, pid, nullptr, 0); return HostProcess(); } Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp (original) +++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp Thu Mar 21 12:35:55 2019 @@ -1387,7 +1387,8 @@ lldb_private::Status ProcessMonitor::Det 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; Modified: lldb/trunk/source/Plugins/Process/Linux/SingleStepCheck.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/SingleStepCheck.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/SingleStepCheck.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/SingleStepCheck.cpp Thu Mar 21 12:35:55 2019 @@ -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)); Modified: lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp (original) +++ lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp Thu Mar 21 12:35:55 2019 @@ -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 */ Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp (original) +++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp Thu Mar 21 12:35:55 2019 @@ -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 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); Modified: lldb/trunk/tools/lldb-mi/MIUtilFileStd.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIUtilFileStd.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/tools/lldb-mi/MIUtilFileStd.cpp (original) +++ lldb/trunk/tools/lldb-mi/MIUtilFileStd.cpp Thu Mar 21 12:35:55 2019 @@ -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 C #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 C 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; Modified: lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp?rev=356703&r1=356702&r2=356703&view=diff ============================================================================== --- lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp (original) +++ lldb/trunk/tools/lldb-vscode/lldb-vscode.cpp Thu Mar 21 12:35:55 2019 @@ -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 // 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 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits