From c99efbfa1bc8c447f237de65a4b6b2373831da83 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 5 Oct 2016 12:20:02 +1100 Subject: [PATCH] 4473. [bug] Only call fsync / _commit on regular files. [RT #43196] (cherry picked from commit fe4d0fbc7c88acf4f2d1a4f6d612f123b56fbd98) --- CHANGES | 2 ++ lib/isc/unix/stdio.c | 14 ++++++++++---- lib/isc/win32/stdio.c | 13 +++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 19bda7c75c..a97981659a 100644 --- 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 diff --git a/lib/isc/unix/stdio.c b/lib/isc/unix/stdio.c index 82ef9c255f..5b2cae918d 100644 --- a/lib/isc/unix/stdio.c +++ b/lib/isc/unix/stdio.c @@ -137,14 +137,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)); diff --git a/lib/isc/win32/stdio.c b/lib/isc/win32/stdio.c index 6f65fdbf7e..bdea0cb65f 100644 --- a/lib/isc/win32/stdio.c +++ b/lib/isc/win32/stdio.c @@ -25,6 +25,9 @@ #include #include +#include +#include + #include "errno2result.h" isc_result_t @@ -133,8 +136,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);