[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

fsync fails on O_RDONLY file handle (patch attached)

From: Mike Ashmore <mike_at_motomike.net>
Date: 2006-02-06 22:49:53 CET

Hello all,
I'm the proud owner of a copy of STOP 6.2, a multi-level secure
operating system that acts a lot like RedHat Linux. Naturally, one of
the first things I wanted to do to support my work was get Subversion
up and running.

The build went smoothly. But when I tried to do "svnadmin create
<my_repository> --fs-type=fsfs", I got an error saying "svnadmin:
can't flush file to disk".

Now, STOP is very nearly identical to Linux, but it's got some
idiosyncrasies. In this case, they relate to the operation of fsync().

According to my man pages, POSIX doesn't define a behavior for fsync
() on a file descriptor that was opened O_RDONLY. Unfortunately,
STOP's authors chose to make fsync fail on a read-only file
descriptor, while apparently every other implementor in the galaxy
chose to succeed (and presumably silently no-op).

Anyway, to get everything working, I had to tweak libsvn_subr/io.c
just a bit. The patch is attached. And if there's a better way to
find out if a file descriptor is read-only, please let me know.

I'm not a subscriber to this list, so please CC replies to mike (at)
motomike (dot) net.

-Mike Ashmore

diff -ru subversion-1.3.0/subversion/libsvn_subr/io.c
--- subversion-1.3.0/subversion/libsvn_subr/io.c 2006-02-06
16:24:30.000000000 -0500
+++ subversion-1.3.0-patch/subversion/libsvn_subr/io.c 2006-02-06
16:26:43.000000000 -0500
@@ -1399,7 +1399,11 @@
        int rv;

        do {
- rv = fsync (filehand);
+ if (write(filehand, NULL, 0) == 0) { // Check if filehand is
O_RDONLY or not
+ rv = fsync (filehand);
+ } else { // fsync on a O_RDONLY file could fail, and is
unnecessary in any case.
+ rv = 0;
+ }
        } while (rv == -1 && APR_STATUS_IS_EINTR (apr_get_os_error ()));

        /* If the file is in a memory filesystem, fsync() may return

To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Feb 8 16:51:58 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.