[RFC,spice-vdagent,17/18] vdagentd: move code to do_guest_xorg_resolution()

Submitted by Jakub Janku on Aug. 14, 2018, 6:53 p.m.

Details

Message ID 20180814185352.6080-18-jjanku@redhat.com
State New
Headers show
Series "GLib integration" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Jakub Janku Aug. 14, 2018, 6:53 p.m.
Move code handling VDAGENTD_GUEST_XORG_RESOLUTION
from agent_read_complete() to a separate function
to make the switch statement less cluttered.

Remove unnecessary res variable.
---
 src/vdagentd/vdagentd.c | 61 +++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 30 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
index b8f617c..e975abd 100644
--- a/src/vdagentd/vdagentd.c
+++ b/src/vdagentd/vdagentd.c
@@ -887,43 +887,44 @@  static void agent_disconnect(struct udscs_connection *conn)
     g_free(agent_data);
 }
 
-static void agent_read_complete(struct udscs_connection **connp,
-    struct udscs_message_header *header, uint8_t *data)
+static void do_guest_xorg_resolution(struct udscs_connection    **connp,
+                                     struct udscs_message_header *header,
+                                     guint8                      *data)
 {
     struct agent_data *agent_data = udscs_get_user_data(*connp);
+    guint n = header->size / sizeof(struct vdagentd_guest_xorg_resolution);
 
-    switch (header->type) {
-    case VDAGENTD_GUEST_XORG_RESOLUTION: {
-        struct vdagentd_guest_xorg_resolution *res;
-        int n = header->size / sizeof(*res);
-
-        /* Detect older version session agent, but don't disconnect, as
-           that stops it from getting the VDAGENTD_VERSION message, and then
-           it will never re-exec the new version... */
-        if (header->arg1 == 0 && header->arg2 == 0) {
-            syslog(LOG_INFO, "got old session agent xorg resolution message, "
-                             "ignoring");
-            return;
-        }
+    /* Detect older version session agent, but don't disconnect, as
+     * that stops it from getting the VDAGENTD_VERSION message, and then
+     * it will never re-exec the new version... */
+    if (header->arg1 == 0 && header->arg2 == 0) {
+        syslog(LOG_INFO, "got old session agent xorg resolution message, ignoring");
+        return;
+    }
 
-        if (header->size != n * sizeof(*res)) {
-            syslog(LOG_ERR, "guest xorg resolution message has wrong size, "
-                            "disconnecting agent");
-            udscs_destroy_connection(connp);
-            return;
-        }
+    if (header->size != n * sizeof(struct vdagentd_guest_xorg_resolution)) {
+        syslog(LOG_ERR, "guest xorg resolution message has wrong size, "
+                        "disconnecting agent");
+        udscs_destroy_connection(connp);
+        return;
+    }
+
+    g_free(agent_data->screen_info);
+    agent_data->screen_info = g_memdup(data, header->size);
+    agent_data->width  = header->arg1;
+    agent_data->height = header->arg2;
+    agent_data->screen_count = n;
 
-        g_free(agent_data->screen_info);
-        res = g_malloc(n * sizeof(*res));
-        memcpy(res, data, n * sizeof(*res));
-        agent_data->width  = header->arg1;
-        agent_data->height = header->arg2;
-        agent_data->screen_info  = res;
-        agent_data->screen_count = n;
+    check_xorg_resolution();
+}
 
-        check_xorg_resolution();
+static void agent_read_complete(struct udscs_connection **connp,
+    struct udscs_message_header *header, uint8_t *data)
+{
+    switch (header->type) {
+    case VDAGENTD_GUEST_XORG_RESOLUTION:
+        do_guest_xorg_resolution(connp, header, data);
         break;
-    }
     case VDAGENTD_CLIPBOARD_GRAB:
     case VDAGENTD_CLIPBOARD_REQUEST:
     case VDAGENTD_CLIPBOARD_DATA:

Comments

Hi,

On Tue, Aug 14, 2018 at 08:53:51PM +0200, Jakub Janků wrote:
> Move code handling VDAGENTD_GUEST_XORG_RESOLUTION
> from agent_read_complete() to a separate function
> to make the switch statement less cluttered.
> 
> Remove unnecessary res variable.

Please, send this outside of glib integration series, I'd be
happy to apply before :)

Reviewed-by: Victor Toso <victortoso@redhat.com>

Victor

> ---
>  src/vdagentd/vdagentd.c | 61 +++++++++++++++++++++--------------------
>  1 file changed, 31 insertions(+), 30 deletions(-)
> 
> diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
> index b8f617c..e975abd 100644
> --- a/src/vdagentd/vdagentd.c
> +++ b/src/vdagentd/vdagentd.c
> @@ -887,43 +887,44 @@ static void agent_disconnect(struct udscs_connection *conn)
>      g_free(agent_data);
>  }
>  
> -static void agent_read_complete(struct udscs_connection **connp,
> -    struct udscs_message_header *header, uint8_t *data)
> +static void do_guest_xorg_resolution(struct udscs_connection    **connp,
> +                                     struct udscs_message_header *header,
> +                                     guint8                      *data)
>  {
>      struct agent_data *agent_data = udscs_get_user_data(*connp);
> +    guint n = header->size / sizeof(struct vdagentd_guest_xorg_resolution);
>  
> -    switch (header->type) {
> -    case VDAGENTD_GUEST_XORG_RESOLUTION: {
> -        struct vdagentd_guest_xorg_resolution *res;
> -        int n = header->size / sizeof(*res);
> -
> -        /* Detect older version session agent, but don't disconnect, as
> -           that stops it from getting the VDAGENTD_VERSION message, and then
> -           it will never re-exec the new version... */
> -        if (header->arg1 == 0 && header->arg2 == 0) {
> -            syslog(LOG_INFO, "got old session agent xorg resolution message, "
> -                             "ignoring");
> -            return;
> -        }
> +    /* Detect older version session agent, but don't disconnect, as
> +     * that stops it from getting the VDAGENTD_VERSION message, and then
> +     * it will never re-exec the new version... */
> +    if (header->arg1 == 0 && header->arg2 == 0) {
> +        syslog(LOG_INFO, "got old session agent xorg resolution message, ignoring");
> +        return;
> +    }
>  
> -        if (header->size != n * sizeof(*res)) {
> -            syslog(LOG_ERR, "guest xorg resolution message has wrong size, "
> -                            "disconnecting agent");
> -            udscs_destroy_connection(connp);
> -            return;
> -        }
> +    if (header->size != n * sizeof(struct vdagentd_guest_xorg_resolution)) {
> +        syslog(LOG_ERR, "guest xorg resolution message has wrong size, "
> +                        "disconnecting agent");
> +        udscs_destroy_connection(connp);
> +        return;
> +    }
> +
> +    g_free(agent_data->screen_info);
> +    agent_data->screen_info = g_memdup(data, header->size);
> +    agent_data->width  = header->arg1;
> +    agent_data->height = header->arg2;
> +    agent_data->screen_count = n;
>  
> -        g_free(agent_data->screen_info);
> -        res = g_malloc(n * sizeof(*res));
> -        memcpy(res, data, n * sizeof(*res));
> -        agent_data->width  = header->arg1;
> -        agent_data->height = header->arg2;
> -        agent_data->screen_info  = res;
> -        agent_data->screen_count = n;
> +    check_xorg_resolution();
> +}
>  
> -        check_xorg_resolution();
> +static void agent_read_complete(struct udscs_connection **connp,
> +    struct udscs_message_header *header, uint8_t *data)
> +{
> +    switch (header->type) {
> +    case VDAGENTD_GUEST_XORG_RESOLUTION:
> +        do_guest_xorg_resolution(connp, header, data);
>          break;
> -    }
>      case VDAGENTD_CLIPBOARD_GRAB:
>      case VDAGENTD_CLIPBOARD_REQUEST:
>      case VDAGENTD_CLIPBOARD_DATA:
> -- 
> 2.17.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel