[pve-devel] [PATCH common v2] PVE::RESTEnvironment::fork_worker: put child in foreground
Stoiko Ivanov
s.ivanov at proxmox.com
Fri Jun 29 11:21:18 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>
---
changes from v1:
* check whether STDIN is actually a terminal (otherwise running commands using
fork_worker and redirecting input (e.g. ansible) failed with
Inappropriate ioctl for device
* whitespace fixup
* the comment that the combination of having $sync 1 in few cases was wrong
(all cli invocations involving fork_worker are affected)
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..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;
--
2.11.0
More information about the pve-devel
mailing list