Stop closing Win32 tee pipes with CloseHandle
This commit uses regular perl `close` to avoid a double close problem.
Previously, Capture::Tiny closed the OS handle with `CloseHandle` but
then the perl auto-close tried to close again and triggered a bad
file descriptor warning.
Fixes issue #26.
David Golden
9 years ago
0 | 0 |
Revision history for Capture-Tiny
|
1 | 1 |
|
2 | 2 |
{{$NEXT}}
|
|
3 |
|
|
4 |
Fixed:
|
|
5 |
|
|
6 |
- Fix double filehandle close error with tee on Windows
|
|
7 |
(which started warning during the perl 5.21.x series,
|
|
8 |
causing tests to fail)
|
3 | 9 |
|
4 | 10 |
0.28 2015-02-11 06:39:51-05:00 America/New_York
|
5 | 11 |
|
209 | 209 |
# execute @cmd as a separate process
|
210 | 210 |
if ( $IS_WIN32 ) {
|
211 | 211 |
local $@;
|
212 | |
eval "use Win32API::File qw/CloseHandle GetOsFHandle SetHandleInformation fileLastError HANDLE_FLAG_INHERIT INVALID_HANDLE_VALUE/ ";
|
|
212 |
eval "use Win32API::File qw/GetOsFHandle SetHandleInformation fileLastError HANDLE_FLAG_INHERIT INVALID_HANDLE_VALUE/ ";
|
213 | 213 |
# _debug( "# Win32API::File loaded\n") unless $@;
|
214 | 214 |
my $os_fhandle = GetOsFHandle( $stash->{tee}{$which} );
|
215 | 215 |
# _debug( "# Couldn't get OS handle: " . fileLastError() . "\n") if ! defined $os_fhandle || $os_fhandle == INVALID_HANDLE_VALUE();
|
|
263 | 263 |
sub _kill_tees {
|
264 | 264 |
my ($stash) = @_;
|
265 | 265 |
if ( $IS_WIN32 ) {
|
266 | |
# _debug( "# closing handles with CloseHandle\n");
|
267 | |
CloseHandle( GetOsFHandle($_) ) for values %{ $stash->{tee} };
|
|
266 |
# _debug( "# closing handles\n");
|
|
267 |
close($_) for values %{ $stash->{tee} };
|
268 | 268 |
# _debug( "# waiting for subprocesses to finish\n");
|
269 | 269 |
my $start = time;
|
270 | 270 |
1 until wait == -1 || (time - $start > 30);
|