aboutsummaryrefslogtreecommitdiffstats
path: root/unix/vncserver
diff options
context:
space:
mode:
authorMark Mielke <mark.mielke@gmail.com>2020-07-29 00:11:28 -0400
committerMark Mielke <mark.mielke@gmail.com>2020-07-29 00:32:46 -0400
commitcc362f77987bb32ebeffcb4aa2c7e90b7a8f6914 (patch)
tree68b3dcc7212cdedf69f6904fbb5775433b4aa63a /unix/vncserver
parented62b9f81aae1ba8d266f8d84c292e57e2a2aed5 (diff)
downloadtigervnc-cc362f77987bb32ebeffcb4aa2c7e90b7a8f6914.tar.gz
tigervnc-cc362f77987bb32ebeffcb4aa2c7e90b7a8f6914.zip
vncserver: Display check should avoid duplicate code
The display check had duplicate code to first check if the X11 port is not in use, and then check that the RFB port is not in use. Eliminate the duplicate code by using a for-loop.
Diffstat (limited to 'unix/vncserver')
-rwxr-xr-xunix/vncserver/vncserver.in24
1 files changed, 10 insertions, 14 deletions
diff --git a/unix/vncserver/vncserver.in b/unix/vncserver/vncserver.in
index 670bcf1b..1b5717e8 100755
--- a/unix/vncserver/vncserver.in
+++ b/unix/vncserver/vncserver.in
@@ -374,21 +374,17 @@ sub CheckDisplayNumber
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, $x11_port))) {
- close(S);
- return 0;
- }
- close(S);
-
- 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, $rfb_port))) {
- close(S);
- return 0;
+ for my $port ($rfb_port, $x11_port) {
+ # Bind to port to confirm it is not in use.
+ 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, $port))) {
+ # Port is in use.
+ close(S);
+ return 0;
+ }
+ close(S);
}
- close(S);
my $x11_unix_domain = "/tmp/.X11-unix/X$n";