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