[Top][All Lists]

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

Re: [Chicken-hackers] Fix attempt for bug #1269 "Port or reader state co

From: Kooda
Subject: Re: [Chicken-hackers] Fix attempt for bug #1269 "Port or reader state corruption"
Date: Fri, 25 Mar 2016 17:30:11 +0100
User-agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (Gojō) APEL/10.8 EasyPG/1.0.0 Emacs/24.4 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)


I’ve been spending some time on the musl libc IRC channel today, and
discussed the issue with them.

The conclusion is that the bug is indeed caused by the exit() call,
which is required to synchronize stdio FILE* streams with their
associated file descriptor.

Unfortunately, in evhan’s test case as well as the core and
scsh-process test suites (and probably most other cases), the call to
fork() happens while the FILE* buffer is in use. So at exit() time,
the file descriptor associated with the source file will get lseek-ed
to match the position in the FILE* buffer.

This happens for all file descriptors associated to stdio FILE*

The obvious fix for this is to call fflush(NULL) before we fork. This
call should synchronize all FILE* streams with their file descriptors.

Unfortunately, POSIX only documents the behaviour of fflush(NULL) for
*output and update streams*. Input streams stay untouched. See here:

>From this, I only see a handful ways of working around the bug:

- Calling _exit() instead of exit() in the default exit-handler. This
  would prevent the streams from synchronizing with their FDs but
  would completely throw away functions registered with atexit() or

- Calling fflush() on every input file owned by CHICKEN before calling
  fork(). This would require a way to get all FILE* streams opened by
  CHICKEN, I don’t know if we have that. It would not cause the
  atexit() problem mentioned earlier, but it wouldn’t be completely
  general, as we wouldn’t be able to call fflush() on streams not
  owned by CHICKEN.

- Getting rid of every stdio use in core and roll our own buffered i/o
  system. This is quite involved but may also be a push in the right
  direction for the ports system redesign of CHICKEN 5.

Anyhow, we should at least add a call to fflush(NULL) in the
process-fork procedure, as it takes care of the output streams.

Some musl people will get it touch with the POSIX work group to see if
there is a way to fix this.

I hope this explains clearly what happens. If you find another way to
fix this bug, please go ahead and tell us!

reply via email to

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