xref: /openbsd-src/gnu/usr.bin/perl/t/io/closepid.t (revision 256a93a44f36679bee503f12e49566c2183f6181)
16fb12b70Safresh1#!./perl
26fb12b70Safresh1
36fb12b70Safresh1BEGIN {
46fb12b70Safresh1    chdir 't' if -d 't';
5*5759b3d2Safresh1    require "./test.pl";
6*5759b3d2Safresh1    set_up_inc('../lib');
76fb12b70Safresh1}
86fb12b70Safresh1
96fb12b70Safresh1plan tests => 3;
106fb12b70Safresh1watchdog(10, $^O eq 'MSWin32' ? "alarm" : '');
116fb12b70Safresh1
126fb12b70Safresh1use Config;
136fb12b70Safresh1$| = 1;
146fb12b70Safresh1$SIG{PIPE} = 'IGNORE';
156fb12b70Safresh1# work around a shell set to ignore HUP
166fb12b70Safresh1$SIG{HUP} = 'DEFAULT';
176fb12b70Safresh1$SIG{HUP} = 'IGNORE' if $^O eq 'interix';
186fb12b70Safresh1
196fb12b70Safresh1my $perl = which_perl();
206fb12b70Safresh1
216fb12b70Safresh1my $killsig = 'HUP';
226fb12b70Safresh1$killsig = 1 unless $Config{sig_name} =~ /\bHUP\b/;
236fb12b70Safresh1
246fb12b70Safresh1SKIP:
256fb12b70Safresh1{
266fb12b70Safresh1    skip("Not relevant to $^O", 3)
276fb12b70Safresh1      if $^O eq "MSWin32" || $^O eq "VMS";
286fb12b70Safresh1    skip("only matters for waitpid or wait4", 3)
296fb12b70Safresh1      unless $Config{d_waitpid} || $Config{d_wait4};
306fb12b70Safresh1    # [perl #119893]
316fb12b70Safresh1    # close on the original of a popen handle dupped to a standard handle
326fb12b70Safresh1    # would wait4pid(0, ...)
336fb12b70Safresh1    open my $savein, "<&", \*STDIN;
346fb12b70Safresh1    my $pid = open my $fh1, "-|", $perl, "-e", "sleep 50";
356fb12b70Safresh1    ok($pid, "open a pipe");
366fb12b70Safresh1    # at this point PL_fdpids[fileno($fh1)] is the pid of the new process
376fb12b70Safresh1    ok(open(STDIN, "<&=", $fh1), "dup the pipe");
386fb12b70Safresh1    # now PL_fdpids[fileno($fh1)] is zero and PL_fdpids[0] is
396fb12b70Safresh1    # the pid of the process created above, previously this would block
406fb12b70Safresh1    # internally on waitpid(0, ...)
416fb12b70Safresh1    ok(close($fh1), "close the original");
426fb12b70Safresh1    kill $killsig, $pid;
436fb12b70Safresh1    open STDIN, "<&", $savein;
446fb12b70Safresh1}
45