[Spice-devel] [PATCH xf86-video-qxl 3/4] Reopen the uinput socket after a close.
Christophe Fergeau
cfergeau at redhat.com
Fri Oct 16 09:02:50 PDT 2015
On Fri, Oct 02, 2015 at 11:21:02AM -0500, Jeremy White wrote:
> 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 at codeweavers.com>
> ---
> 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;
> }
> +
Nit, I think you could keep it like
if (n == -1) {
if (errno != EAGAIN || ...) {
/* reopen uinput socket */
}
return;
}
I think it would be slightly more readable.
Or did you want to save an indentation level ?
Looks good otherwise.
Christophe
> 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 at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20151016/63ce4d1a/attachment.sig>
More information about the Spice-devel
mailing list