]> git.proxmox.com Git - qemu-server.git/commitdiff
fix bug 247: retry qmp open
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 27 Aug 2012 11:41:24 +0000 (13:41 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 27 Aug 2012 11:43:30 +0000 (13:43 +0200)
PVE/QMPClient.pm

index cc975abe693ee868b5abac74940c606a60417ff0..f8b0dc637bbca938a612b569e400573806fd5f26 100755 (executable)
@@ -4,7 +4,10 @@ use strict;
 #use PVE::SafeSyslog;
 use PVE::QemuServer;
 use IO::Multiplex;
+use POSIX qw(EINTR EAGAIN);
 use JSON;
+use Time::HiRes qw(usleep gettimeofday tv_interval);
+
 use Data::Dumper;
 
 # Qemu Monitor Protocol (QMP) client.
@@ -109,8 +112,22 @@ my $open_connection = sub {
 
     my $sname = PVE::QemuServer::qmp_socket($vmid);
 
-    my $fh = IO::Socket::UNIX->new(Peer => $sname, Blocking => 0, Timeout => 1) ||
-       die "unable to connect to VM $vmid socket - $!\n";
+    my $fh;
+    my $starttime = [gettimeofday];
+    my $count = 0;
+    for (;;) {
+       $count++;
+       $fh = IO::Socket::UNIX->new(Peer => $sname, Blocking => 0, Timeout => 1);
+       last if $fh;
+       if ($! != EINTR && $! != EAGAIN) {
+           die "unable to connect to VM $vmid socket - $!\n";
+       }
+       my $elapsed = tv_interval($starttime, [gettimeofday]);
+       if ($elapsed > 1) {
+           die "unable to connect to VM $vmid socket - timeout after $count retries\n";
+       }
+       usleep(100000);
+    }
 
     $self->{fhs}->{$vmid} = $fh;
     $self->{fhs_lookup}->{$fh} = $vmid;