exit when child finish

Some programs daemonize without closing stdout/stderr, but we do not want to wait until all childs closed stdout/stderr.
This commit is contained in:
Dietmar Maurer 2011-10-22 10:43:17 +02:00
parent 362fe4c650
commit b28410fcf4

View File

@ -3,7 +3,9 @@ package PVE::RPCEnvironment;
use strict; use strict;
use warnings; use warnings;
use POSIX qw(:sys_wait_h EINTR); use POSIX qw(:sys_wait_h EINTR);
use IO::Handle;
use IO::File; use IO::File;
use IO::Select;
use Fcntl qw(:flock); use Fcntl qw(:flock);
use PVE::SafeSyslog; use PVE::SafeSyslog;
use PVE::Tools; use PVE::Tools;
@ -667,10 +669,17 @@ sub fork_worker {
}; };
local $SIG{PIPE} = sub { die "broken pipe\n"; }; local $SIG{PIPE} = sub { die "broken pipe\n"; };
while (1) { my $select = new IO::Select;
if (!defined($count = POSIX::read($psync[0], $readbuf, 4096))) { my $fh = IO::Handle->new_from_fd($psync[0], 'r');
next if $! == EINTR; $select->add($fh);
last;
while ($select->count) {
my @handles = $select->can_read(1);
if (scalar(@handles)) {
my $count = sysread ($handles[0], $readbuf, 4096);
if (!defined ($count)) {
my $err = $!;
die "sync pipe read error: $err\n";
} }
last if $count == 0; # eof last if $count == 0; # eof
@ -690,6 +699,10 @@ sub fork_worker {
$outfh->flush(); $outfh->flush();
} }
} }
} else {
# some commands daemonize without closing stdout
last if !PVE::ProcFSTools::check_process_running($cpid);
}
} }
}; };
my $err = $@; my $err = $@;