[Spice-devel] [PATCH spice-gtk 2/3] SpiceUsbAclHelper: add "acl-helper-path" property

Jonathon Jongsma jjongsma at redhat.com
Tue Mar 8 22:25:22 UTC 2016


This allows you to specify a path to a custom binary that will be
spawned by SpiceUsbAclHelper to obtain permission for a particular USB
device. This will be used for testing so that we can use a mock acl
helper binary that can be manipulated to return arbitary responses.
This makes it easier to verify that the SpiceUsbAclHelper class handles
those responses appropriately.
---
 src/usb-acl-helper.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/src/usb-acl-helper.c b/src/usb-acl-helper.c
index 3145b68..c9d384b 100644
--- a/src/usb-acl-helper.c
+++ b/src/usb-acl-helper.c
@@ -40,10 +40,16 @@ struct _SpiceUsbAclHelperPrivate {
     GIOChannel *out_ch;
     GCancellable *cancellable;
     gulong cancellable_id;
+    char *acl_helper_path;
 };
 
 G_DEFINE_TYPE(SpiceUsbAclHelper, spice_usb_acl_helper, G_TYPE_OBJECT);
 
+enum {
+    PROP_0,
+    PROP_ACL_HELPER_PATH
+};
+
 static void spice_usb_acl_helper_init(SpiceUsbAclHelper *self)
 {
     self->priv = SPICE_USB_ACL_HELPER_GET_PRIVATE(self);
@@ -68,6 +74,11 @@ static void spice_usb_acl_helper_cleanup(SpiceUsbAclHelper *self)
         g_io_channel_unref(priv->out_ch);
         priv->out_ch = NULL;
     }
+
+    if (priv->acl_helper_path) {
+        g_free(priv->acl_helper_path);
+        priv->acl_helper_path = NULL;
+    }
 }
 
 static void spice_usb_acl_helper_finalize(GObject *gobject)
@@ -78,13 +89,58 @@ static void spice_usb_acl_helper_finalize(GObject *gobject)
         G_OBJECT_CLASS(spice_usb_acl_helper_parent_class)->finalize(gobject);
 }
 
+static void spice_usb_acl_helper_get_property(GObject    *object,
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+    SpiceUsbAclHelper *self = SPICE_USB_ACL_HELPER(object);
+
+    switch (prop_id) {
+    case PROP_ACL_HELPER_PATH:
+        g_value_set_string(value, self->priv->acl_helper_path);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void spice_usb_acl_helper_set_property(GObject *gobject, guint prop_id,
+                                              const GValue *value, GParamSpec *pspec)
+{
+    SpiceUsbAclHelper *self = SPICE_USB_ACL_HELPER(gobject);
+
+    switch (prop_id) {
+    case PROP_ACL_HELPER_PATH:
+        g_free(self->priv->acl_helper_path);
+        self->priv->acl_helper_path = g_value_dup_string(value);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
+        break;
+    }
+}
+
 static void spice_usb_acl_helper_class_init(SpiceUsbAclHelperClass *klass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
     gobject_class->finalize     = spice_usb_acl_helper_finalize;
+    gobject_class->get_property = spice_usb_acl_helper_get_property;
+    gobject_class->set_property = spice_usb_acl_helper_set_property;
 
     g_type_class_add_private(klass, sizeof(SpiceUsbAclHelperPrivate));
+
+    g_object_class_install_property(gobject_class, PROP_ACL_HELPER_PATH,
+                                    g_param_spec_string("acl-helper-path",
+                                                        "acl-helper-path",
+                                                        "acl-helper-path",
+                                                        ACL_HELPER_PATH "/spice-client-glib-usb-acl-helper",
+                                                        G_PARAM_STATIC_STRINGS
+                                                        | G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT));
+
 }
 
 /* ------------------------------------------------------------------ */
@@ -198,7 +254,7 @@ void spice_usb_acl_helper_open_acl(SpiceUsbAclHelper *self,
     GIOStatus status;
     GPid helper_pid;
     gsize bytes_written;
-    gchar *argv[] = { (char*) ACL_HELPER_PATH"/spice-client-glib-usb-acl-helper", NULL };
+    gchar *argv[] = { priv->acl_helper_path, NULL };
     gint in, out;
     gchar buf[128];
 
-- 
2.4.3



More information about the Spice-devel mailing list