From: Thomas Lamprecht Date: Mon, 4 Dec 2017 10:30:11 +0000 (+0100) Subject: wait_for_vnc_port: allow to enforce IP family X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=590b924e19426c93e0c7f4b969ff80eed66ab29e wait_for_vnc_port: allow to enforce IP family 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 --- diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 2c64f6a..6d579d8 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -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);