]> git.proxmox.com Git - pve-common.git/commitdiff
fork_worker: refactor child exit
authorStoiko Ivanov <s.ivanov@proxmox.com>
Tue, 20 Nov 2018 08:46:31 +0000 (09:46 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 20 Nov 2018 08:50:38 +0000 (09:50 +0100)
* factor out duplicated code.
* drop final kill(-9, $$), since the POSIX:_exit call does not return
  (see man 2 _exit).

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
src/PVE/RESTEnvironment.pm

index 69af004bab6d27cdf9d2f7c16d904f6646493eae..c2fea2b1f047496d2a83744122fdc9e0b32f1e96 100644 (file)
@@ -579,22 +579,21 @@ sub fork_worker {
            }
            &$function($upid);
        };
+       my ($msg, $exitcode);
        my $err = $@;
        if ($err) {
            chomp $err;
            $err =~ s/\n/ /mg;
            syslog('err', $err);
-           my $msg = "TASK ERROR: $err\n";
-           POSIX::write($resfh, $msg, length($msg));
-           POSIX::close($resfh) if $sync;
-           POSIX::_exit(-1);
+           $msg = "TASK ERROR: $err\n";
+           $exitcode = -1;
        } else {
-           my $msg = "TASK OK\n";
-           POSIX::write($resfh, $msg, length($msg));
-           POSIX::close($resfh) if $sync;
-           POSIX::_exit(0);
+           $msg = "TASK OK\n";
+           $exitcode = 0;
        }
-       kill(-9, $$);
+       POSIX::write($resfh, $msg, length($msg));
+       POSIX::close($resfh) if $sync;
+       POSIX::_exit($exitcode);
     }
 
     # parent