From 0ca46888a026922715087f76dfbe1a88d7c3c32a Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Thu, 12 Aug 2021 23:33:57 +1200 Subject: [PATCH] vncserver: replace -kill sleep with a faster busyloop --- unix/vncserver | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/unix/vncserver b/unix/vncserver index 89c48f4..5b85289 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -375,7 +375,9 @@ sub Kill if (kill 0, $pid) { system("kill $pid"); - sleep(1); + &WaitForTimeLimitOrSubReturningTrue(1, sub { + !IsProcessRunning($pid) + }); if (kill 0, $pid) { print "Xvnc seems to be deadlocked. Kill the process manually and then re-run\n"; print " ".$0." -kill ".$opt{'-kill'}."\n"; @@ -1069,3 +1071,20 @@ sub StartXvncOrExit { &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; +}