diff options
author | Lubomir Rintel <lubo.rintel@gooddata.com> | 2010-07-26 16:05:05 +0200 |
---|---|---|
committer | Rafael Garcia-Suarez <rgs@consttype.org> | 2010-07-26 16:06:25 +0200 |
commit | d016601746b09e0f0a7eb2148b6eb594d3992339 (patch) | |
tree | 4e1ca2a5523dea59a0931cafbbbb4bcd93dcb10a /t | |
parent | 1e8125c621275d18c74bc8dae3bfc3c03929fe1e (diff) | |
download | perl-d016601746b09e0f0a7eb2148b6eb594d3992339.tar.gz |
Restore errno if signal handler changes it
It's way too easy to forget to "local $!" in signal handlers and
changing $! when signal hits between two ops is probably never useful.
Diffstat (limited to 't')
-rw-r--r-- | t/io/errnosig.t | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/t/io/errnosig.t b/t/io/errnosig.t new file mode 100644 index 0000000000..8effcf1144 --- /dev/null +++ b/t/io/errnosig.t @@ -0,0 +1,30 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = qw(. ../lib); +} + +require Config; import Config; +require "test.pl"; +plan(tests => 1); + +SKIP: { + skip("Alarm not supported", 1) unless exists $Config{'d_alarm'}; + + $SIG{ALRM} = sub { + # We could call anything that modifies $! here, but + # this way we can be sure that it isn't the same + # errno as interrupted sleep() would return, and are + # able to check it thereafter. + $! = -1; + }; + + alarm 1; + sleep 2; + + # Interrupted sleeps sets errno to EAGAIN, but signal + # that # hits after it (if safe signal handling is enabled) + # causes a routing that modifies $! to be run afterwards + isnt($! + 0, -1, 'Signal does not modify $!'); +} |