3 # If a read or write is interrupted by a signal, Perl will call the
4 # signal handler and then attempt to restart the call. If the handler does
5 # something nasty like close the handle or pop layers, make sure that the
6 # read/write handles this gracefully (for some definition of 'graceful':
7 # principally, don't segfault).
26 skip_all('pipe not implemented');
29 unless (exists $Config{'d_alarm'}) {
30 skip_all('alarm not implemented');
34 # XXX for some reason the stdio layer doesn't seem to interrupt
35 # write system call when the alarm triggers. This makes the tests
38 if (exists $ENV{PERLIO} && $ENV{PERLIO} =~ /stdio/ ) {
39 skip_all('stdio not supported for this script');
43 # on Win32, alarm() won't interrupt the read/write call.
44 # Similar issues with VMS.
46 if ($^O eq 'VMS' || $^O eq 'MSWin32' || $^O eq 'cygwin') {
47 skip_all('various portability issues');
51 my ($in, $out, $st, $sigst, $buf);
56 # make two handles that will always block
59 undef $in; undef $out; # use fresh handles each time
64 $SIG{PIPE} = 'IGNORE';
69 $SIG{ALRM} = sub { $sigst = close($in) ? "ok" : "nok" };
71 $st = read($in, $buf, 1);
73 is($sigst, 'ok', 'read/close: sig handler close status');
74 ok(!$st, 'read/close: read status');
75 ok(!close($in), 'read/close: close status');
80 $SIG{ALRM} = sub { die };
82 $st = eval { read($in, $buf, 1) };
84 ok(!$st, 'read/die: read status');
85 ok(close($in), 'read/die: close status');
90 $SIG{ALRM} = sub { $sigst = close($out) ? "ok" : "nok" };
91 $buf = "a" x 1_000_000 . "\n"; # bigger than any pipe buffer hopefully
92 select $out; $| = 1; select STDOUT;
94 $st = print $out $buf;
96 is($sigst, 'nok', 'print/close: sig handler close status');
97 ok(!$st, 'print/close: print status');
98 ok(!close($out), 'print/close: close status');
103 $SIG{ALRM} = sub { die };
104 $buf = "a" x 1_000_000 . "\n"; # bigger than any pipe buffer hopefully
105 select $out; $| = 1; select STDOUT;
107 $st = eval { print $out $buf };
109 ok(!$st, 'print/die: print status');
110 # the close will hang since there's data to flush, so use alarm
112 ok(!eval {close($out)}, 'print/die: close status');
117 # Apparently there's nothing in standard Linux that can cause an
118 # EINTR in close(2); but run the code below just in case it does on some
119 # platform, just to see if it segfaults.
121 $SIG{ALRM} = sub { $sigst = close($in) ? "ok" : "nok" };
129 $SIG{ALRM} = sub { die };
134 # vim: ts=4 sts=4 sw=4: