die "unknown environment type"
if !$type || $type !~ m/^(cli|pub|priv|ha)$/;
- my $has_anyevent = $type eq 'pub' || $type eq 'priv';
-
$SIG{CHLD} = sub {
- # when we're in an api server, we have to postpone the call to worker_reaper, otherwise it
+ # when we're using AnyEvent, we have to postpone the call to worker_reaper, otherwise it
# might interfere with running api calls
- if ($has_anyevent) {
+ if (defined($AnyEvent::MODEL)) {
AnyEvent::postpone { $worker_reaper->() };
} else {
$worker_reaper->();
};
local $SIG{PIPE} = sub { die "broken pipe\n"; };
- my $select = new IO::Select;
+ my $select = IO::Select->new();
my $fh = IO::Handle->new_from_fd($childfd, 'r');
$select->add($fh);
my @psync = POSIX::pipe();
my @csync = POSIX::pipe();
- my @ctrlfd = POSIX::pipe() if $sync;
+ my @ctrlfd = $sync ? POSIX::pipe() : ();
my $node = $self->{nodename};
close STDIN;
POSIX::close(0) if $fd != 0;
- die "unable to redirect STDIN - $!"
- if !open(STDIN, "</dev/null");
+ open(STDIN, '<', '/dev/null') or die "unable to redirect STDIN - $!";
$outfh = PVE::Tools::upid_open($upid);
$resfh = fileno($outfh);
close STDOUT;
POSIX::close (1) if $fd != 1;
- die "unable to redirect STDOUT - $!"
- if !open(STDOUT, ">&", $outfh);
+ open(STDOUT, ">&", $outfh) or die "unable to redirect STDOUT - $!";
STDOUT->autoflush (1);
close STDERR;
POSIX::close(2) if $fd != 2;
- die "unable to redirect STDERR - $!"
- if !open(STDERR, ">&1");
+ open(STDERR, '>&', '1') or die "unable to redirect STDERR - $!";
STDERR->autoflush(1);
};