Explorar o código

2010-11-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Retry open(2) and fallocate(2) when they are interrupted by
	signal.
	* src/AbstractDiskWriter.cc
Tatsuhiro Tsujikawa %!s(int64=15) %!d(string=hai) anos
pai
achega
f1af13567f
Modificáronse 2 ficheiros con 15 adicións e 4 borrados
  1. 6 0
      ChangeLog
  2. 9 4
      src/AbstractDiskWriter.cc

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2010-11-10  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Retry open(2) and fallocate(2) when they are interrupted by
+	signal.
+	* src/AbstractDiskWriter.cc
+
 2010-11-09  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Capture errno right after system/library call to avoid it to get

+ 9 - 4
src/AbstractDiskWriter.cc

@@ -98,7 +98,9 @@ void AbstractDiskWriter::openExistingFile(uint64_t totalLength)
     flags |= O_RDWR;
   }
 
-  if((fd_ = open(filename_.c_str(), flags, OPEN_MODE)) < 0) {
+  while((fd_ = open(filename_.c_str(), flags, OPEN_MODE)) == -1 &&
+        errno == EINTR);
+  if(fd_ < 0) {
     int errNum = errno;
     throw DL_ABORT_EX2
       (errNum,
@@ -112,8 +114,10 @@ void AbstractDiskWriter::createFile(int addFlags)
 {
   assert(!filename_.empty());
   util::mkdirs(File(filename_).getDirname());
-  if((fd_ = open(filename_.c_str(), O_CREAT|O_RDWR|O_TRUNC|O_BINARY|addFlags,
-                OPEN_MODE)) < 0) {
+
+  while((fd_ = open(filename_.c_str(), O_CREAT|O_RDWR|O_TRUNC|O_BINARY|addFlags,
+                    OPEN_MODE)) == -1 && errno == EINTR);
+  if(fd_ < 0) {
     int errNum = errno;
     throw DL_ABORT_EX2
       (errNum,
@@ -222,7 +226,8 @@ void AbstractDiskWriter::allocate(off_t offset, uint64_t length)
 # ifdef HAVE_FALLOCATE
   // For linux, we use fallocate to detect file system supports
   // fallocate or not.
-  int r = fallocate(fd_, 0, offset, length);
+  int r;
+  while((r = fallocate(fd_, 0, offset, length)) == -1 && errno == EINTR);
   int errNum = errno;
   if(r == -1) {
     throw DL_ABORT_EX(StringFormat("fallocate failed. cause: %s",