[pve-devel] applied: [PATCH common] tools: unbless errors in run_fork_with_timeout

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Jun 4 12:59:50 CEST 2018


Am 06/04/2018 um 10:39 AM schrieb Wolfgang Bumiller:
> We cannot properly encode blessed objects as json, so
> instead, we should stringify them. This happened for
> instance if a VM's systemd scope wasn't cleaned up as we
> got an error as a Net::DBus::Error object causing a
> "malformed json string" error to appear instead of the
> actual message.
> 
> Additionally, add a 'must_stringify' helper: The above error
> object implements a '""' operator for stringification (as
> all error sshould), but in theory that could die as well, in

I fixed up: s/sshould/should/

> which case we just return a generic error string we'll
> hopefully never see...
> 
> Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
> ---
>   src/PVE/Tools.pm | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
> index 1c5b502..53ac83f 100644
> --- a/src/PVE/Tools.pm
> +++ b/src/PVE/Tools.pm
> @@ -904,6 +904,13 @@ sub next_spice_port {
>       return next_unused_port(61000, 61099, $family, $address);
>   }
>   
> +sub must_stringify {
> +	my ($value) = @_;
> +	eval { $value = "$value" };
> +	return "error turning value into a string: $@" if $@;
> +	return $value;
> +}
> +
>   # sigkill after $timeout  a $sub running in a fork if it can't write a pipe
>   # the $sub has to return a single scalar
>   sub run_fork_with_timeout {
> @@ -935,7 +942,7 @@ sub run_fork_with_timeout {
>   	    $pipe_out->flush();
>   	};
>   	if (my $err = $@) {
> -	    print {$pipe_out} encode_json({ error => $err });
> +	    print {$pipe_out} encode_json({ error => must_stringify($err) });
>   	    $pipe_out->flush();
>   	    POSIX::_exit(1);
>   	}
> 




More information about the pve-devel mailing list