]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: bufferlist::read_file: return read errors
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 30 Dec 2010 22:41:03 +0000 (14:41 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 30 Dec 2010 22:50:06 +0000 (14:50 -0800)
Don't ignore errors when reading a file with buffer::list.

Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/common/buffer.cc

index b1a18e30620e63e17e2ffc397add5ce839b842e7..0757218831d390c46b3903486ee9e11635f908d0 100644 (file)
@@ -102,17 +102,27 @@ int buffer::list::read_file(const char *fn, bool silent)
   int got = 0;
   while (left > 0) {
     int r = ::read(fd, (void *)(bp.c_str() + got), left);
-    if (r <= 0) {
+    if (r == 0) {
+      // Premature EOF.
+      // Perhaps the file changed between stat() and read()?
+      if (!silent) {
+       derr << "bufferlist::read_file(" << fn << "): warning: got premature "
+            << "EOF:" << dendl;
+      }
+      break;
+    }
+    else if (r < 0) {
       int err = errno;
       if (err == EINTR) {
        // ignore EINTR, 'tis a silly error
        continue;
       }
       if (!silent) {
-       derr << "buffer::list::read_file: read error:"
+       derr << "bufferlist::read_file(" << fn << "): read error:"
             << cpp_strerror(err) << dendl;
       }
-      break;
+      TEMP_FAILURE_RETRY(::close(fd));
+      return -err;
     }
     got += r;
     left -= r;