Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[perl #77672] avoid a file handle redirection race
With multiple threads (and Win32 fork() is implemented in terms of threads), Win32's popen() code had a race condition where a different thread could write to the stdout (or read from the stdin) handle setup for a child process. Avoid this by using the Win32 API to supply the I/O handles instead of redirecting them in the current process.
- Loading branch information
Showing
3 changed files
with
74 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!./perl | ||
|
||
BEGIN { | ||
chdir 't' if -d 't'; | ||
@INC = '../lib'; | ||
require "./test.pl"; | ||
require Config; | ||
$Config::Config{d_pseudofork} | ||
or skip_all("no psuedo-fork"); | ||
eval 'use Errno'; | ||
die $@ if $@ and !is_miniperl(); | ||
} | ||
|
||
# [perl #77672] backticks capture text printed to stdout when working | ||
# with multiple threads on windows | ||
watchdog(20); # before the fix this would often lock up | ||
|
||
fresh_perl_like(<<'PERL', qr/\A[z\n]+\z/, {}, "popen and threads"); | ||
if (!defined fork) { die "can't fork" } | ||
for(1..100) { | ||
print "zzzzzzzzzzzzz\n"; | ||
my $r=`perl -v`; | ||
print $r if($r=~/zzzzzzzzzzzzz/); | ||
} | ||
PERL | ||
|
||
done_testing(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters