From 51462d6b834b07ecc94568294e726935b5c3fd4d Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Thu, 30 Dec 2010 14:41:03 -0800 Subject: [PATCH] common: bufferlist::read_file: return read errors Don't ignore errors when reading a file with buffer::list. Signed-off-by: Colin McCabe --- src/common/buffer.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index b1a18e30620e6..0757218831d39 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -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; -- 2.39.5