3 # $RCSfile: pipe.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:31 $
8 require Config; import Config;
9 unless ($Config{'d_fork'}) {
18 open(PIPE, "|-") || (exec 'tr', 'YX', 'ko');
23 if (open(PIPE, "-|")) {
28 close PIPE; # avoid zombies which disrupt test 12
31 print STDOUT "not ok 3\n";
32 exec 'echo', 'not ok 4';
35 pipe(READER,WRITER) || die "Can't open pipe";
44 close READER; # avoid zombies which disrupt test 12
47 die "Couldn't fork" unless defined $pid;
49 print WRITER "not ok 5\n";
50 open(STDOUT,">&WRITER") || die "Can't dup WRITER to STDOUT";
52 exec 'echo', 'not ok 6';
56 pipe(READER,WRITER) || die "Can't open pipe";
59 $SIG{'PIPE'} = 'broken_pipe';
62 $SIG{'PIPE'} = 'IGNORE'; # loop preventer
66 print WRITER "not ok 7\n";
71 # VMS doesn't like spawning subprocesses that are still connected to
72 # STDOUT. Someone should modify tests #9 to #12 to work with VMS.
82 if ($Config{d_sfio} || $^O eq machten || $^O eq beos) {
83 # Sfio doesn't report failure when closing a broken pipe
84 # that has pending output. Go figure. MachTen doesn't either,
85 # but won't write to broken pipes, so nothing's pending at close.
86 # BeOS will not write to broken pipes, either.
90 local $SIG{PIPE} = 'IGNORE';
91 open NIL, '|true' or die "open failed: $!";
93 print NIL 'foo' or die "print failed: $!";
102 # check that errno gets forced to 0 if the piped program exited non-zero
103 open NIL, '|exit 23;' or die "fork failed: $!";
106 print "not ok 10\n# successful close\n";
109 print "not ok 10\n# errno $!\n";
112 print "not ok 10\n# status 0\n";
118 # check that status for the correct process is collected
119 wait; # Collect from $pid
120 my $zombie = fork or exit 37;
121 my $pipe = open *FH, "sleep 2;exit 13|" or die "Open: $!\n";
122 $SIG{ALRM} = sub { return };
124 my $close = close FH;
125 if ($? == 13*256 && ! length $close && ! $!) {
128 print "not ok 11\n# close $close\$?=$? \$!=", $!+0, ":$!\n";
131 if ($? == 37*256 && $wait == $zombie && ! $!) {
134 print "not ok 12\n# pid=$wait first=$pid pipe=$pipe zombie=$zombie me=$$ \$?=$? \$!=", $!+0, ":$!\n";