aboutsummaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authorMark Mielke <mark.mielke@gmail.com>2020-07-28 23:46:02 -0400
committerMark Mielke <mark.mielke@gmail.com>2020-07-29 00:30:48 -0400
commit344a9b2da3a37d79cf03183ff7b33ccf267b85c1 (patch)
treec7a6f58b0ad65930caa06d9b275ba6997a17e863 /unix
parent9842baa3ccf9aa8464f1d4eff840a1930cc18877 (diff)
downloadtigervnc-344a9b2da3a37d79cf03183ff7b33ccf267b85c1.tar.gz
tigervnc-344a9b2da3a37d79cf03183ff7b33ccf267b85c1.zip
vncserver: Display check should check for lock file first
Checking for the existence of `/tmp/.X<n>-lock` is a fast read-only operation, while calls to bind() or connect() are more expensive and may have side effects. Perform the fast operation first.
Diffstat (limited to 'unix')
-rwxr-xr-xunix/vncserver/vncserver.in12
1 files changed, 6 insertions, 6 deletions
diff --git a/unix/vncserver/vncserver.in b/unix/vncserver/vncserver.in
index 2707bace..27288fd2 100755
--- a/unix/vncserver/vncserver.in
+++ b/unix/vncserver/vncserver.in
@@ -363,6 +363,12 @@ sub CheckDisplayNumber
{
local ($n) = @_;
+ if (-e "/tmp/.X$n-lock") {
+ warn "\nWarning: $host:$n is taken because of /tmp/.X$n-lock\n";
+ warn "Remove this file if there is no X server $host:$n\n";
+ return 0;
+ }
+
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))) {
@@ -379,12 +385,6 @@ sub CheckDisplayNumber
}
close(S);
- if (-e "/tmp/.X$n-lock") {
- warn "\nWarning: $host:$n is taken because of /tmp/.X$n-lock\n";
- warn "Remove this file if there is no X server $host:$n\n";
- return 0;
- }
-
if (-e "/tmp/.X11-unix/X$n") {
warn "\nWarning: $host:$n is taken because of /tmp/.X11-unix/X$n\n";
warn "Remove this file if there is no X server $host:$n\n";