[pve-devel] [PATCH common 2/2] fork_worker: guard more setup code with eval

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Dec 27 11:15:58 CET 2017


As it might die with an error which should end up in the
_exit() code path rather than bailing out into the upper
scope.

Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 src/PVE/RESTEnvironment.pm | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm
index 871f12b..ebf8a2e 100644
--- a/src/PVE/RESTEnvironment.pm
+++ b/src/PVE/RESTEnvironment.pm
@@ -561,15 +561,17 @@ sub fork_worker {
 	POSIX::write($psync[1], $upid, length ($upid));
 	POSIX::close($psync[1]) if !$sync; # don't need output pipe if async
 
-	my $readbuf = '';
-	# sync with parent (wait until parent is ready)
-	POSIX::read($csync[0], $readbuf, 4096);
-	die "parent setup error\n" if $readbuf ne 'OK';
+	eval {
+	    my $readbuf = '';
+	    # sync with parent (wait until parent is ready)
+	    POSIX::read($csync[0], $readbuf, 4096);
+	    die "parent setup error\n" if $readbuf ne 'OK';
 
-	if ($self->{type} eq 'ha') {
-	    print "task started by HA resource agent\n";
-	}
-	eval { &$function($upid); };
+	    if ($self->{type} eq 'ha') {
+		print "task started by HA resource agent\n";
+	    }
+	    &$function($upid);
+	};
 	my $err = $@;
 	if ($err) {
 	    chomp $err;
-- 
2.11.0





More information about the pve-devel mailing list