summaryrefslogtreecommitdiff
path: root/file_io
diff options
context:
space:
mode:
authorBranko Čibej <brane@apache.org>2020-11-12 08:54:27 +0000
committerBranko Čibej <brane@apache.org>2020-11-12 08:54:27 +0000
commit8e470dfcfdc616530f0735af3d6692ec3757d299 (patch)
treef1d755a236fdb4e1f21ea0079705593d65a2f401 /file_io
parentc10354014ec3926f514474374275d613b5cff221 (diff)
downloadapr-8e470dfcfdc616530f0735af3d6692ec3757d299.tar.gz
Follow up to r1790200: fall back to fsync() if F_FULLFSYNC is not supported
by the file descriptor, filesystem or underlying device. See, e.g.: https://github.com/vim/vim/pull/4025 git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1883340 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io')
-rw-r--r--file_io/unix/readwrite.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/file_io/unix/readwrite.c b/file_io/unix/readwrite.c
index f7429ee7b..593bf66a7 100644
--- a/file_io/unix/readwrite.c
+++ b/file_io/unix/readwrite.c
@@ -466,6 +466,7 @@ APR_DECLARE(apr_status_t) apr_file_sync(apr_file_t *thefile)
APR_DECLARE(apr_status_t) apr_file_datasync(apr_file_t *thefile)
{
apr_status_t rv = APR_SUCCESS;
+ int os_status = 0;
file_lock(thefile);
@@ -479,12 +480,17 @@ APR_DECLARE(apr_status_t) apr_file_datasync(apr_file_t *thefile)
}
#ifdef HAVE_FDATASYNC
- if (fdatasync(thefile->filedes)) {
+ os_status = fdatasync(thefile->filedes);
#elif defined(F_FULLFSYNC)
- if (fcntl(thefile->filedes, F_FULLFSYNC)) {
+ os_status = fcntl(thefile->filedes, F_FULLFSYNC);
+ if (os_status) {
+ /* Fall back to fsync() if the device doesn't support F_FULLFSYNC. */
+ os_status = fsync(thefile->filedes);
+ }
#else
- if (fsync(thefile->filedes)) {
+ os_status = fsync(thefile->filedes);
#endif
+ if (os_status) {
rv = apr_get_os_error();
}