]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/RESTEnvironment.pm
fix #1819: fork_worker: ensure sync'ed workers control terminal
[pve-common.git] / src / PVE / RESTEnvironment.pm
index ebf8a2e7aaaadc8e88b50929b8f15e6e00e98dbd..3155aac849de59a2f9f7eb1fb028c97422a66b84 100644 (file)
@@ -270,7 +270,7 @@ sub active_workers  {
        }
 
 
-       @ta = sort { $b->{starttime} cmp $a->{starttime} } @ta;
+       @ta = sort { $b->{starttime} <=> $a->{starttime} } @ta;
 
        my $save = defined($new_upid);
 
@@ -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;