[pve-devel] [PATCH common 2/2] wait_for_vnc_port: allow to enforce IP family
Thomas Lamprecht
t.lamprecht at proxmox.com
Mon Dec 4 11:30:11 CET 2017
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 at proxmox.com>
---
src/PVE/Tools.pm | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index c2c2f93..23f63bd 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);
--
2.11.0
More information about the pve-devel
mailing list