xref: /openbsd-src/gnu/usr.bin/perl/t/io/closepid.t (revision 256a93a44f36679bee503f12e49566c2183f6181)
1#!./perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    require "./test.pl";
6    set_up_inc('../lib');
7}
8
9plan tests => 3;
10watchdog(10, $^O eq 'MSWin32' ? "alarm" : '');
11
12use Config;
13$| = 1;
14$SIG{PIPE} = 'IGNORE';
15# work around a shell set to ignore HUP
16$SIG{HUP} = 'DEFAULT';
17$SIG{HUP} = 'IGNORE' if $^O eq 'interix';
18
19my $perl = which_perl();
20
21my $killsig = 'HUP';
22$killsig = 1 unless $Config{sig_name} =~ /\bHUP\b/;
23
24SKIP:
25{
26    skip("Not relevant to $^O", 3)
27      if $^O eq "MSWin32" || $^O eq "VMS";
28    skip("only matters for waitpid or wait4", 3)
29      unless $Config{d_waitpid} || $Config{d_wait4};
30    # [perl #119893]
31    # close on the original of a popen handle dupped to a standard handle
32    # would wait4pid(0, ...)
33    open my $savein, "<&", \*STDIN;
34    my $pid = open my $fh1, "-|", $perl, "-e", "sleep 50";
35    ok($pid, "open a pipe");
36    # at this point PL_fdpids[fileno($fh1)] is the pid of the new process
37    ok(open(STDIN, "<&=", $fh1), "dup the pipe");
38    # now PL_fdpids[fileno($fh1)] is zero and PL_fdpids[0] is
39    # the pid of the process created above, previously this would block
40    # internally on waitpid(0, ...)
41    ok(close($fh1), "close the original");
42    kill $killsig, $pid;
43    open STDIN, "<&", $savein;
44}
45