Index: lldb/source/Host/common/PseudoTerminal.cpp =================================================================== --- lldb/source/Host/common/PseudoTerminal.cpp +++ lldb/source/Host/common/PseudoTerminal.cpp @@ -147,7 +147,7 @@ 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) Index: lldb/source/Host/common/Socket.cpp =================================================================== --- lldb/source/Host/common/Socket.cpp +++ lldb/source/Host/common/Socket.cpp @@ -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 @@ 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); Index: lldb/source/Host/common/TCPSocket.cpp =================================================================== --- lldb/source/Host/common/TCPSocket.cpp +++ lldb/source/Host/common/TCPSocket.cpp @@ -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 @@ 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; } Index: lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp =================================================================== --- lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -252,8 +252,10 @@ ::tcgetattr(fd, &options); // Set port speed to maximum - ::cfsetospeed(&options, B115200); - ::cfsetispeed(&options, B115200); + llvm::sys::RetryAfterSignal(-1, ::cfsetospeed, + &options, B115200); + llvm::sys::RetryAfterSignal(-1, ::cfsetispeed, + &options, B115200); // Raw input, disable echo and signals options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); Index: lldb/source/Host/posix/DomainSocket.cpp =================================================================== --- lldb/source/Host/posix/DomainSocket.cpp +++ lldb/source/Host/posix/DomainSocket.cpp @@ -8,6 +8,7 @@ #include "lldb/Host/posix/DomainSocket.h" +#include "llvm/Support/Errno.h" #include "llvm/Support/FileSystem.h" #include @@ -81,8 +82,8 @@ 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; Index: lldb/source/Host/posix/FileSystem.cpp =================================================================== --- lldb/source/Host/posix/FileSystem.cpp +++ lldb/source/Host/posix/FileSystem.cpp @@ -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 @@ } 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); } Index: lldb/source/Host/posix/LockFilePosix.cpp =================================================================== --- lldb/source/Host/posix/LockFilePosix.cpp +++ lldb/source/Host/posix/LockFilePosix.cpp @@ -8,6 +8,8 @@ #include "lldb/Host/posix/LockFilePosix.h" +#include "llvm/Support/Errno.h" + #include #include @@ -27,7 +29,7 @@ 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; Index: lldb/source/Host/posix/PipePosix.cpp =================================================================== --- lldb/source/Host/posix/PipePosix.cpp +++ lldb/source/Host/posix/PipePosix.cpp @@ -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 @@ 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 @@ 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 @@ bytes_read += result; if (bytes_read == size || result == 0) break; + } else if (errno == EINTR) { + continue; } else { error.SetErrorToErrno(); break; @@ -305,6 +308,8 @@ bytes_written += result; if (bytes_written == size) break; + } else if (errno == EINTR) { + continue; } else { error.SetErrorToErrno(); } Index: lldb/source/Host/posix/ProcessLauncherPosixFork.cpp =================================================================== --- lldb/source/Host/posix/ProcessLauncherPosixFork.cpp +++ lldb/source/Host/posix/ProcessLauncherPosixFork.cpp @@ -72,7 +72,8 @@ 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 @@ error.SetErrorString(buf); - waitpid(pid, nullptr, 0); + llvm::sys::RetryAfterSignal(-1, waitpid, pid, nullptr, 0); return HostProcess(); } Index: lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp =================================================================== --- lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp +++ lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp @@ -1387,7 +1387,8 @@ 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; Index: lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp =================================================================== --- lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp +++ lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp @@ -51,8 +51,10 @@ ~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 @@ } 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 @@ 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)); Index: lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp =================================================================== --- lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp +++ lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp @@ -665,7 +665,8 @@ 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 */ Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -21,6 +21,7 @@ #include "lldb/Utility/Stream.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/Errno.h" #include @@ -39,7 +40,7 @@ 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); Index: lldb/tools/darwin-debug/darwin-debug.cpp =================================================================== --- lldb/tools/darwin-debug/darwin-debug.cpp +++ lldb/tools/darwin-debug/darwin-debug.cpp @@ -39,6 +39,8 @@ #include +#include "llvm/Support/Errno.h" + #ifndef _POSIX_SPAWN_DISABLE_ASLR #define _POSIX_SPAWN_DISABLE_ASLR 0x0100 #endif @@ -287,7 +289,8 @@ saddr_un.sun_path[sizeof(saddr_un.sun_path) - 1] = '\0'; saddr_un.sun_len = SUN_LEN(&saddr_un); - if (::connect(s, (struct sockaddr *)&saddr_un, SUN_LEN(&saddr_un)) < 0) { + if (llvm::sys::RetryAfterSignal(-1, ::connect, s, + (struct sockaddr *)&saddr_un, SUN_LEN(&saddr_un)) < 0) { perror("error: connect (socket, &saddr_un, saddr_un_len)"); exit(1); } Index: lldb/tools/debugserver/source/DNB.cpp =================================================================== --- lldb/tools/debugserver/source/DNB.cpp +++ lldb/tools/debugserver/source/DNB.cpp @@ -170,7 +170,8 @@ } else { int status; const pid_t pid = (pid_t)death_event.ident; - const pid_t child_pid = waitpid(pid, &status, 0); + const pid_t child_pid = llvm::sys::RetryAfterSignal(-1, waitpid, + pid, &status, 0); bool exited = false; int signal = 0; Index: lldb/tools/debugserver/source/PseudoTerminal.cpp =================================================================== --- lldb/tools/debugserver/source/PseudoTerminal.cpp +++ lldb/tools/debugserver/source/PseudoTerminal.cpp @@ -105,7 +105,7 @@ if (slave_name == NULL) return err_ptsname_failed; - m_slave_fd = ::open(slave_name, oflag); + m_slave_fd = llvm::sys::RetryAfterSignal(-1, ::open, slave_name, oflag); if (m_slave_fd < 0) return err_open_slave_failed; Index: lldb/tools/debugserver/source/RNBRemote.cpp =================================================================== --- lldb/tools/debugserver/source/RNBRemote.cpp +++ lldb/tools/debugserver/source/RNBRemote.cpp @@ -41,6 +41,8 @@ #include "RNBSocket.h" #include "StdStringExtractor.h" +#include "llvm/Support/Errno.h" + #include #include @@ -1830,7 +1832,8 @@ std::string op = get_operator(line); std::string value = get_value(line); if (variable == "logfile") { - FILE *log_file = fopen(value.c_str(), "w"); + FILE *log_file = llvm::sys::RetryAfterSignal(nullptr, fopen, + value.c_str(), "w"); if (log_file) { DNBLogSetLogCallback(FileLogCallback, log_file); return SendPacket("OK"); Index: lldb/tools/debugserver/source/RNBSocket.cpp =================================================================== --- lldb/tools/debugserver/source/RNBSocket.cpp +++ lldb/tools/debugserver/source/RNBSocket.cpp @@ -25,6 +25,7 @@ #include #include "lldb/Host/SocketAddress.h" +#include "llvm/Support/Errno.h" #ifdef WITH_LOCKDOWN #include "lockdown.h" @@ -156,8 +157,12 @@ kevent(queue_id, events.data(), events.size(), event_list, 4, NULL); if (num_events < 0) { - err.SetError(errno, DNBError::MachKernel); - err.LogThreaded("error: kevent() failed."); + if (errno == EINTR) + num_events = 0; + else { + err.SetError(errno, DNBError::MachKernel); + err.LogThreaded("error: kevent() failed."); + } } for (int i = 0; i < num_events; ++i) { @@ -169,7 +174,8 @@ lldb_private::SocketAddress &addr_in = socket_pair->second; lldb_private::SocketAddress accept_addr; socklen_t sa_len = accept_addr.GetMaxLength(); - m_fd = ::accept(sock_fd, &accept_addr.sockaddr(), &sa_len); + m_fd = llvm::sys::RetryAfterSignal(-1, ::accept, + sock_fd, &accept_addr.sockaddr(), &sa_len); if (m_fd == -1) { err.SetError(errno, DNBError::POSIX); @@ -230,7 +236,8 @@ address.SetPort(port); - if (-1 == ::connect(m_fd, &address.sockaddr(), address.GetLength())) { + if (-1 == llvm::sys::RetryAfterSignal(-1, ::connect, m_fd, + &address.sockaddr(), address.GetLength())) { Disconnect(false); continue; } @@ -275,7 +282,7 @@ rnb_err_t RNBSocket::OpenFile(const char *path) { DNBError err; - m_fd = open(path, O_RDWR); + m_fd = llvm::sys::RetryAfterSignal(-1, open, path, O_RDWR); if (m_fd == -1) { err.SetError(errno, DNBError::POSIX); err.LogThreaded("can't open file '%s'", path); @@ -323,7 +330,8 @@ // DNBLogThreadedIf(LOG_RNB_COMM, "%8u RNBSocket::%s calling read()", // (uint32_t)m_timer.ElapsedMicroSeconds(true), __FUNCTION__); DNBError err; - ssize_t bytesread = read(m_fd, buf, sizeof(buf)); + ssize_t bytesread = llvm::sys::RetryAfterSignal(-1, read, + m_fd, buf, sizeof(buf)); if (bytesread <= 0) err.SetError(errno, DNBError::POSIX); else @@ -356,7 +364,8 @@ return rnb_err; DNBError err; - ssize_t bytessent = write(m_fd, buffer, length); + ssize_t bytessent = llvm::sys::RetryAfterSignal(-1, write, + m_fd, buffer, length); if (bytessent < 0) err.SetError(errno, DNBError::POSIX); Index: lldb/tools/debugserver/source/debugserver.cpp =================================================================== --- lldb/tools/debugserver/source/debugserver.cpp +++ lldb/tools/debugserver/source/debugserver.cpp @@ -42,6 +42,8 @@ #include "RNBSocket.h" #include "SysSignal.h" +#include "llvm/Support/Errno.h" + // Global PID in case we get a signal and need to stop the process... nub_process_t g_pid = INVALID_NUB_PROCESS; @@ -681,8 +683,9 @@ saddr_un.sun_path[sizeof(saddr_un.sun_path) - 1] = '\0'; saddr_un.sun_len = SUN_LEN(&saddr_un); - if (::connect(s, (struct sockaddr *)&saddr_un, - static_cast(SUN_LEN(&saddr_un))) < 0) { + if (llvm::sys::RetryAfterSignal(-1, ::connect, s, + (struct sockaddr *)&saddr_un, + static_cast(SUN_LEN(&saddr_un))) < 0) { perror("error: connect (socket, &saddr_un, saddr_un_len)"); exit(1); } @@ -712,7 +715,8 @@ static void PortWasBoundCallbackNamedPipe(const void *baton, uint16_t port) { const char *named_pipe = (const char *)baton; if (named_pipe && named_pipe[0]) { - int fd = ::open(named_pipe, O_WRONLY); + int fd = llvm::sys::RetryAfterSignal(-1, ::open, + named_pipe, O_WRONLY); if (fd > -1) { char port_str[64]; const ssize_t port_str_len = @@ -1151,7 +1155,8 @@ else if (strcasecmp(optarg, "stderr") == 0) log_file = stderr; else { - log_file = fopen(optarg, "w"); + log_file = llvm::sys::RetryAfterSignal(nullptr, fopen, + optarg, "w"); if (log_file != NULL) setlinebuf(log_file); } @@ -1381,7 +1386,8 @@ // We have to close STDOUT and STDERR, else the first time we // try and do any, we get SIGPIPE and die as posix_spawn is // doing bad things with our file descriptors at the moment. - int null = open("/dev/null", O_RDWR); + int null = llvm::sys::RetryAfterSignal(-1, open, + "/dev/null", O_RDWR); dup2(null, STDOUT_FILENO); dup2(null, STDERR_FILENO); } else if (g_applist_opt != 0) { Index: lldb/tools/lldb-mi/MIUtilFileStd.cpp =================================================================== --- lldb/tools/lldb-mi/MIUtilFileStd.cpp +++ lldb/tools/lldb-mi/MIUtilFileStd.cpp @@ -18,6 +18,7 @@ #include "lldb/Host/FileSystem.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/Errno.h" //++ //------------------------------------------------------------------------------------ @@ -83,7 +84,8 @@ #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 @@ 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; Index: lldb/tools/lldb-server/lldb-platform.cpp =================================================================== --- lldb/tools/lldb-server/lldb-platform.cpp +++ lldb/tools/lldb-server/lldb-platform.cpp @@ -19,6 +19,7 @@ #include +#include "llvm/Support/Errno.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FileUtilities.h" @@ -315,7 +316,8 @@ printf("Connection established.\n"); if (g_server) { // Collect child zombie processes. - while (waitpid(-1, nullptr, WNOHANG) > 0) + while (llvm::sys::RetryAfterSignal(-1, waitpid, + -1, nullptr, WNOHANG) > 0) ; if (fork()) { // Parent doesn't need a connection to the lldb client Index: lldb/tools/lldb-vscode/lldb-vscode.cpp =================================================================== --- lldb/tools/lldb-vscode/lldb-vscode.cpp +++ lldb/tools/lldb-vscode/lldb-vscode.cpp @@ -41,6 +41,7 @@ #include #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 @@ } 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 @@ // 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