[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: possible bug in fseek of buffered files shared between processes (example uses stdin)
On Tue, Nov 2, 2021 at 3:17 PM RVP <rvp%sdf.org@localhost> wrote:
> On Tue, 2 Nov 2021, Christos Zoulas wrote:
> > In article <a91717c9-3b97-2756-5b73-81d5dee4e7%SDF.ORG@localhost>,
> > RVP <rvp%SDF.ORG@localhost> wrote:
> >> This looks like a useful behaviour to add to the libc close routines.
> > I agree!
FWIW at least MUSL seems to be just doing an fflush(), which might be
the part where I thought NetBSD's implementation might be diverging
from the standard where it says in calls to fseek() in 18.104.22.168.4
"For a text stream, either offset shall be zero, or offset shall be a
value returned by an earlier successful call to the ftell function on
a stream associated with the same file and whence shall be SEEK_SET."
There is also a mention somewhere else that fflush() is required to
"write" the position, which seems to imply that fflush(stdin) might
have been what was missing (but didn't help) in my original
Note that the way the wording is done in that paragraph, it might seem
to imply that the position is a property of the file and not of the
FILE, so you could have more than one FILE pointing to the same fd,
and any fseek on it should be visible to them all.
> diff -urN stdio.orig/findfp.c stdio/findfp.c
> --- stdio.orig/findfp.c 2012-03-27 15:05:42.000000000 +0000
> +++ stdio/findfp.c 2021-11-02 21:46:29.767257736 +0000
> @@ -207,8 +207,10 @@
> - /* (void) _fwalk(fclose); */
> + (void) _fwalk(fclose);
> +#if 0
> (void) fflush(NULL); /* `cheating' */
> Carlo, can you see if that works with your use-case?
I only have a slow OpenBSD VM with current to test, so I am building a
port of your patch there (which seems will take several more hours to
build), I kept the "cheating" part there though, so not sure how much
useful my answer would be, but I expect it to work.
Main Index |
Thread Index |