Avoids deadlocking when large data is sent to/from pipes (see tesh test IO-bigsize)
###
# exec the command line
### $line =~ s/\r//g;
###
# exec the command line
### $line =~ s/\r//g;
- $pid = open3(\*CHILD_IN, \*OUT, \*OUT, $cmd{'cmd'} );
+
+ my $e = IO::File->new_tmpfile;
+ $e->autoflush(1);
+ local *E = $e;
+ $pid = open3(\*CHILD_IN, ">&E", ">&E", $cmd{'cmd'} );
# push all provided input to executing child
map { print CHILD_IN "$_\n" } @{$cmd{'in'}};
# push all provided input to executing child
map { print CHILD_IN "$_\n" } @{$cmd{'in'}};
+
+ # Cleanup the executing child, and kill the timeouter brother on need
+ $cmd{'return'} = 0 unless defined($cmd{'return'});
+ my $wantret;
+ if(defined($cmd{'expect'}) and ($cmd{'expect'} ne "")){
+ $wantret = "got signal $cmd{'expect'}";
+ }else{
+ $wantret = "returned code ".(defined($cmd{'return'})? $cmd{'return'} : 0);
+ $exitcode= 41;
+ }
+ my $gotret;
+ waitpid ($pid, 0);
+ $gotret = exit_status($?);
# pop all output from executing child
my @got;
# pop all output from executing child
my @got;
- while(defined(my $got=<OUT>)) {
+ while(defined(my $got=<$e>)) {
$got =~ s/\r//g;
$got =~ s/^( )*//g;
chomp $got;
$got =~ s/\r//g;
$got =~ s/^( )*//g;
chomp $got;
if ($cmd{'sort'}){
sub mysort{
$a cmp $b
if ($cmd{'sort'}){
sub mysort{
$a cmp $b
@{$cmd{'out'}}=sort mysort @{$cmd{'out'}};
}
}
@{$cmd{'out'}}=sort mysort @{$cmd{'out'}};
}
}
-
- # Cleanup the executing child, and kill the timeouter brother on need
- $cmd{'return'} = 0 unless defined($cmd{'return'});
- my $wantret;
- if(defined($cmd{'expect'}) and ($cmd{'expect'} ne "")){
- $wantret = "got signal $cmd{'expect'}";
- }else{
- $wantret = "returned code ".(defined($cmd{'return'})? $cmd{'return'} : 0);
- $exitcode= 41;
- }
- my $gotret;
- waitpid ($pid, 0);
- $gotret = exit_status($?);
#Did we timeout ? If yes, handle it. If not, kill the forked process.
if($timeout==-1 and $gotret eq "got signal SIGKILL"){
#Did we timeout ? If yes, handle it. If not, kill the forked process.
if($timeout==-1 and $gotret eq "got signal SIGKILL"){