Skip to content

Commit 977289e

Browse files
nwc10jhi
authored andcommitted
Re: FreeBSD hangs when reading from dup'd STDOUT/ERR w/o perlio
Message-ID: <[email protected]> p4raw-id: //depot/perl@14614
1 parent e731106 commit 977289e

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

t/lib/warnings/pp_hot

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
print STDIN "abc" ;
88

99
Filehandle %s opened only for output [pp_print]
10-
print <STDOUT> ;
10+
$a = <STDOUT> ;
1111

1212
print() on closed filehandle %s [pp_print]
1313
close STDIN ; print STDIN "abc" ;
@@ -62,27 +62,32 @@ print() on unopened filehandle abc at - line 4.
6262
########
6363
# pp_hot.c [pp_print]
6464
use warnings 'io' ;
65-
print STDIN "anc";
66-
print <STDOUT>;
67-
print <STDERR>;
68-
open(FOO, ">&STDOUT") and print <FOO>;
69-
print getc(STDERR);
70-
print getc(FOO);
71-
####################################################################
72-
# The next test is known to fail on some systems (Linux+old glibc, #
73-
# some *BSDs (including Mac OS X and NeXT), among others. #
74-
# We skip it for now (on the grounds that it is "just" a warning). #
75-
####################################################################
76-
#read(FOO,$_,1);
65+
# There is no guarantee that STDOUT is output only, or STDIN input only.
66+
# Certainly on some BSDs (at least FreeBSD, Darwin, BSDi) file descriptors
67+
# 1 and 2 are opened read/write on the tty, and the IO layers may reflect this.
68+
# So we must make our own file handle that is read only.
69+
my $file = "./xcv" ; unlink $file ;
70+
open (FH, ">$file") or die $! ;
71+
close FH or die $! ;
72+
die "There is no file $file" unless -f $file ;
73+
open (FH, "<$file") or die $! ;
74+
print FH "anc" ;
75+
open(FOO, "<&FH") or die $! ;
76+
print FOO "anc" ;
7777
no warnings 'io' ;
78-
print STDIN "anc";
78+
print FH "anc" ;
79+
print FOO "anc" ;
80+
use warnings 'io' ;
81+
print FH "anc" ;
82+
print FOO "anc" ;
83+
close (FH) or die $! ;
84+
close (FOO) or die $! ;
85+
unlink $file ;
7986
EXPECT
80-
Filehandle STDIN opened only for input at - line 3.
81-
Filehandle STDOUT opened only for output at - line 4.
82-
Filehandle STDERR opened only for output at - line 5.
83-
Filehandle FOO opened only for output at - line 6.
84-
Filehandle STDERR opened only for output at - line 7.
85-
Filehandle FOO opened only for output at - line 8.
87+
Filehandle FH opened only for input at - line 12.
88+
Filehandle FOO opened only for input at - line 14.
89+
Filehandle FH opened only for input at - line 19.
90+
Filehandle FOO opened only for input at - line 20.
8691
########
8792
# pp_hot.c [pp_print]
8893
use warnings 'closed' ;
@@ -150,14 +155,26 @@ readline() on closed filehandle STDIN at - line 4.
150155
# pp_hot.c [Perl_do_readline]
151156
use warnings 'io' ;
152157
my $file = "./xcv" ; unlink $file ;
153-
open (FH, ">./xcv") ;
158+
open (FH, ">$file") or die $! ;
154159
my $a = <FH> ;
155160
no warnings 'io' ;
156161
$a = <FH> ;
157-
close (FH) ;
162+
use warnings 'io' ;
163+
open(FOO, ">&FH") or die $! ;
164+
$a = <FOO> ;
165+
no warnings 'io' ;
166+
$a = <FOO> ;
167+
use warnings 'io' ;
168+
$a = <FOO> ;
169+
$a = <FH> ;
170+
close (FH) or die $! ;
171+
close (FOO) or die $! ;
158172
unlink $file ;
159173
EXPECT
160174
Filehandle FH opened only for output at - line 5.
175+
Filehandle FOO opened only for output at - line 10.
176+
Filehandle FOO opened only for output at - line 14.
177+
Filehandle FH opened only for output at - line 15.
161178
########
162179
# pp_hot.c [Perl_sub_crush_depth]
163180
use warnings 'recursion' ;

0 commit comments

Comments
 (0)