]> git.proxmox.com Git - pve-common.git/commitdiff
wait_for_vnc_port: allow to enforce IP family
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 4 Dec 2017 10:30:11 +0000 (11:30 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 5 Dec 2017 12:48:49 +0000 (13:48 +0100)
Most times a port was requested for a specified IP family (v4, v6)
only. Thus also ensure that the port from the respective family got
ready, else we may return on a false positive.

As we had no user setting the $timeout param we can add the $family
param as second one, it'll get used more often, so no need to put it
at the back.

As we do nothing if not defined this does not changes the behavior of
our users yet.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/Tools.pm

index 2c64f6ac33206791a5e70b038b49b76fa71b13dd..6d579d8f9cd1234cecafd986e60cf9eaec7a6c5b 100644 (file)
@@ -791,17 +791,20 @@ sub extract_param {
 
 # Note: we use this to wait until vncterm/spiceterm is ready
 sub wait_for_vnc_port {
-    my ($port, $timeout) = @_;
+    my ($port, $family, $timeout) = @_;
 
     $timeout = 5 if !$timeout;
     my $sleeptime = 0;
     my $starttime = [gettimeofday];
     my $elapsed;
 
+    my $cmd = ['/bin/ss', '-Htln', "sport = :$port"];
+    push @$cmd, $family == AF_INET6 ? '-6' : '-4' if defined($family);
+
     my $found;
     while (($elapsed = tv_interval($starttime)) < $timeout) {
        # -Htln = don't print header, tcp, listening sockets only, numeric ports
-       run_command(['/bin/ss', '-Htln', "sport = :$port"], outfunc => sub {
+       run_command($cmd, outfunc => sub {
            my $line = shift;
            if ($line =~ m/^LISTEN\s+\d+\s+\d+\s+\S+:(\d+)\s/) {
                $found = 1 if ($port == $1);