[spice-gtk,v1,2/4] usb-acl-helper: always build access control helper

Submitted by Victor Toso on May 7, 2019, 8:56 a.m.

Details

Message ID 20190507085605.10054-3-victortoso@redhat.com
State New
Headers show
Series "polkit code to be on usb-acl-helper" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Victor Toso May 7, 2019, 8:56 a.m.
From: Victor Toso <me@victortoso.com>

This will allow us to simplify channel-usbredir code, which contains a
few #ifdef USE_POLKIT blocks while the code itself is only calling
the usb-acl-helper APIs.

Let's keep the API working even when polkit is disabled.

This is a preparation patch, after this patch, the channel-usbredir.c
still only calls usb-acl-helper API's when polkit is enabled. The next
patch adds the missing bits so the API keeps working without Polkit.

Signed-off-by: Victor Toso <victortoso@redhat.com>
---
 src/Makefile.am      | 13 +++----------
 src/meson.build      |  7 ++-----
 src/usb-acl-helper.c | 19 ++++++++++++-------
 3 files changed, 17 insertions(+), 22 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/Makefile.am b/src/Makefile.am
index 7b98180..90a5c7c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -96,6 +96,7 @@  SPICE_COMMON_CPPFLAGS =						\
 
 AM_CPPFLAGS =					\
 	-DLOCALE_DIR=\""$(datadir)/locale"\"	\
+	-DACL_HELPER_PATH="\"$(ACL_HELPER_DIR)\""	\
 	$(SPICE_COMMON_CPPFLAGS)		\
 	$(SPICE_CFLAGS)				\
 	$(NULL)
@@ -203,15 +204,6 @@  libspice_client_glib_impl_la_LIBADD =					\
 	$(PHODAV_LIBS)							\
 	$(NULL)
 
-if WITH_POLKIT
-USB_ACL_HELPER_SRCS =				\
-	usb-acl-helper.c			\
-	usb-acl-helper.h			\
-	$(NULL)
-AM_CPPFLAGS += -DACL_HELPER_PATH="\"$(ACL_HELPER_DIR)\""
-else
-USB_ACL_HELPER_SRCS =
-endif
 
 libspice_client_glib_2_0_la_SOURCES =
 libspice_client_glib_impl_la_SOURCES =			\
@@ -264,7 +256,8 @@  libspice_client_glib_impl_la_SOURCES =			\
 	usb-device-manager-priv.h			\
 	usbutil.c					\
 	usbutil.h					\
-	$(USB_ACL_HELPER_SRCS)				\
+	usb-acl-helper.c				\
+	usb-acl-helper.h				\
 	vmcstream.c					\
 	vmcstream.h					\
 							\
diff --git a/src/meson.build b/src/meson.build
index 5365f05..0608532 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -118,6 +118,8 @@  spice_client_glib_sources = [
   'spice-uri.c',
   'spice-uri-priv.h',
   'spice-util-priv.h',
+  'usb-acl-helper.c',
+  'usb-acl-helper.h',
   'usb-device-manager-priv.h',
   'usbutil.c',
   'usbutil.h',
@@ -129,11 +131,6 @@  if spice_gtk_has_builtin_mjpeg
   spice_client_glib_sources += 'channel-display-mjpeg.c'
 endif
 
-if spice_gtk_has_polkit
-  spice_client_glib_sources += ['usb-acl-helper.c',
-                                'usb-acl-helper.h']
-endif
-
 if spice_gtk_has_phodav
   spice_client_glib_sources += ['giopipe.c',
                                 'giopipe.h']
diff --git a/src/usb-acl-helper.c b/src/usb-acl-helper.c
index 3145597..30ac3dd 100644
--- a/src/usb-acl-helper.c
+++ b/src/usb-acl-helper.c
@@ -81,6 +81,15 @@  static void async_result_set_cancelled(GTask *task)
                 "Setting USB device node ACL cancelled");
 }
 
+static void cancelled_cb(GCancellable *cancellable, gpointer user_data)
+{
+    SpiceUsbAclHelper *self = SPICE_USB_ACL_HELPER(user_data);
+
+    spice_usb_acl_helper_cancel(self);
+}
+
+#ifdef USE_POLKIT
+
 static gboolean cb_out_watch(GIOChannel    *channel,
                              GIOCondition   cond,
                              gpointer      *user_data)
@@ -142,13 +151,6 @@  done:
     return FALSE;
 }
 
-static void cancelled_cb(GCancellable *cancellable, gpointer user_data)
-{
-    SpiceUsbAclHelper *self = SPICE_USB_ACL_HELPER(user_data);
-
-    spice_usb_acl_helper_cancel(self);
-}
-
 static void helper_child_watch_cb(GPid pid, gint status, gpointer user_data)
 {
     /* Nothing to do, but we need the child watch to avoid zombies */
@@ -201,6 +203,7 @@  exec_usb_acl_helper_bin(SpiceUsbAclHelper *self,
                    (GIOFunc)cb_out_watch, g_object_ref(self));
     return TRUE;
 }
+#endif /* USE_POLKIT */
 
 /* ------------------------------------------------------------------ */
 /* private api                                                        */
@@ -242,12 +245,14 @@  void spice_usb_acl_helper_open_acl_async(SpiceUsbAclHelper *self,
         goto done;
     }
 
+#ifdef USE_POLKIT
     gchar buf[128];
     snprintf(buf, sizeof(buf), "%d %d\n", busnum, devnum);
     if (!exec_usb_acl_helper_bin(self, buf, &err)) {
         g_task_return_error(task, err);
         goto done;
     }
+#endif /* USE_POLKIT */
 
     priv->task = task;
     if (cancellable) {