From cc90fe9ff6ebffe06fe05b4bbcc60a67d315e320 Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Tue, 10 Aug 2021 22:18:31 +1200 Subject: [PATCH] vncserver: slice start time from 3 seconds to ~170ms --- unix/vncserver | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/unix/vncserver b/unix/vncserver index f8ca7d2..d3f63a7 100755 --- a/unix/vncserver +++ b/unix/vncserver @@ -25,6 +25,8 @@ # vncserver - wrapper script to start an X VNC server. # +use Time::HiRes qw (sleep); + &DetectEnvironment(); &SetGlobalVariables(); @@ -41,7 +43,6 @@ $pidFile = "$vncUserDir/$host:$displayNumber.pid"; $kasmAuthEnabled = 1; &DisableVncAuth(); - if ($kasmAuthEnabled) { &EnsureAtLeastOneKasmUserExists(); } @@ -54,11 +55,11 @@ $cmd = &ConstructXvncCmd(); &DeleteLogLeftFromPreviousXvncRun(); &StartXvncAndRecordPID(); -&WaitForXvncToStart(); +&WaitForXvncToRespond(); if (!&IsXvncRunning() && !&UsingSafeFontPath()) { &StartXvncWithSafeFontPath(); - &WaitForXvncToStart(); + &WaitForXvncToRespond(); } unless (&IsXvncRunning()) { @@ -956,8 +957,20 @@ sub WarnUserXvncNotStartedAndExit { die "\n"; } -sub WaitForXvncToStart { - sleep(3); +sub WaitForXvncToRespond { + my $sleepSlice = 0.1; + my $sleptFor = 0; + my $sleepLimit = 3; + + until (&IsXvncResponding() || $sleptFor >= $sleepLimit) { + sleep($sleepSlice); + $sleptFor += $sleepSlice; + } +} + +sub IsXvncResponding { + `xdpyinfo -display :$displayNumber >/dev/null 2>&1`; + $? == 0; } sub UsingSafeFontPath {