]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4473. [bug] Only call fsync / _commit on regular files. [RT #43196]
authorMark Andrews <marka@isc.org>
Wed, 5 Oct 2016 01:20:02 +0000 (12:20 +1100)
committerMark Andrews <marka@isc.org>
Wed, 5 Oct 2016 01:20:02 +0000 (12:20 +1100)
CHANGES
lib/isc/unix/stdio.c
lib/isc/win32/stdio.c

diff --git a/CHANGES b/CHANGES
index 0f085a557009fc6212b9593435d65d9be5fc4bf6..8a7bf7eb591b474aa2e23a3bc77b7819d5c09686 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+4473.  [bug]           Only call fsync / _commit on regular files. [RT #43196]
+
 4472.  [bug]           Named could fail to find the correct NSEC3 records when
                        a zone was updated between looking for the answer and
                        looking for the NSEC3 records proving non-existance
index 03d0e7c31643530f2e4575d860265f007ca07e2b..d10d1121ca5c53c2bd8594fb25ebaf7d101497a0 100644 (file)
@@ -128,14 +128,20 @@ isc_stdio_flush(FILE *f) {
 
 isc_result_t
 isc_stdio_sync(FILE *f) {
+       struct stat buf;
        int r;
 
-       r = fsync(fileno(f));
+       if (fstat(fileno(f), &buf) != 0)
+               return (isc__errno2result(errno));
        /*
-        * fsync is not supported on sockets and pipes which
-        * result in EINVAL / ENOTSUP.
+        * Only call fsync() on regular files.
         */
-       if (r == 0 || errno == EINVAL || errno == ENOTSUP)
+       if ((buf.st_mode & S_IFMT) != S_IFREG)
+               return (ISC_R_SUCCESS);
+
+       r = fsync(fileno(f));
+       if (r == 0)
                return (ISC_R_SUCCESS);
        else
                return (isc__errno2result(errno));
index 6735d2ba6f51f5785578aa067d65b35b5d5bc209..a03a37ae4865573a076fd42c9a5503ee0cfc9461 100644 (file)
@@ -16,6 +16,9 @@
 #include <isc/stdio.h>
 #include <isc/util.h>
 
+#include <sys/stat.h>
+#include <sys/types.h>
+
 #include "errno2result.h"
 
 isc_result_t
@@ -124,8 +127,18 @@ isc_stdio_flush(FILE *f) {
 
 isc_result_t
 isc_stdio_sync(FILE *f) {
+       struct _stat buf;
        int r;
 
+       if (_fstat(_fileno(f), &buf) != 0)
+               return (isc__errno2result(errno));
+
+       /*
+        * Only call _commit() on regular files.
+        */
+       if ((buf.st_mode & S_IFMT) != S_IFREG)
+               return (ISC_R_SUCCESS);
+
        r = _commit(_fileno(f));
        if (r == 0)
                return (ISC_R_SUCCESS);