mgorny updated this revision to Diff 191657.
mgorny marked an inline comment as done.
mgorny added a comment.

Applied requested changes.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59606/new/

https://reviews.llvm.org/D59606

Files:
  lldb/source/Host/common/PseudoTerminal.cpp
  lldb/source/Host/common/Socket.cpp
  lldb/source/Host/common/TCPSocket.cpp
  lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
  lldb/source/Host/posix/DomainSocket.cpp
  lldb/source/Host/posix/FileSystem.cpp
  lldb/source/Host/posix/LockFilePosix.cpp
  lldb/source/Host/posix/PipePosix.cpp
  lldb/source/Host/posix/ProcessLauncherPosixFork.cpp
  lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
  lldb/source/Plugins/Process/Linux/SingleStepCheck.cpp
  lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
  lldb/tools/lldb-mi/MIUtilFileStd.cpp
  lldb/tools/lldb-vscode/lldb-vscode.cpp

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 <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 @@
     } 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
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/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 <stdio.h>
 
@@ -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/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/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/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/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/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/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 <fcntl.h>
 #include <unistd.h>
 
@@ -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/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/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 <stddef.h>
@@ -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/ConnectionFileDescriptorPosix.cpp
===================================================================
--- lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
+++ lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp
@@ -262,7 +262,7 @@
         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);
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/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/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)
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to