mirror of
https://git.proxmox.com/git/pve-access-control
synced 2025-08-07 15:31:13 +00:00
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:
parent
362fe4c650
commit
b28410fcf4
@ -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;
|
||||||
@ -666,29 +668,40 @@ sub fork_worker {
|
|||||||
$int_count++;
|
$int_count++;
|
||||||
};
|
};
|
||||||
local $SIG{PIPE} = sub { die "broken pipe\n"; };
|
local $SIG{PIPE} = sub { die "broken pipe\n"; };
|
||||||
|
|
||||||
while (1) {
|
|
||||||
if (!defined($count = POSIX::read($psync[0], $readbuf, 4096))) {
|
|
||||||
next if $! == EINTR;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
last if $count == 0; # eof
|
|
||||||
|
|
||||||
$outbuf .= $readbuf;
|
my $select = new IO::Select;
|
||||||
while ($outbuf =~ s/^(([^\010\r\n]*)(\r|\n|(\010)+|\r\n))//s) {
|
my $fh = IO::Handle->new_from_fd($psync[0], 'r');
|
||||||
my $line = $1;
|
$select->add($fh);
|
||||||
my $data = $2;
|
|
||||||
if ($data =~ m/^TASK OK$/) {
|
while ($select->count) {
|
||||||
# skip
|
my @handles = $select->can_read(1);
|
||||||
} elsif ($data =~ m/^TASK ERROR: (.+)$/) {
|
if (scalar(@handles)) {
|
||||||
print STDERR "$1\n";
|
my $count = sysread ($handles[0], $readbuf, 4096);
|
||||||
} else {
|
if (!defined ($count)) {
|
||||||
print $line;
|
my $err = $!;
|
||||||
|
die "sync pipe read error: $err\n";
|
||||||
}
|
}
|
||||||
if ($outfh) {
|
last if $count == 0; # eof
|
||||||
print $outfh $line;
|
|
||||||
$outfh->flush();
|
$outbuf .= $readbuf;
|
||||||
|
while ($outbuf =~ s/^(([^\010\r\n]*)(\r|\n|(\010)+|\r\n))//s) {
|
||||||
|
my $line = $1;
|
||||||
|
my $data = $2;
|
||||||
|
if ($data =~ m/^TASK OK$/) {
|
||||||
|
# skip
|
||||||
|
} elsif ($data =~ m/^TASK ERROR: (.+)$/) {
|
||||||
|
print STDERR "$1\n";
|
||||||
|
} else {
|
||||||
|
print $line;
|
||||||
|
}
|
||||||
|
if ($outfh) {
|
||||||
|
print $outfh $line;
|
||||||
|
$outfh->flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
# some commands daemonize without closing stdout
|
||||||
|
last if !PVE::ProcFSTools::check_process_running($cpid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user