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

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


Hi,

in a log (rhel) and also in the debug messages, there sometimes appear
messages, that a controller could not connect to a socket file
(int SpiceController::Connect()). This is caused by the fact, that we try
to connect before the socket is present. I added this simple poll loop to
wait for the socket file to be created.

Any opinions?

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

diff --git a/SpiceXPI/src/plugin/controller.cpp b/SpiceXPI/src/plugin/controller.cpp
index b912c27..094f086 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,11 @@ int SpiceController::Connect()
         }
     }
 
+    // wait for a socket file
+    struct stat buf;
+    while (stat(m_name.c_str(), &buf))
+        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