vncserver: replace -kill sleep with a faster busyloop

This commit is contained in:
Dmitry Maksyoma 2021-08-12 23:33:57 +12:00
parent 8ca36e349e
commit 0ca46888a0

View File

@ -375,7 +375,9 @@ sub Kill
if (kill 0, $pid) { if (kill 0, $pid) {
system("kill $pid"); system("kill $pid");
sleep(1); &WaitForTimeLimitOrSubReturningTrue(1, sub {
!IsProcessRunning($pid)
});
if (kill 0, $pid) { if (kill 0, $pid) {
print "Xvnc seems to be deadlocked. Kill the process manually and then re-run\n"; print "Xvnc seems to be deadlocked. Kill the process manually and then re-run\n";
print " ".$0." -kill ".$opt{'-kill'}."\n"; print " ".$0." -kill ".$opt{'-kill'}."\n";
@ -1069,3 +1071,20 @@ sub StartXvncOrExit {
&WarnUserXvncNotStartedAndExit(); &WarnUserXvncNotStartedAndExit();
} }
} }
sub WaitForTimeLimitOrSubReturningTrue {
my ($timeLimit, $sub) = @_;
my $sleepSlice = 0.05;
my $sleptFor = 0;
until (&$sub() || $sleptFor >= $timeLimit) {
sleep($sleepSlice);
$sleptFor += $sleepSlice;
}
}
sub IsProcessRunning {
my $pid = shift;
kill 0, $pid;
}