summaryrefslogtreecommitdiffstats
path: root/client/x11/platform.cpp
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2010-10-06 12:37:05 +0200
committerHans de Goede <hdegoede@redhat.com>2010-10-06 19:17:08 +0200
commit7b84db7a7484b58fdde21029ef374baeaa0a4b51 (patch)
treeb60ecf190ce59021b7e57c3d4b9d4c076536ae9a /client/x11/platform.cpp
parent34bfaa302d5da8e08620d31d3f40d55ee9d14b98 (diff)
downloadspice-7b84db7a7484b58fdde21029ef374baeaa0a4b51.tar.gz
spice-7b84db7a7484b58fdde21029ef374baeaa0a4b51.tar.xz
spice-7b84db7a7484b58fdde21029ef374baeaa0a4b51.zip
spicec: Move setting of clipboard_owner to guest to platform code
Atleast under x11 there is a race condition when setting the clipboard owner to guest from the RedClient code rather then doing it in Platform. After the XSetSelectionOwner() in Platform::on_clipboard_grab(), which runs from the main message loop thread, the x11 event thread can receive a SelectionRequest event from another x11 app, before the RedClient code has set the clipboard owner, which will trigger the owner != guest check in the SelectionRequest event handling code. By moving the setting of the owner in to Platform::on_clipboard_grab() it gets protected by the clipboard lock, which closes this tiny race.
Diffstat (limited to 'client/x11/platform.cpp')
-rw-r--r--client/x11/platform.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/client/x11/platform.cpp b/client/x11/platform.cpp
index 29b5f753..8f0665cb 100644
--- a/client/x11/platform.cpp
+++ b/client/x11/platform.cpp
@@ -3355,6 +3355,8 @@ bool Platform::on_clipboard_grab(uint32_t *types, uint32_t type_count)
XSetSelectionOwner(x_display, clipboard_prop, platform_win, CurrentTime);
XFlush(x_display);
+
+ set_clipboard_owner_unlocked(owner_guest);
return true;
}
@@ -3362,12 +3364,16 @@ int Platform::_clipboard_owner = Platform::owner_none;
void Platform::set_clipboard_owner(int new_owner)
{
+ Lock lock(clipboard_lock);
+ set_clipboard_owner_unlocked(new_owner);
+}
+
+void Platform::set_clipboard_owner_unlocked(int new_owner)
+{
const char * const owner_str[] = { "none", "guest", "client" };
/* Clear pending requests and clipboard data */
{
- Lock lock(clipboard_lock);
-
if (next_selection_request) {
LOG_INFO("selection requests pending upon clipboard owner change, clearing");
while (next_selection_request)