[llvm-commits] [llvm] r103158 - /llvm/trunk/lib/Support/raw_ostream.cpp

Dan Gohman gohman at apple.com
Wed May 5 19:06:20 PDT 2010


Author: djg
Date: Wed May  5 21:06:20 2010
New Revision: 103158

URL: http://llvm.org/viewvc/llvm-project?rev=103158&view=rev
Log:
Handle the case where open(2) or close(2) is interrupted by a signal when
automatic syscall restarting is disabled.

Also, fix the build on systems which don't define EWOULDBLOCK.

Modified:
    llvm/trunk/lib/Support/raw_ostream.cpp

Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=103158&r1=103157&r2=103158&view=diff
==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Wed May  5 21:06:20 2010
@@ -400,21 +400,27 @@
   if (Flags & F_Excl)
     OpenFlags |= O_EXCL;
 
-  FD = open(Filename, OpenFlags, 0664);
-  if (FD < 0) {
-    ErrorInfo = "Error opening output file '" + std::string(Filename) + "'";
-    ShouldClose = false;
-  } else {
-    ShouldClose = true;
+  while ((FD = open(Filename, OpenFlags, 0664)) < 0) {
+    if (errno != EINTR) {
+      ErrorInfo = "Error opening output file '" + std::string(Filename) + "'";
+      ShouldClose = false;
+      return;
+    }
   }
+
+  // Ok, we successfully opened the file, so it'll need to be closed.
+  ShouldClose = true;
 }
 
 raw_fd_ostream::~raw_fd_ostream() {
   if (FD < 0) return;
   flush();
   if (ShouldClose)
-    if (::close(FD) != 0)
-      error_detected();
+    while (::close(FD) != 0)
+      if (errno != EINTR) {
+        error_detected();
+        break;
+      }
 }
 
 
@@ -432,7 +438,11 @@
       // some programs, such as bjam, assume that their child processes
       // will treat them as if they are. If you don't want this code to
       // spin, don't use O_NONBLOCK file descriptors with raw_ostream.
-      if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
+      if (errno == EINTR || errno == EAGAIN
+#ifdef EWOULDBLOCK
+          || errno == EWOULDBLOCK
+#endif
+          )
         continue;
 
       // Otherwise it's a non-recoverable error. Note it and quit.
@@ -452,8 +462,11 @@
   assert(ShouldClose);
   ShouldClose = false;
   flush();
-  if (::close(FD) != 0)
-    error_detected();
+  while (::close(FD) != 0)
+    if (errno != EINTR) {
+      error_detected();
+      break;
+    }
   FD = -1;
 }
 





More information about the llvm-commits mailing list