X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FRESTEnvironment.pm;h=338a534d4abcec6d4eb1292b04f4d3720dc41636;hp=871f12ba9b25549be1abe2a82893545e0ecb591d;hb=c5adc5f9ef0fbdd7487cf38fc640a48454d502b9;hpb=4d9f4d62e416b0080ccd223c553a967e051d4bab diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm index 871f12b..338a534 100644 --- a/src/PVE/RESTEnvironment.pm +++ b/src/PVE/RESTEnvironment.pm @@ -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,17 @@ sub fork_worker { $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub { die "received interrupt\n"; }; $SIG{CHLD} = $SIG{PIPE} = 'DEFAULT'; - - # set sess/process group - we want to be able to kill the - # whole process group - POSIX::setsid(); + $SIG{TTOU} = 'IGNORE'; + + # 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 + 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; @@ -561,15 +568,17 @@ sub fork_worker { POSIX::write($psync[1], $upid, length ($upid)); POSIX::close($psync[1]) if !$sync; # don't need output pipe if async - my $readbuf = ''; - # sync with parent (wait until parent is ready) - POSIX::read($csync[0], $readbuf, 4096); - die "parent setup error\n" if $readbuf ne 'OK'; + eval { + my $readbuf = ''; + # sync with parent (wait until parent is ready) + POSIX::read($csync[0], $readbuf, 4096); + die "parent setup error\n" if $readbuf ne 'OK'; - if ($self->{type} eq 'ha') { - print "task started by HA resource agent\n"; - } - eval { &$function($upid); }; + if ($self->{type} eq 'ha') { + print "task started by HA resource agent\n"; + } + &$function($upid); + }; my $err = $@; if ($err) { chomp $err;