vncserver: extract DetectDisplayNumberFromCliArgs()

This commit is contained in:
Dmitry Maksyoma 2021-07-31 01:11:26 +12:00
parent 55525a627b
commit c79da47c21

View File

@ -78,19 +78,7 @@ chop($host = `uname -n`);
# Create the user's vnc directory if necessary.
&CreateDotVncDir();
# Find display number.
if ((@ARGV > 0) && ($ARGV[0] =~ /^:(\d+)$/)) {
$displayNumber = $1;
shift(@ARGV);
if (!&CheckDisplayNumber($displayNumber)) {
die "A VNC server is already running as :$displayNumber\n";
}
} elsif ((@ARGV > 0) && ($ARGV[0] !~ /^-/) && ($ARGV[0] !~ /^\+/)) {
&Usage();
} else {
$displayNumber = &GetLowestAvailableDisplayNumber();
}
&DetectDisplayNumberFromCliArgs();
$vncPort = 5900 + $displayNumber;
if ($opt{'-name'}) {
@ -953,3 +941,20 @@ sub AskUserToChooseDeOrManualXstartup {
system($selectDeCmd) == 0 || die("Failed to execute $selectDeCmd\n");
}
}
sub DetectDisplayNumberFromCliArgs {
if (@ARGV == 0) {
$displayNumber = &GetLowestAvailableDisplayNumber();
return;
}
if ($ARGV[0] =~ /^:(\d+)$/) {
$displayNumber = $1;
shift(@ARGV);
if (!&CheckDisplayNumber($displayNumber)) {
die "A VNC server is already running as :$displayNumber\n";
}
} elsif (($ARGV[0] !~ /^-/) && ($ARGV[0] !~ /^\+/)) {
&Usage();
}
}