On 2017-01-18 at 14:38 GMT+01:00 Bill Allombert wrote:
On Wed, Jan 18, 2017 at 02:29:28PM +0100, Loïc Grenié wrote:
> On 2017-01-18 at 14:24 GMT+01:00 Bill Allombert wrote:
>
> > On Wed, Jan 18, 2017 at 01:25:24PM +0100, Loïc Grenié wrote:
> > >   for Debian -- but I failed the bug report.
> > >
> > >     To use it, compile it in a directory where you can create a file,
> > >   use it with ./fopen-bug and ./fopen-bug a. The second form (with
> > >   an argument) forks while the first one does not. The output are not
> > >   the same (while I would have expected that they are equal).
> >
> > Indeed, I get different result with jessie and stretch.
> >
> > However it seems the issue is due to buffering and the following:
> >    All open stdio(3) streams are flushed and closed.
> >
> > exit cause the inherited stream to be flushed in the child, but this does
> > not
> > empty the parent buffer, which is flushed twice.
> >
>
>      I'm not completely sure of what fflush does but the streams are opened
>   "read only" so fflush should be, as *I* understand it, a no-op.

stdout is not read only, and this is the stream which should be flushed
(in you test code)

     This does not help. The read-only stream ("f" in my code) is still
  read twice from line 4 onward (it does help if the output is piped in the
  sense that I get the same error with or without piping while without
  fflush(stdout) the situation was worse with a pipe).

            Loïc