summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zafman <david.zafman@inktank.com>2013-09-27 16:25:36 -0700
committerDavid Zafman <david.zafman@inktank.com>2013-09-27 16:25:36 -0700
commit14d4862048be0262bf838cc38465c77a78ea494e (patch)
treee48ea6ee591c373185a96ab443f9a03b05ea442c
parent4d54c73b7013b772005e9677f629ed2c8c12c6f2 (diff)
downloadceph-wip-6422.tar.gz
Review changes to be squashedwip-6422
Fix error handling (Discovered this myself) Add check for the last fsync error
-rw-r--r--src/common/safe_io.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/common/safe_io.c b/src/common/safe_io.c
index 5880bc1bc75..e3e40ff989e 100644
--- a/src/common/safe_io.c
+++ b/src/common/safe_io.c
@@ -145,26 +145,29 @@ int safe_write_file(const char *base, const char *file,
}
ret = fsync(fd);
+ if (ret < 0) ret = -errno;
TEMP_FAILURE_RETRY(close(fd));
- if (ret) {
+ if (ret < 0) {
unlink(tmp);
return ret;
}
ret = rename(tmp, fn);
- if (ret) {
+ if (ret < 0) {
+ ret = -errno;
unlink(tmp);
return ret;
}
fd = open(base, O_RDONLY);
if (fd < 0) {
- ret = errno;
- return -ret;
+ ret = -errno;
+ return ret;
}
- fsync(fd);
+ ret = fsync(fd);
+ if (ret < 0) ret = -errno;
TEMP_FAILURE_RETRY(close(fd));
- return 0;
+ return ret;
}
int safe_read_file(const char *base, const char *file,