5
0
mirror of git://git.proxmox.com/git/pve-common.git synced 2025-01-23 10:03:33 +03:00

allow input/output redirection in run_command

Those changes are needed by new vzdump code.
This commit is contained in:
Dietmar Maurer 2011-10-13 13:55:49 +02:00
parent 710d2994af
commit 1c50a24add

View File

@ -177,11 +177,8 @@ sub run_command {
my $pid;
eval {
my $reader = IO::File->new();
my $writer = IO::File->new();
my $error = IO::File->new();
my $input;
my $output;
my $outfunc;
my $errfunc;
@ -198,6 +195,8 @@ sub run_command {
};
} elsif ($p eq 'input') {
$input = $param{$p};
} elsif ($p eq 'output') {
$output = $param{$p};
} elsif ($p eq 'outfunc') {
$outfunc = $param{$p};
} elsif ($p eq 'errfunc') {
@ -207,6 +206,10 @@ sub run_command {
}
}
my $reader = $output && $output =~ m/^>&/ ? $output : IO::File->new();
my $writer = $input && $input =~ m/^<&/ ? $input : IO::File->new();
my $error = IO::File->new();
# try to avoid locale related issues/warnings
my $lang = $param{lang} || 'C';
@ -312,12 +315,14 @@ sub run_command {
} elsif (my $sig = ($? & 127)) {
die "got signal $sig\n";
} elsif (my $ec = ($? >> 8)) {
if ($errmsg && $laststderr) {
my $lerr = $laststderr;
$laststderr = undef;
die "$lerr\n";
if (!($ec == 24 && ($cmdstr =~ m|^(\S+/)?rsync\s|))) {
if ($errmsg && $laststderr) {
my $lerr = $laststderr;
$laststderr = undef;
die "$lerr\n";
}
die "exit code $ec\n";
}
die "exit code $ec\n";
}
alarm(0);
@ -346,6 +351,8 @@ sub run_command {
die "command '$cmdstr' failed: $err";
}
}
return undef;
}
sub split_list {