[pve-devel] [PATCH common] run_command: default exit code to -1
Wolfgang Bumiller
w.bumiller at proxmox.com
Wed Apr 5 12:08:22 CEST 2017
There may be other cases we need to adapt. grep revealed at least two in
pve-storage: Storage.pm:1398 and Diskmanage.pm:90. These use noerr=>1
as well. One checks for an undefined return value, and the other
doesn't. (One explicitly checks for a return value > 0 even.)
Not sure which way makes more sense now. But the one in Storage.pm
definitely seems off as it doesn't deal with an undefined $rc at all,
even uses it before using $@ (which is weird there anyhow since it's
combining noerr with eval{} and the subs passed to out/err can't die
AFAICT.)
On Wed, Apr 05, 2017 at 11:35:53AM +0200, Thomas Lamprecht wrote:
> When the child process running the command got an signal or failed
> to execute exitcode was still undefined as we extract it just only
> after the signal/failed to execute check.
> This led to:
> > Use of uninitialized value in numeric ne (!=) at
> > /usr/share/perl5/PVE/API2/Qemu.pm line 1433.
> errors if we used run_commands `noerr` param and checked for the
> commands exit code.
>
> So just default the exit code to -1 for such cases.
>
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> ---
> src/PVE/Tools.pm | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
> index 2cd4733..1f0ec75 100644
> --- a/src/PVE/Tools.pm
> +++ b/src/PVE/Tools.pm
> @@ -341,7 +341,7 @@ sub run_command {
> my $timeout;
> my $oldtimeout;
> my $pid;
> - my $exitcode;
> + my $exitcode = -1;
>
> my $outfunc;
> my $errfunc;
> --
> 2.11.0
More information about the pve-devel
mailing list