[Spice-devel] [spice-gtk v1 4/4] channel-usbredir: move polkit related checks to usb-acl-helper
Victor Toso
victortoso at redhat.com
Tue May 7 08:56:05 UTC 2019
From: Victor Toso <me at victortoso.com>
There is no need to direct interaction with polkit in
channel-usbredir. Let's keep all the access control related code to
usb-acl-helper APIs.
This patch moves the g_task_run_in_thread() to
spice_usb_acl_helper_open_acl_async() to keep code behaving similarly
to what we had before this patch.
Signed-off-by: Victor Toso <victortoso at redhat.com>
---
src/channel-usbredir.c | 52 ++----------------------------------------
src/usb-acl-helper.c | 21 +++++++++++++++++
2 files changed, 23 insertions(+), 50 deletions(-)
diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index 5214160..5411a51 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -27,9 +27,7 @@
#ifdef USE_LZ4
#include <lz4.h>
#endif
-#ifdef USE_POLKIT
#include "usb-acl-helper.h"
-#endif
#include "channel-usbredir-priv.h"
#include "usb-device-manager-priv.h"
#include "usbutil.h"
@@ -55,9 +53,7 @@
#define COMPRESS_THRESHOLD 1000
enum SpiceUsbredirChannelState {
STATE_DISCONNECTED,
-#ifdef USE_POLKIT
STATE_WAITING_FOR_ACL_HELPER,
-#endif
STATE_CONNECTED,
STATE_DISCONNECTING,
};
@@ -73,10 +69,8 @@ struct _SpiceUsbredirChannelPrivate {
const uint8_t *read_buf;
int read_buf_size;
enum SpiceUsbredirChannelState state;
-#ifdef USE_POLKIT
GTask *task;
SpiceUsbAclHelper *acl_helper;
-#endif
GMutex device_connect_mutex;
SpiceUsbDeviceManager *usb_device_manager;
};
@@ -282,11 +276,8 @@ static gboolean spice_usbredir_channel_open_device(
int rc, status;
SpiceUsbDeviceManager *manager;
- g_return_val_if_fail(priv->state == STATE_DISCONNECTED
-#ifdef USE_POLKIT
- || priv->state == STATE_WAITING_FOR_ACL_HELPER
-#endif
- , FALSE);
+ g_return_val_if_fail(priv->state == STATE_DISCONNECTED ||
+ priv->state == STATE_WAITING_FOR_ACL_HELPER, FALSE);
rc = libusb_open(priv->device, &handle);
if (rc != 0) {
@@ -319,7 +310,6 @@ static gboolean spice_usbredir_channel_open_device(
return TRUE;
}
-#ifdef USE_POLKIT
static void spice_usbredir_channel_open_acl_cb(
GObject *gobject, GAsyncResult *acl_res, gpointer user_data)
{
@@ -359,37 +349,6 @@ static void spice_usbredir_channel_open_acl_cb(
g_clear_object(&priv->task);
}
-#endif
-
-#ifndef USE_POLKIT
-static void
-_open_device_async_cb(GTask *task,
- gpointer object,
- gpointer task_data,
- GCancellable *cancellable)
-{
- GError *err = NULL;
- SpiceUsbredirChannel *channel = SPICE_USBREDIR_CHANNEL(object);
- SpiceUsbredirChannelPrivate *priv = channel->priv;
-
- spice_usbredir_channel_lock(channel);
-
- if (!spice_usbredir_channel_open_device(channel, &err)) {
- libusb_unref_device(priv->device);
- priv->device = NULL;
- g_boxed_free(spice_usb_device_get_type(), priv->spice_device);
- priv->spice_device = NULL;
- }
-
- spice_usbredir_channel_unlock(channel);
-
- if (err) {
- g_task_return_error(task, err);
- } else {
- g_task_return_boolean(task, TRUE);
- }
-}
-#endif
G_GNUC_INTERNAL
void spice_usbredir_channel_connect_device_async(
@@ -430,7 +389,6 @@ void spice_usbredir_channel_connect_device_async(
priv->device = libusb_ref_device(device);
priv->spice_device = g_boxed_copy(spice_usb_device_get_type(),
spice_device);
-#ifdef USE_POLKIT
priv->task = task;
priv->state = STATE_WAITING_FOR_ACL_HELPER;
priv->acl_helper = spice_usb_acl_helper_new();
@@ -443,10 +401,6 @@ void spice_usbredir_channel_connect_device_async(
spice_usbredir_channel_open_acl_cb,
channel);
return;
-#else
- g_task_run_in_thread(task, _open_device_async_cb);
-#endif
-
done:
g_object_unref(task);
}
@@ -477,13 +431,11 @@ void spice_usbredir_channel_disconnect_device(SpiceUsbredirChannel *channel)
case STATE_DISCONNECTED:
case STATE_DISCONNECTING:
break;
-#ifdef USE_POLKIT
case STATE_WAITING_FOR_ACL_HELPER:
priv->state = STATE_DISCONNECTING;
/* We're still waiting for the acl helper -> cancel it */
spice_usb_acl_helper_cancel(priv->acl_helper);
break;
-#endif
case STATE_CONNECTED:
/*
* This sets the usb event thread run condition to FALSE, therefor
diff --git a/src/usb-acl-helper.c b/src/usb-acl-helper.c
index 30ac3dd..6e9a0ab 100644
--- a/src/usb-acl-helper.c
+++ b/src/usb-acl-helper.c
@@ -203,6 +203,23 @@ exec_usb_acl_helper_bin(SpiceUsbAclHelper *self,
(GIOFunc)cb_out_watch, g_object_ref(self));
return TRUE;
}
+
+#else
+
+static void
+complete_later(GTask *task,
+ G_GNUC_UNUSED gpointer object,
+ G_GNUC_UNUSED gpointer task_data,
+ GCancellable *cancellable)
+{
+ if (g_cancellable_is_cancelled(cancellable)) {
+ async_result_set_cancelled(task);
+ return;
+ }
+
+ g_task_return_boolean(task, TRUE);
+}
+
#endif /* USE_POLKIT */
/* ------------------------------------------------------------------ */
@@ -261,6 +278,10 @@ void spice_usb_acl_helper_open_acl_async(SpiceUsbAclHelper *self,
G_CALLBACK(cancelled_cb),
self, NULL);
}
+
+#ifndef USE_POLKIT
+ g_task_run_in_thread(task, complete_later);
+#endif
return;
done:
--
2.20.1
More information about the Spice-devel
mailing list