vncserver: slice start time from 3 seconds to ~170ms

This commit is contained in:
Dmitry Maksyoma 2021-08-10 22:18:31 +12:00
parent 2b4f01f5ae
commit cc90fe9ff6

View File

@ -25,6 +25,8 @@
# vncserver - wrapper script to start an X VNC server. # vncserver - wrapper script to start an X VNC server.
# #
use Time::HiRes qw (sleep);
&DetectEnvironment(); &DetectEnvironment();
&SetGlobalVariables(); &SetGlobalVariables();
@ -41,7 +43,6 @@ $pidFile = "$vncUserDir/$host:$displayNumber.pid";
$kasmAuthEnabled = 1; $kasmAuthEnabled = 1;
&DisableVncAuth(); &DisableVncAuth();
if ($kasmAuthEnabled) { if ($kasmAuthEnabled) {
&EnsureAtLeastOneKasmUserExists(); &EnsureAtLeastOneKasmUserExists();
} }
@ -54,11 +55,11 @@ $cmd = &ConstructXvncCmd();
&DeleteLogLeftFromPreviousXvncRun(); &DeleteLogLeftFromPreviousXvncRun();
&StartXvncAndRecordPID(); &StartXvncAndRecordPID();
&WaitForXvncToStart(); &WaitForXvncToRespond();
if (!&IsXvncRunning() && !&UsingSafeFontPath()) { if (!&IsXvncRunning() && !&UsingSafeFontPath()) {
&StartXvncWithSafeFontPath(); &StartXvncWithSafeFontPath();
&WaitForXvncToStart(); &WaitForXvncToRespond();
} }
unless (&IsXvncRunning()) { unless (&IsXvncRunning()) {
@ -956,8 +957,20 @@ sub WarnUserXvncNotStartedAndExit {
die "\n"; die "\n";
} }
sub WaitForXvncToStart { sub WaitForXvncToRespond {
sleep(3); 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 { sub UsingSafeFontPath {