From: Mark Mielke Date: Wed, 29 Jul 2020 04:21:19 +0000 (-0400) Subject: vncserver: Display check should be re-factored for Perl 5 X-Git-Tag: v1.10.90~5^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b0071a6ff2d828060e90198ebdb0fe2eeb5690af;p=tigervnc.git vncserver: Display check should be re-factored for Perl 5 The display check and related setup code was complex due to compatibility with Perl 4. This included different ways of obtaining system constants and building system data structures. Perl 5 provides direct constants and utility methods to abstract this out of the vncserver code. --- diff --git a/unix/vncserver/vncserver.in b/unix/vncserver/vncserver.in index eee27fff..6229ea38 100755 --- a/unix/vncserver/vncserver.in +++ b/unix/vncserver/vncserver.in @@ -361,7 +361,9 @@ sub LoadXSession { sub CheckDisplayNumber { - local ($n) = @_; + my($n) = @_; + + use Socket; my $x11_lock_path = "/tmp/.X$n-lock"; @@ -378,9 +380,9 @@ sub CheckDisplayNumber 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))) { + socket(S, PF_INET, SOCK_STREAM, 0) || die "$prog: socket failed: $!\n"; + setsockopt(S, SOL_SOCKET, SO_REUSEADDR, 1); + if (!bind(S, sockaddr_in($port, INADDR_ANY))) { # Port is in use. close(S); return 0; @@ -444,36 +446,4 @@ sub SanityCheck if (!defined($ENV{HOME})) { die "$prog: The HOME environment variable is not set.\n"; } - - # - # Find socket constants. 'use Socket' is a perl5-ism, so we wrap it in an - # eval, and if it fails we try 'require "sys/socket.ph"'. If this fails, - # we just guess at the values. If you find perl moaning here, just - # hard-code the values of AF_INET and SOCK_STREAM. You can find these out - # for your platform by looking in /usr/include/sys/socket.h and related - # files. - # - - chop($os = `uname`); - chop($osrev = `uname -r`); - - eval 'use Socket'; - if ($@) { - eval 'require "sys/socket.ph"'; - if ($@) { - if (($os eq "SunOS") && ($osrev !~ /^4/)) { - $AF_INET = 2; - $SOCK_STREAM = 2; - } else { - $AF_INET = 2; - $SOCK_STREAM = 1; - } - } else { - $AF_INET = &AF_INET; - $SOCK_STREAM = &SOCK_STREAM; - } - } else { - $AF_INET = &AF_INET; - $SOCK_STREAM = &SOCK_STREAM; - } }