[pve-devel] [PATCH common] don't double-exit

Stoiko Ivanov s.ivanov at proxmox.com
Wed Aug 22 16:14:01 CEST 2018


On Wed, 22 Aug 2018 16:04:39 +0200
Wolfgang Bumiller <w.bumiller at proxmox.com> wrote:

> if _exit() doesn't work, why would kill() be more
> reliable...
if I understood perldoc -f kill correctly a negative signal is
interpreted as sending the positive signal to the processgroup of the
pid - however I didn't examine the code in this case.

> 
> Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
> ---
>  src/PVE/RESTEnvironment.pm | 7 +++----
>  src/PVE/Tools.pm           | 1 -
>  2 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm
> index 338a534..f9b3732 100644
> --- a/src/PVE/RESTEnvironment.pm
> +++ b/src/PVE/RESTEnvironment.pm
> @@ -561,7 +561,6 @@ sub fork_worker {
>  	    POSIX::write($psync[1], $msg, length ($msg));
>  	    POSIX::close($psync[1]);
>  	    POSIX::_exit(1);
> -	    kill(-9, $$);
>  	}
>  
>  	# sync with parent (signal that we are ready)
> @@ -580,21 +579,21 @@ sub fork_worker {
>  	    &$function($upid);
>  	};
>  	my $err = $@;
> +	my $ret = 0;
>  	if ($err) {
> +	    $ret = -1;
>  	    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);
>  	} else {
>  	    my $msg = "TASK OK\n";
>  	    POSIX::write($resfh, $msg, length($msg));
>  	    POSIX::close($resfh) if $sync;
> -	    POSIX::_exit(0);
>  	}
> -	kill(-9, $$);
> +	POSIX::_exit($ret);
>      }
>  
>      # parent
> diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
> index 06da78b..d9115c3 100644
> --- a/src/PVE/Tools.pm
> +++ b/src/PVE/Tools.pm
> @@ -444,7 +444,6 @@ sub run_command {
>  	if ($orig_pid != $$) {
>  	    warn "ERROR: $err";
>  	    POSIX::_exit (1);
> -	    kill ('KILL', $$);
>  	}
>  
>  	die $err if $err;





More information about the pve-devel mailing list