This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make PerlIO marginally reentrant
authorDavid Mitchell <davem@iabyn.com>
Mon, 22 Nov 2010 19:18:49 +0000 (19:18 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 26 Nov 2010 16:01:34 +0000 (16:01 +0000)
commitabf9167d3fff002ddaed53abb44d638387bca978
treef81a5b1c720adff647b3866f0a7b7890b444534b
parentcc6623a84b782d30463b9046c2916f35064a7e3f
Make PerlIO marginally reentrant

Currently if an operation on a file handle is interrupted, and if
the signal handler accesses that same file handle (e.g. closes it),
then perl will crash. See [perl #75556].

This commit provides some basic infrastructure to avoid segfaults.
Basically it adds a lock count field to each handle (by re-purposing the
unused flags field in the PL_perlio array), then each time a signal
handler is called, the count is incremented. Then various parts of PerlIO
use a positive count to change behaviour. Most importantly, when layers
are popped, the PerlIOl structure is cleared, but not freed, and is left
in the chain of layers. This means that callers still holding pointers to
the various layers won't access freed structures. It does however mean
that PerlIOl structs may be leaked, and possibly slots in PL_perlio. But
this is better than crashing.

Not much has been done to give sensible behaviour on re-entrancy; for
example, a buffer that has already been written once might get written
again. Fixing this sort of thing would require a large-scale audit of
perlio.c.
MANIFEST
perl.h
perlio.c
perliol.h
pod/perlipc.pod
t/io/eintr.t [new file with mode: 0644]