use strict;
use warnings;
-use POSIX qw(:sys_wait_h EINTR);
-use IO::Handle;
+
+use Fcntl qw(:flock);
use IO::File;
+use IO::Handle;
use IO::Select;
-use Fcntl qw(:flock);
+use POSIX qw(:sys_wait_h EINTR);
+
use PVE::Exception qw(raise raise_perm_exc);
-use PVE::SafeSyslog;
-use PVE::Tools;
use PVE::INotify;
use PVE::ProcFSTools;
-
+use PVE::SafeSyslog;
+use PVE::Tools;
my $rest_env;
# environment types
# cli ... command started fron command line
- # pub ... access from public server (apache)
+ # pub ... access from public server (pveproxy)
# priv ... access from private server (pvedaemon)
- # ha ... access from HA resource manager agent (rgmanager)
+ # ha ... access from HA resource manager agent (pve-ha-manager)
- my $self = { type => $type };
+ my $self = {
+ type => $type,
+ warning_count => 0,
+ };
bless $self, $class;
die "user name not set\n";
}
+sub set_u2f_challenge {
+ my ($self, $challenge) = @_;
+
+ $self->{u2f_challenge} = $challenge;
+}
+
+sub get_u2f_challenge {
+ my ($self, $noerr) = @_;
+
+ return $self->{u2f_challenge} if defined($self->{u2f_challenge}) || $noerr;
+
+ die "no active u2f challenge\n";
+}
+
+sub set_request_host {
+ my ($self, $host) = @_;
+
+ $self->{request_host} = $host;
+}
+
+sub get_request_host {
+ my ($self, $noerr) = @_;
+
+ return $self->{request_host} if defined($self->{request_host}) || $noerr;
+
+ die "no hostname available in current environment\n";
+}
+
sub is_worker {
my ($class) = @_;
}
}
- # get status (error or OK)
POSIX::read($ctrlfd, $readbuf, 4096);
if ($readbuf =~ m/^TASK OK\n?$/) {
# skip printing to stdout
} elsif ($readbuf =~ m/^TASK ERROR: (.*)\n?$/) {
print STDERR "$1\n";
print $taskfh "\n$readbuf"; # ensure start on new line for webUI
+ } elsif ($readbuf =~ m/^TASK WARNINGS: (\d+)\n?$/) {
+ print STDERR "Task finished with $1 warning(s)!\n";
+ print $taskfh "\n$readbuf"; # ensure start on new line for webUI
} else {
die "got unexpected control message: $readbuf\n";
}
syslog('err', $err);
$msg = "TASK ERROR: $err\n";
$exitcode = -1;
+ } elsif (my $warnings = $self->{warning_count}) {
+ $msg = "TASK WARNINGS: $warnings\n";
+ $exitcode = 0;
} else {
$msg = "TASK OK\n";
$exitcode = 0;
}
}
POSIX::_exit($exitcode);
+ kill(-9, $$); # not really needed, just to be sure
}
# parent
return wantarray ? ($upid, $res) : $upid;
}
+sub warn {
+ my ($self, $message) = @_;
+
+ chomp($message);
+
+ print STDERR "WARN: $message\n";
+
+ $self->{warning_count}++;
+}
+
# Abstract function
sub log_cluster_msg {