]> git.proxmox.com Git - pve-common.git/commitdiff
correctly call errfunc inside run_command
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 2 Dec 2011 05:28:43 +0000 (06:28 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 2 Dec 2011 09:28:44 +0000 (10:28 +0100)
Makefile
data/PVE/Tools.pm
debian/changelog

index 363fdaa184564465c2610169adf4aa6d15a72783..1b5abadc97c5205602904c0e86bc09cf1feb926a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 RELEASE=2.0
 
 VERSION=1.0
 RELEASE=2.0
 
 VERSION=1.0
-PKGREL=8
+PKGREL=9
 
 PACKAGE=libpve-common-perl
 
 
 PACKAGE=libpve-common-perl
 
index 1a8d33c3b8102150667bf886071befd57be19c30..33f0de1a217715395c521caf77b218673d9fe51e 100644 (file)
@@ -178,12 +178,13 @@ sub run_command {
     my $oldtimeout;
     my $pid;
 
     my $oldtimeout;
     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) {
            if ($p eq 'timeout') {
 
        foreach my $p (keys %param) {
            if ($p eq 'timeout') {
@@ -192,10 +193,6 @@ sub run_command {
                umask($param{$p});
            } elsif ($p eq 'errmsg') {
                $errmsg = $param{$p};
                umask($param{$p});
            } elsif ($p eq 'errmsg') {
                $errmsg = $param{$p};
-               $errfunc = sub {
-                   print STDERR "$laststderr\n" if $laststderr;
-                   $laststderr = shift; 
-               };
            } elsif ($p eq 'input') {
                $input = $param{$p};
            } elsif ($p eq 'output') {
            } elsif ($p eq 'input') {
                $input = $param{$p};
            } 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 $writer = $input && $input =~ m/^<&/ ? $input : IO::File->new();
        my $error  = IO::File->new();
        my $reader = $output && $output =~ m/^>&/ ? $output : IO::File->new();
        my $writer = $input && $input =~ m/^<&/ ? $input : 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);
 
index 5e802bfaefaf1246e3ca5f91018a1a827dbc9b66..9e66272ad6bf770536a724567cea336bddf5e1ea 100644 (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
 
   * make cli argument parser more flexible
 libpve-common-perl (1.0-8) unstable; urgency=low
 
   * make cli argument parser more flexible