From 0df59fcfc992c6fe3f7a3140a13b8de227f36edc Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Fri, 18 Mar 2016 16:29:38 +0100 Subject: [PATCH] agent: Sync AgentMsgFilter state upon agent connection AgentMsgFilter needs to know whether monitors config messages need to be filtered or not. This used to be done from within agent_msg_filter_config() using the global RedsState, but this got more tricky as it was removed. A first attempt a1e62fa5ae9 caused crashes on qemu startup with "qemu-system-x86_64 -spice port=5900" (without -vga qxl). A second attempt added a RedsState* argument to agent_msg_filter_config() which in my opinion is not really nice from a layering point of view. This new attempt makes sure AgentMsgFilter state is correct when the filter is set to stop discarding all data, which allows to remove direct use of RedsState from within AgentMsgFilter. Acked-by: Frediano Ziglio --- server/agent-msg-filter.c | 14 +++++++++++--- server/agent-msg-filter.h | 3 +++ server/reds.c | 10 ++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/server/agent-msg-filter.c b/server/agent-msg-filter.c index db8526e7..498864c5 100644 --- a/server/agent-msg-filter.c +++ b/server/agent-msg-filter.c @@ -27,15 +27,23 @@ #include "reds.h" #include "red-qxl.h" +void agent_msg_filter_config(struct AgentMsgFilter *filter, + gboolean copy_paste, gboolean file_xfer, + gboolean use_client_monitors_config) +{ + filter->copy_paste_enabled = copy_paste; + filter->file_xfer_enabled = file_xfer; + filter->use_client_monitors_config = use_client_monitors_config; +} + void agent_msg_filter_init(struct AgentMsgFilter *filter, gboolean copy_paste, gboolean file_xfer, gboolean use_client_monitors_config, int discard_all) { memset(filter, 0, sizeof(*filter)); - filter->copy_paste_enabled = copy_paste; - filter->file_xfer_enabled = file_xfer; - filter->use_client_monitors_config = use_client_monitors_config; + agent_msg_filter_config(filter, copy_paste, file_xfer, + use_client_monitors_config); filter->discard_all = discard_all; } diff --git a/server/agent-msg-filter.h b/server/agent-msg-filter.h index c04face8..2ee055c8 100644 --- a/server/agent-msg-filter.h +++ b/server/agent-msg-filter.h @@ -45,6 +45,9 @@ void agent_msg_filter_init(struct AgentMsgFilter *filter, gboolean copy_paste, gboolean file_xfer, gboolean use_client_monitors_config, gboolean discard_all); +void agent_msg_filter_config(struct AgentMsgFilter *filter, + gboolean copy_paste, gboolean file_xfer, + gboolean use_client_monitors_config); int agent_msg_filter_process_data(struct AgentMsgFilter *filter, uint8_t *data, uint32_t len); diff --git a/server/reds.c b/server/reds.c index f10f218a..91c7851a 100644 --- a/server/reds.c +++ b/server/reds.c @@ -953,6 +953,10 @@ void reds_on_main_agent_start(RedsState *reds, MainChannelClient *mcc, uint32_t rcc->client, num_tokens); } + + agent_msg_filter_config(&reds->agent_state.write_filter, reds->agent_copypaste, + reds->agent_file_xfer, + reds_use_client_monitors_config(reds)); reds->agent_state.write_filter.discard_all = FALSE; } @@ -1680,6 +1684,10 @@ static void reds_handle_main_link(RedsState *reds, RedLinkInfo *link) if (mig_target) { spice_warning("unexpected: vdagent attached to destination during migration"); } + agent_msg_filter_config(&reds->agent_state.read_filter, + reds->agent_copypaste, + reds->agent_file_xfer, + reds_use_client_monitors_config(reds)); reds->agent_state.read_filter.discard_all = FALSE; reds->agent_state.plug_generation++; } @@ -3190,8 +3198,6 @@ SPICE_GNUC_VISIBLE int spice_server_add_interface(SpiceServer *s, qxl = SPICE_CONTAINEROF(sin, QXLInstance, base); red_qxl_init(reds, qxl); reds->qxl_instances = g_list_prepend(reds->qxl_instances, qxl); - reds->agent_state.write_filter.use_client_monitors_config = reds_use_client_monitors_config(reds); - reds->agent_state.read_filter.use_client_monitors_config = reds_use_client_monitors_config(reds); /* this function has to be called after the qxl is on the list * as QXLInstance clients expect the qxl to be on the list when