X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FRESTEnvironment.pm;h=6a53741242349610902093342c2e3b7e04b5d6a6;hp=91de8750595a75042fe775f9168b5606cf88dbbd;hb=aea06195b731c464b030af8decfb2f01d9697295;hpb=3e2da216007a4f63716c0a1fae179d24816a3752 diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm index 91de875..6a53741 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; @@ -525,7 +532,7 @@ sub fork_worker { if !open(STDIN, "{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;