[PATCH xf86-video-qxl 3/4] Reopen the uinput socket after a close.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This should allow multiple vdagents; one can disconnect,
and a different one can connect, and XSpice will continue
to function correctly.

Signed-off-by: Jeremy White <jwhite@xxxxxxxxxxxxxxx>
---
 src/spiceqxl_uinput.c | 31 +++++++++++++++++++++++++------
 src/spiceqxl_uinput.h |  1 +
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/spiceqxl_uinput.c b/src/spiceqxl_uinput.c
index 2d1b149..23f673f 100644
--- a/src/spiceqxl_uinput.c
+++ b/src/spiceqxl_uinput.c
@@ -19,9 +19,10 @@
 #include "spiceqxl_uinput.h"
 
 static const char *uinput_filename;
-static int uinput_fd;
+static int uinput_fd = -1;
 static struct input_event inp_event;
 static int offset;
+static SpiceWatch *uinput_watch;
 
 static void spiceqxl_uinput_read_cb(int fd, int event, void *opaque)
 {
@@ -30,14 +31,20 @@ static void spiceqxl_uinput_read_cb(int fd, int event, void *opaque)
     static int y = -1;
     static int buttons_state = 0;
     int button = -1;
+    qxl_screen_t *qxl = (qxl_screen_t *) opaque;
 
     n = read(uinput_fd, (char *)&inp_event + offset, sizeof(inp_event) - offset);
-    if (n == -1) {
-        if (errno != EAGAIN && errno != EINTR && errno != EWOULDBLOCK) {
-            fprintf(stderr, "spice: uinput read failed: %s\n", strerror(errno));
-        }
+    if (n == -1 &&
+                (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK))
         return;
+
+    if (n <= 0) {
+            fprintf(stderr, "spice: uinput read failed: %d-%s\n", n, n == 0 ? "closed" : strerror(errno));
+            spiceqxl_uinput_term(qxl);
+            spiceqxl_uinput_init(qxl);
+            return;
     }
+
     offset += n;
     if (offset < sizeof(inp_event)) {
         return;
@@ -121,5 +128,17 @@ void spiceqxl_uinput_init(qxl_screen_t *qxl)
                uinput_filename, strerror(errno));
         return;
     }
-    qxl->core->watch_add(uinput_fd, SPICE_WATCH_EVENT_READ, spiceqxl_uinput_read_cb, qxl);
+    uinput_watch = qxl->core->watch_add(uinput_fd, SPICE_WATCH_EVENT_READ, spiceqxl_uinput_read_cb, qxl);
+}
+
+void spiceqxl_uinput_term(qxl_screen_t *qxl)
+{
+    if (uinput_watch)
+        qxl->core->watch_remove(uinput_watch);
+    if (uinput_fd > -1) {
+        close(uinput_fd);
+        unlink(uinput_filename);
+    }
+    uinput_fd = -1;
+    uinput_watch = NULL;
 }
diff --git a/src/spiceqxl_uinput.h b/src/spiceqxl_uinput.h
index 59c704c..5023f69 100644
--- a/src/spiceqxl_uinput.h
+++ b/src/spiceqxl_uinput.h
@@ -4,5 +4,6 @@
 #include "qxl.h"
 
 void spiceqxl_uinput_init(qxl_screen_t *qxl);
+void spiceqxl_uinput_term(qxl_screen_t *qxl);
 
 #endif
-- 
2.1.4

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]