[Spice-devel] [PATCH spice-xpi] wait for a socket file

Peter Hatina phatina at redhat.com
Tue Aug 7 02:27:05 PDT 2012


Or with some timeout hooked up.

---
 SpiceXPI/src/plugin/controller.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/SpiceXPI/src/plugin/controller.cpp b/SpiceXPI/src/plugin/controller.cpp
index b912c27..323e89a 100644
--- a/SpiceXPI/src/plugin/controller.cpp
+++ b/SpiceXPI/src/plugin/controller.cpp
@@ -51,6 +51,8 @@ extern "C" {
 #  include <unistd.h>
 #  include <fcntl.h>
 #  include <sys/socket.h>
+#  include <sys/types.h>
+#  include <sys/stat.h>
 #  include <sys/un.h>
 }
 
@@ -94,6 +96,12 @@ int SpiceController::Connect()
         }
     }
 
+    // wait for a socket file
+    struct stat buf;
+    int timeout = 30;
+    while (stat(m_name.c_str(), &buf) && timeout--)
+        usleep(100000);
+
     struct sockaddr_un remote;
     remote.sun_family = AF_UNIX;
     if (m_name.length() + 1 > sizeof(remote.sun_path))
-- 
Peter Hatina
EMEA ENG-Base Operating Systems
Red Hat Czech, Brno



More information about the Spice-devel mailing list