]> source.dussan.org Git - tigervnc.git/commitdiff
vncserver: Display check should confirm lock file is still valid
authorMark Mielke <mark.mielke@gmail.com>
Wed, 29 Jul 2020 04:01:07 +0000 (00:01 -0400)
committerMark Mielke <mark.mielke@gmail.com>
Wed, 29 Jul 2020 04:33:25 +0000 (00:33 -0400)
If the X server is not shut down cleanly, it may leave lock files
around that "vncserver" has previously mis-identified as evidence that
the display number is still in use.

Instead of checking for existence of /tmp/.X<n>-lock, the code will
now extract the PID from the lock file and confirm that a process
exists with the same PID. This will eliminate false positives in the
case that this file references a PID that no longer exists. The Xorg
server does not have a problem with fixing this file when it next
starts up. It is only important to avoid using the port if it is still
in use.

unix/vncserver/vncserver.in

index 1b5717e8984c7db12c9f4dc5967edd0376931928..eee27fff1c06df3e0978f2751f3afa0be2836846 100755 (executable)
@@ -366,9 +366,11 @@ sub CheckDisplayNumber
     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($pid) = `cat "$x11_lock_path"` =~ /^\s*(\d+)\s*$/;
+        if (defined($pid) && kill(0, $pid)) {
+            # Lock is associated with valid PID.
+            return 0;
+        }
     }
 
     my $rfb_port = 5900 + $n;