From 14d4862048be0262bf838cc38465c77a78ea494e Mon Sep 17 00:00:00 2001 From: David Zafman Date: Fri, 27 Sep 2013 16:25:36 -0700 Subject: Review changes to be squashed Fix error handling (Discovered this myself) Add check for the last fsync error --- src/common/safe_io.c | 15 +++++++++------ 1 file 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, -- cgit v1.2.1