correctly call errfunc inside run_command

This commit is contained in:
Dietmar Maurer 2011-12-02 06:28:43 +01:00
parent 65e1d3fc9c
commit 4630cb951d
3 changed files with 30 additions and 11 deletions

View File

@ -1,7 +1,7 @@
RELEASE=2.0 RELEASE=2.0
VERSION=1.0 VERSION=1.0
PKGREL=8 PKGREL=9
PACKAGE=libpve-common-perl PACKAGE=libpve-common-perl

View File

@ -178,12 +178,13 @@ sub run_command {
my $oldtimeout; my $oldtimeout;
my $pid; my $pid;
my $outfunc;
my $errfunc;
my $logfunc;
my $input;
my $output;
eval { eval {
my $input;
my $output;
my $outfunc;
my $errfunc;
my $logfunc;
foreach my $p (keys %param) { foreach my $p (keys %param) {
if ($p eq 'timeout') { if ($p eq 'timeout') {
@ -192,10 +193,6 @@ sub run_command {
umask($param{$p}); umask($param{$p});
} elsif ($p eq 'errmsg') { } elsif ($p eq 'errmsg') {
$errmsg = $param{$p}; $errmsg = $param{$p};
$errfunc = sub {
print STDERR "$laststderr\n" if $laststderr;
$laststderr = shift;
};
} elsif ($p eq 'input') { } elsif ($p eq 'input') {
$input = $param{$p}; $input = $param{$p};
} elsif ($p eq 'output') { } elsif ($p eq 'output') {
@ -211,6 +208,20 @@ sub run_command {
} }
} }
if ($errmsg) {
my $origerrfunc = $errfunc;
$errfunc = sub {
if ($laststderr) {
if ($origerrfunc) {
&$origerrfunc("$laststderr\n");
} else {
print STDERR "$laststderr\n" if $laststderr;
}
}
$laststderr = shift;
};
}
my $reader = $output && $output =~ m/^>&/ ? $output : IO::File->new(); my $reader = $output && $output =~ m/^>&/ ? $output : IO::File->new();
my $writer = $input && $input =~ m/^<&/ ? $input : IO::File->new(); my $writer = $input && $input =~ m/^<&/ ? $input : IO::File->new();
my $error = IO::File->new(); my $error = IO::File->new();
@ -353,7 +364,9 @@ sub run_command {
alarm(0); alarm(0);
print STDERR "$laststderr\n" if $laststderr; if ($errmsg && $laststderr) {
&$errfunc(undef); # flush laststderr
}
umask ($old_umask) if defined($old_umask); umask ($old_umask) if defined($old_umask);

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
libpve-common-perl (1.0-9) unstable; urgency=low
* bug fixes for run_command()
-- Proxmox Support Team <support@proxmox.com> Fri, 02 Dec 2011 10:28:27 +0100
libpve-common-perl (1.0-8) unstable; urgency=low libpve-common-perl (1.0-8) unstable; urgency=low
* make cli argument parser more flexible * make cli argument parser more flexible