[pve-devel] [PATCH common v2] run_fork_with_timeout: allow returning undef

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Sep 12 10:28:23 CEST 2017


allow also to return undef without any warnings to our caller.
This avoids a "use of unitialised variable ..." warning

Add a single char at the start which allows us to differ between
returning undef and returning all other values.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

changes v1 -> v2:
 * methods should be allowed to return undef when run with
   run_fork_with_timeout so fix the problem at the source

 src/PVE/Tools.pm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 81662b1..3c73782 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -926,7 +926,8 @@ sub run_fork_with_timeout {
 
 	eval {
 	    $res = $sub->();
-	    print {$pipe_out} "$res";
+	    # allows to pass undef to parent
+	    print {$pipe_out} defined($res) ? "1$res" : "0";
 	    $pipe_out->flush();
 	};
 	if (my $err = $@) {
@@ -943,6 +944,7 @@ sub run_fork_with_timeout {
     my $readvalues = sub {
 	local $/ = undef;
 	$res = <$pipe_out>;
+	$res = undef if !substr ($res, 0, 1, '');
 	$error = <$pipe_err>;
     };
     eval {
-- 
2.11.0





More information about the pve-devel mailing list