aboutsummaryrefslogtreecommitdiffstats
path: root/unix/vncserver
diff options
context:
space:
mode:
authorMark Mielke <mark.mielke@gmail.com>2020-07-28 23:57:22 -0400
committerMark Mielke <mark.mielke@gmail.com>2020-07-29 00:31:39 -0400
commited62b9f81aae1ba8d266f8d84c292e57e2a2aed5 (patch)
tree35c8cd2c994e62b5efa2251e0bfbc45f49c67368 /unix/vncserver
parent344a9b2da3a37d79cf03183ff7b33ccf267b85c1 (diff)
downloadtigervnc-ed62b9f81aae1ba8d266f8d84c292e57e2a2aed5.tar.gz
tigervnc-ed62b9f81aae1ba8d266f8d84c292e57e2a2aed5.zip
vncserver: Display check should use named variables
Several calculated values such as file paths and port numbers were hard coded within strings or expressions, sometimes multiple times. These values should be extracted into named variables to improve self-documentation and avoid accidental divergence.
Diffstat (limited to 'unix/vncserver')
-rwxr-xr-xunix/vncserver/vncserver.in19
1 files changed, 13 insertions, 6 deletions
diff --git a/unix/vncserver/vncserver.in b/unix/vncserver/vncserver.in
index 27288fd2..670bcf1b 100755
--- a/unix/vncserver/vncserver.in
+++ b/unix/vncserver/vncserver.in
@@ -363,15 +363,20 @@ sub CheckDisplayNumber
{
local ($n) = @_;
- if (-e "/tmp/.X$n-lock") {
- warn "\nWarning: $host:$n is taken because of /tmp/.X$n-lock\n";
+ my $x11_lock_path = "/tmp/.X$n-lock";
+
+ if (-e $x11_lock_path) {
+ warn "\nWarning: $host:$n is taken because of $x11_lock_path\n";
warn "Remove this file if there is no X server $host:$n\n";
return 0;
}
+ my $rfb_port = 5900 + $n;
+ my $x11_port = 6000 + $n;
+
socket(S, $AF_INET, $SOCK_STREAM, 0) || die "$prog: socket failed: $!\n";
eval 'setsockopt(S, &SOL_SOCKET, &SO_REUSEADDR, pack("l", 1))';
- if (!bind(S, pack('S n x12', $AF_INET, 6000 + $n))) {
+ if (!bind(S, pack('S n x12', $AF_INET, $x11_port))) {
close(S);
return 0;
}
@@ -379,14 +384,16 @@ sub CheckDisplayNumber
socket(S, $AF_INET, $SOCK_STREAM, 0) || die "$prog: socket failed: $!\n";
eval 'setsockopt(S, &SOL_SOCKET, &SO_REUSEADDR, pack("l", 1))';
- if (!bind(S, pack('S n x12', $AF_INET, 5900 + $n))) {
+ if (!bind(S, pack('S n x12', $AF_INET, $rfb_port))) {
close(S);
return 0;
}
close(S);
- if (-e "/tmp/.X11-unix/X$n") {
- warn "\nWarning: $host:$n is taken because of /tmp/.X11-unix/X$n\n";
+ my $x11_unix_domain = "/tmp/.X11-unix/X$n";
+
+ if (-e $x11_unix_domain) {
+ warn "\nWarning: $host:$n is taken because of $x11_unix_domain\n";
warn "Remove this file if there is no X server $host:$n\n";
return 0;
}