summaryrefslogtreecommitdiff
path: root/t/win32
diff options
context:
space:
mode:
authorTony Cook <tony@develop-help.com>2014-02-03 14:39:46 +1100
committerTony Cook <tony@develop-help.com>2014-02-03 14:39:46 +1100
commitf06c882585eac59ec68dbf93c87659cb62a24000 (patch)
tree6e53a963e5b33648ceec5ba79e082f24ab33d1c0 /t/win32
parent6034ee449826f1beaab7cee35d86aad5a3b6caef (diff)
downloadperl-f06c882585eac59ec68dbf93c87659cb62a24000.tar.gz
[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.
Diffstat (limited to 't/win32')
-rw-r--r--t/win32/popen.t27
1 files changed, 27 insertions, 0 deletions
diff --git a/t/win32/popen.t b/t/win32/popen.t
new file mode 100644
index 0000000000..eca0a1d67c
--- /dev/null
+++ b/t/win32/popen.t
@@ -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();