[pve-devel] applied: [PATCH common 2/2] fix #1956: return controlling terminal to parent

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Nov 20 10:12:51 CET 2018


On 11/20/18 9:46 AM, Stoiko Ivanov wrote:
> The changes introduced in e97f807c388c10250f442b1f16c5315df2ffc2af let the
> child in fork_worker take the controlling terminal of the session, without
> returning it after finishing.
> This breaks using/reading from the terminal after both parent and child exit
> - e.g. when the code is called from within a shellscript.
> 
> Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
> ---
>  src/PVE/RESTEnvironment.pm | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm
> index c2fea2b..cba062d 100644
> --- a/src/PVE/RESTEnvironment.pm
> +++ b/src/PVE/RESTEnvironment.pm
> @@ -496,10 +496,12 @@ sub fork_worker {
>  	$SIG{CHLD} = $SIG{PIPE} = 'DEFAULT';
>  	$SIG{TTOU} = 'IGNORE';
>  
> +	my $ppgid;
>  	# set session/process group allows to kill the process group
>  	if ($sync && -t STDIN) {
>  	    # some sync'ed workers operate on the tty but setsid sessions lose
>  	    # the tty, so just create a new pgroup and give it the tty
> +	    $ppgid = POSIX::getpgrp() or die "failed to get old pgid: $!\n";
>  	    POSIX::setpgid(0, 0) or die "failed to setpgid: $!\n";
>  	    POSIX::tcsetpgrp(fileno(STDIN), $$) or die "failed to tcsetpgrp: $!\n";
>  	} else {
> @@ -592,7 +594,14 @@ sub fork_worker {
>  	    $exitcode = 0;
>  	}
>  	POSIX::write($resfh, $msg, length($msg));
> -	POSIX::close($resfh) if $sync;
> +
> +	if ($sync) {
> +	    POSIX::close($resfh);
> +	    if ( -t STDIN) {
> +		POSIX::tcsetpgrp(fileno(STDIN), $ppgid) or
> +		    die "failed to tcsetpgrp to parent: $!\n";
> +	    }
> +	}
>  	POSIX::_exit($exitcode);
>      }
>  
> 

applied, thanks!




More information about the pve-devel mailing list