+
+ # Cleanup the executing child, and kill the timeouter brother on need
+ $cmd{'return'} = 0 unless defined($cmd{'return'});
+ if($cmd{'background'} != 1){
+ waitpid ($cmd{'pid'}, 0);
+ $cmd{'gotret'} = exit_status($?);
+ parse_out(\%cmd);
+ }else{
+ # & commands, which will be handled at the end
+ push @bg_cmds, \%cmd;
+ # no timeout for background commands
+ if($forked){
+ kill(SIGKILL, $forked);
+ $timeout=0;
+ $forked=0;
+ }
+ }
+}
+
+
+sub parse_out {
+ my %cmd = %{$_[0]};
+ my $gotret=$cmd{'gotret'};
+
+ 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);
+ }