bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug: tests/fsync.c: don't check for fsync failure on invalid fd


From: Paul Eggert
Subject: Re: Bug: tests/fsync.c: don't check for fsync failure on invalid fd
Date: Wed, 13 Mar 2013 23:38:00 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4

On 03/13/2013 07:11 PM, Phillip Susi wrote:

> If anyone is going to use it then it may be worth the bother.

MIT Kerberos relies on fsync (invalid_fd) returning -1,
so I suppose it's worth the bother.
Here's a proposed patch, to libeatmydata.
I haven't tested it.

=== modified file 'libeatmydata/libeatmydata.c'
--- libeatmydata/libeatmydata.c 2012-09-26 06:57:32 +0000
+++ libeatmydata/libeatmydata.c 2013-03-14 06:32:16 +0000
@@ -79,6 +79,11 @@
 #endif
 }
 
+static int validate_fd(int fd)
+{
+       return fcntl(fd, F_GETFD) < 0 ? -1 : 0;
+}
+
 static int eatmydata_is_hungry(void)
 {
        /* Init here, as it is called before any libc functions */
@@ -103,10 +108,8 @@
 
 int LIBEATMYDATA_API fsync(int fd)
 {
-       if (eatmydata_is_hungry()) {
-               errno= 0;
-               return 0;
-       }
+       if (eatmydata_is_hungry())
+               return validate_fd(fd);
 
        return (*libc_fsync)(fd);
 }
@@ -148,10 +151,8 @@
 
 int LIBEATMYDATA_API fdatasync(int fd)
 {
-       if (eatmydata_is_hungry()) {
-               errno= 0;
-               return 0;
-       }
+       if (eatmydata_is_hungry())
+               return validate_fd(fd);
 
        return (*libc_fdatasync)(fd);
 }
@@ -169,10 +170,10 @@
 #ifdef HAVE_SYNC_FILE_RANGE
 int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags)
 {
-       if (eatmydata_is_hungry()) {
-               errno= 0;
-               return 0;
-       }
+       if (eatmydata_is_hungry())
+               flags &= ~ (SYNC_FILE_RANGE_WAIT_BEFORE
+                           | SYNC_FILE_RANGE_WRITE
+                           | SYNC_FILE_RANGE_WAIT_AFTER);
 
        return (libc_sync_file_range)(fd, offset, nbytes, flags);
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]