From: Stoiko Ivanov Date: Fri, 29 Jun 2018 09:21:18 +0000 (+0200) Subject: fix #1819: fork_worker: ensure sync'ed workers control terminal X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=e97f807c388c10250f442b1f16c5315df2ffc2af;ds=sidebyside fix #1819: fork_worker: ensure sync'ed workers control terminal 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. Further, ignore SIGTTOU in child process (otherwise it gets stopped upon tcsetpgrp) Signed-off-by: Stoiko Ivanov Signed-off-by: Thomas Lamprecht --- diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm index 32ffdd1..3155aac 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 && -t STDIN) { + 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;