Mail Archives: djgpp-workers/2003/04/26/05:33:22
> From: sandmann AT clio DOT rice DOT edu (Charles Sandmann)
> Date: Fri, 25 Apr 2003 22:36:48 -0500 (CDT)
>
> > But I don't understand how a child can mess up the parent's environment. If a
> > child program closes inherited file descriptors, how does that affect the
> > parent program? Maybe I'm missing something here. I'm also not sure how the
> > parent would notice, unless __setup_file_rec_list is called after the child
> > has terminated. (I don't think it is.)
>
> What happens is the program does an unconditional close of the handles 3 and
> 4 because they are assumed to be associated with stdaux/stdprn during
> exit file rundown, which corrupts the internal buffering. Maybe it's
> just the child that is corrupted, I can't remember. Now when we set up
> those file descriptors, if 3 and 4 aren't there we flag them so they don't
> get closed at exit before the real file descriptors they were used with
> (which leaves them to be flushed properly).
IIRC, only the program which has handle 3 or 4 closed on startup gets
hit: if it fopen's some file, that file's FILE object gets handle 3 or
4, and the data wrotten to that FILE object does not get flushed when
our exit code fclose's all active FILE objects in stdiohk.c.
The relation of this to parent/child issue is that Perl closes handles
3 and 4 in its startup code, so any DJGPP program run by Perl suffers
from this problem. This is how the bug was discovered: Perl would run
m4 with a debug option, and the data written by m4 to the debug file
did not appear in the file. To a naive user, that looks like a bug in
Perl (i.e. in the parent program).
The thread where the problem was diagnosed and discussed is available
in the archives of this mailing list starting with this message:
http://www.delorie.com/djgpp/mail-archives/browse.cgi?p=djgpp-workers/2001/09/23/11:21:59
For the description of the original bug and the initial discussions
of its possible causes, see this thread:
http://www.delorie.com/djgpp/mail-archives/browse.cgi?p=djgpp-workers/2001/08/14/16:27:37
- Raw text -