bug-gnulib
[Top][All Lists]
Advanced

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

Re: fseek failing without fflush?


From: Eric Blake
Subject: Re: fseek failing without fflush?
Date: Tue, 09 Aug 2011 15:26:08 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.11

On 08/09/2011 12:16 PM, Eric Blake wrote:
On 08/09/2011 12:03 PM, John W. Eaton wrote:
On 9-Aug-2011, Eric Blake wrote:

| I'm thinking this may be a bug in gnulib. I also know that glibc 2.14
| fixed one fclose() bug in how fclose() relates to fflush(), but at the
| expense of introducing another, and that gnulib does not yet detect and
| work around that glibc bug. I'm assuming that you were testing on a
| glibc platform, but which version?

Sorry, I should have included this info in my earlier mail.

$ ldd --version
ldd (Debian EGLIBC 2.13-7) 2.13

Definitely a bug in gnulib's ftell replacement, which is kicking in
because of [e]glibc's fflush() bugs :(

But the gnulib replacement converts fseek(f,0,SEEK_END) into
lseek(,0,SEEK_END), without populating the read buffer and apparently
without updating the stream position, at which point the ftell() is
hopelessly lost.

I'm hoping to be able to decipher the gnulib code enough to have a patch
later today.

Found it. And the fix is embarrassingly simple - we were simply failing to update the stream position to match the fd position:

@@ -111,6 +107,7 @@ fseeko (FILE *fp, off_t offset, int whence)

#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
       fp->_flags &= ~_IO_EOF_SEEN;
+      fp->_offset = pos;
#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
 # if defined __CYGWIN__
       /* fp_->_offset is typed as an integer.  */

And in fact, it turns out I asked Bruno about it a couple years ago! He had special-cased some code in ftello.c in order to make a test pass under glibc, without understanding the real reason why he was getting the testsuite failures:
https://lists.gnu.org/archive/html/bug-gnulib/2009-01/msg00171.html

This means that the real fix for this issue should undo the hacks, since the testsuite was already robust enough to catch this problem and we had just hacked around it, rather than having to also worry about enhancing test-ftello.c. Final patch coming soon.

--
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

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