summaryrefslogtreecommitdiff
path: root/src/os_posix/os_fs.c
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@mongodb.com>2016-06-03 15:18:38 +1000
committerMichael Cahill <michael.cahill@mongodb.com>2016-06-03 15:18:38 +1000
commitfb1663e6fc800be97c0ddc697b6f939dc610e08e (patch)
tree309dd2bf6118a916be76552234df812942359611 /src/os_posix/os_fs.c
parentff108d7c705b82e482fb17e33488dc14304bf259 (diff)
parentc9dfa31598c33255a5f5710d9b22a1ed648feca3 (diff)
downloadmongo-fb1663e6fc800be97c0ddc697b6f939dc610e08e.tar.gz
Merge branch 'develop' into mongodb-3.4mongodb-3.3.8mongodb-3.3.7
Diffstat (limited to 'src/os_posix/os_fs.c')
-rw-r--r--src/os_posix/os_fs.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/os_posix/os_fs.c b/src/os_posix/os_fs.c
index c05f75f2bd5..1cfa8fd2d2d 100644
--- a/src/os_posix/os_fs.c
+++ b/src/os_posix/os_fs.c
@@ -53,7 +53,7 @@ __posix_sync(
* "This is currently implemented on HFS, MS-DOS (FAT), and Universal
* Disk Format (UDF) file systems."
*/
- WT_SYSCALL_RETRY(fcntl(fd, F_FULLFSYNC, 0), ret);
+ WT_SYSCALL_RETRY(fcntl(fd, F_FULLFSYNC, 0) == -1 ? -1 : 0, ret);
if (ret == 0)
return (0);
/*
@@ -92,7 +92,7 @@ __posix_directory_sync(
session = (WT_SESSION_IMPL *)wt_session;
WT_SYSCALL_RETRY((
- (fd = open(path, O_RDONLY, 0444)) == -1 ? 1 : 0), ret);
+ (fd = open(path, O_RDONLY, 0444)) == -1 ? -1 : 0), ret);
if (ret != 0)
WT_RET_MSG(session, ret, "%s: directory-sync: open", path);
@@ -151,10 +151,17 @@ __posix_fs_remove(
session = (WT_SESSION_IMPL *)wt_session;
- WT_SYSCALL_RETRY(remove(name), ret);
+ /*
+ * ISO C doesn't require remove return -1 on failure or set errno (note
+ * POSIX 1003.1 extends C with those requirements). Regardless, use the
+ * unlink system call, instead of remove, to simplify error handling;
+ * where we're not doing any special checking for standards compliance,
+ * using unlink may be marginally safer.
+ */
+ WT_SYSCALL_RETRY(unlink(name), ret);
if (ret == 0)
return (0);
- WT_RET_MSG(session, ret, "%s: file-remove: remove", name);
+ WT_RET_MSG(session, ret, "%s: file-remove: unlink", name);
}
/*
@@ -172,7 +179,14 @@ __posix_fs_rename(WT_FILE_SYSTEM *file_system,
session = (WT_SESSION_IMPL *)wt_session;
- WT_SYSCALL_RETRY(rename(from, to), ret);
+ /*
+ * ISO C doesn't require rename return -1 on failure or set errno (note
+ * POSIX 1003.1 extends C with those requirements). Be cautious, force
+ * any non-zero return to -1 so we'll check errno. We can still end up
+ * with the wrong errno (if errno is garbage), or the generic WT_ERROR
+ * return (if errno is 0), but we've done the best we can.
+ */
+ WT_SYSCALL_RETRY(rename(from, to) != 0 ? -1 : 0, ret);
if (ret == 0)
return (0);
WT_RET_MSG(session, ret, "%s to %s: file-rename: rename", from, to);
@@ -295,7 +309,7 @@ __posix_file_lock(
fl.l_type = lock ? F_WRLCK : F_UNLCK;
fl.l_whence = SEEK_SET;
- WT_SYSCALL_RETRY(fcntl(pfh->fd, F_SETLK, &fl), ret);
+ WT_SYSCALL_RETRY(fcntl(pfh->fd, F_SETLK, &fl) == -1 ? -1 : 0, ret);
if (ret == 0)
return (0);
WT_RET_MSG(session, ret, "%s: handle-lock: fcntl", file_handle->name);
@@ -533,7 +547,7 @@ __posix_open_file(WT_FILE_SYSTEM *file_system, WT_SESSION *wt_session,
f |= O_CLOEXEC;
#endif
WT_SYSCALL_RETRY((
- (pfh->fd = open(name, f, 0444)) == -1 ? 1 : 0), ret);
+ (pfh->fd = open(name, f, 0444)) == -1 ? -1 : 0), ret);
if (ret != 0)
WT_ERR_MSG(session, ret, "%s: handle-open: open", name);
WT_ERR(__posix_open_file_cloexec(session, pfh->fd, name));
@@ -587,7 +601,7 @@ __posix_open_file(WT_FILE_SYSTEM *file_system, WT_SESSION *wt_session,
#endif
}
- WT_SYSCALL_RETRY(((pfh->fd = open(name, f, mode)) == -1 ? 1 : 0), ret);
+ WT_SYSCALL_RETRY(((pfh->fd = open(name, f, mode)) == -1 ? -1 : 0), ret);
if (ret != 0)
WT_ERR_MSG(session, ret,
pfh->direct_io ?