[Spice-devel] [PATCH v2 vdagent-linux] vdagentd: support fake uinput

Hans de Goede hdegoede at redhat.com
Mon Sep 2 11:09:51 PDT 2013


Hi,

On 09/02/2013 05:12 PM, Alon Levy wrote:
> This is used with Xspice. Fake means we open a pipe for write only, and
> don't do any ioctls on it. Specifically it means the axis and buttons
> have to be coordinated for now with Xspice (xf86-video-qxl).
>
> Signed-off-by: Alon Levy <alevy at redhat.com>
> ---
>   src/vdagentd-uinput.c | 11 +++++++++--
>   src/vdagentd-uinput.h |  2 +-
>   src/vdagentd.c        | 14 +++++++++++---
>   3 files changed, 21 insertions(+), 6 deletions(-)
>
> diff --git a/src/vdagentd-uinput.c b/src/vdagentd-uinput.c
> index a415f9c..47e1b45 100644
> --- a/src/vdagentd-uinput.c
> +++ b/src/vdagentd-uinput.c
> @@ -42,12 +42,13 @@ struct vdagentd_uinput {
>       struct vdagentd_guest_xorg_resolution *screen_info;
>       int screen_count;
>       VDAgentMouseState last;
> +    int fake;
>   };
>
>   struct vdagentd_uinput *vdagentd_uinput_create(const char *devname,
>       int width, int height,
>       struct vdagentd_guest_xorg_resolution *screen_info, int screen_count,
> -    int debug)
> +    int debug, int fake)
>   {
>       struct vdagentd_uinput *uinput;
>
> @@ -58,6 +59,7 @@ struct vdagentd_uinput *vdagentd_uinput_create(const char *devname,
>       uinput->devname = devname;
>       uinput->fd      = -1; /* Gets opened by vdagentd_uinput_update_size() */
>       uinput->debug   = debug;
> +    uinput->fake    = fake;
>
>       vdagentd_uinput_update_size(&uinput, width, height,
>                                   screen_info, screen_count);
> @@ -119,13 +121,18 @@ void vdagentd_uinput_update_size(struct vdagentd_uinput **uinputp,
>           return;
>   #endif
>
> -    uinput->fd = open(uinput->devname, O_RDWR);
> +    uinput->fd = open(uinput->devname, uinput->fake ? O_WRONLY : O_RDWR);
>       if (uinput->fd == -1) {
>           syslog(LOG_ERR, "open %s: %m", uinput->devname);
>           vdagentd_uinput_destroy(uinputp);
>           return;
>       }
>
> +    if (uinput->fake) {
> +        /* fake device doesn't understand any ioctls and only writes events */
> +        return;
> +    }
> +
>       rc = write(uinput->fd, &device, sizeof(device));
>       if (rc != sizeof(device)) {
>           syslog(LOG_ERR, "write %s: %m", uinput->devname);
> diff --git a/src/vdagentd-uinput.h b/src/vdagentd-uinput.h
> index 81f0376..b9bd9f1 100644
> --- a/src/vdagentd-uinput.h
> +++ b/src/vdagentd-uinput.h
> @@ -30,7 +30,7 @@ struct vdagentd_uinput;
>   struct vdagentd_uinput *vdagentd_uinput_create(const char *devname,
>       int width, int height,
>       struct vdagentd_guest_xorg_resolution *screen_info, int screen_count,
> -    int debug);
> +    int debug, int fake);
>   void vdagentd_uinput_destroy(struct vdagentd_uinput **uinputp);
>
>   void vdagentd_uinput_do_mouse(struct vdagentd_uinput **uinputp,
> diff --git a/src/vdagentd.c b/src/vdagentd.c
> index 2288671..80726af 100644
> --- a/src/vdagentd.c
> +++ b/src/vdagentd.c
> @@ -58,6 +58,7 @@ static const char *portdev = "/dev/virtio-ports/com.redhat.spice.0";
>   static const char *vdagentd_socket = VDAGENTD_SOCKET;
>   static const char *uinput_device = "/dev/uinput";
>   static int debug = 0;
> +static int uinput_fake = 0;
>   static struct udscs_server *server = NULL;
>   static struct vdagent_virtio_port *virtio_port = NULL;
>   static GHashTable *active_xfers = NULL;
> @@ -317,7 +318,8 @@ int virtio_port_read_complete(
>                                                   agent_data->height,
>                                                   agent_data->screen_info,
>                                                   agent_data->screen_count,
> -                                                debug > 1);
> +                                                debug > 1,
> +                                                uinput_fake);
>               if (!uinput) {
>                   syslog(LOG_CRIT, "Fatal uinput error");
>                   retval = 1;
> @@ -488,7 +490,8 @@ static void check_xorg_resolution(void)
>                                               agent_data->height,
>                                               agent_data->screen_info,
>                                               agent_data->screen_count,
> -                                            debug > 1);
> +                                            debug > 1,
> +                                            uinput_fake);
>           else
>               vdagentd_uinput_update_size(&uinput,
>                                           agent_data->width,
> @@ -867,6 +870,11 @@ int main(int argc, char *argv[])
>           }
>       }
>
> +    if (strncmp(uinput_device, "/dev", 4) != 0) {
> +        fprintf(stderr, "%s: using fake uinput\n", __func__);
> +        uinput_fake = 1;
> +    }
> +

This still needs to be changed to use syslog and to not use __func__

Regards,

Hans


More information about the Spice-devel mailing list