[pve-devel] [PATCH common] PVE::RESTEnvironment::fork_worker: put child in foreground

Stoiko Ivanov s.ivanov at proxmox.com
Thu Jun 28 10:57:24 CEST 2018


* Fix #1819
* Use setpgid+tcsetpgrp instead of setsid if $sync (invocation via cli), thus
  keeping /dev/tty - ssh-copy-id/ssh need it to read the password, and putting
  the child in the forground
* Ignore SIGTTOU in child process (otherwise it gets stopped upon tcsetpgrp)

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
Code change fixes the problem described in #1819 for me.
AFAIS the only other place where we have the combination of letting a
fork_worker run synced is with pct push/pull - both were roughly tested and
still work.

Would be grateful for feedback about potential omissions!
src/PVE/RESTEnvironment.pm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm
index 32ffdd1..1dfdaa4 100644
--- a/src/PVE/RESTEnvironment.pm
+++ b/src/PVE/RESTEnvironment.pm
@@ -494,10 +494,16 @@ sub fork_worker {
 	$SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub { die "received interrupt\n"; };
 
 	$SIG{CHLD} = $SIG{PIPE} = 'DEFAULT';
+	$SIG{TTOU} = 'IGNORE';
 
 	# set sess/process group - we want to be able to kill the
 	# whole process group
-	POSIX::setsid();
+	if($sync){
+	    POSIX::setpgid(0,0) or die "failed to setpgid: $!\n";;
+	    POSIX::tcsetpgrp(fileno(STDIN), $$) or die "failed to tcsetpgrp: $!\n";
+	}else{
+	    POSIX::setsid();
+	}
 
 	POSIX::close ($psync[0]);
 	POSIX::close ($ctrlfd[0]) if $sync;
-- 
2.11.0




More information about the pve-devel mailing list