[sysprof] build: make polkit optional again for sysprof-cli



commit 04eacbcfe209558a58f1c314c8532b74240e4845
Author: Christian Hergert <chergert redhat com>
Date:   Mon Nov 16 14:57:04 2020 -0800

    build: make polkit optional again for sysprof-cli

 meson.build                                    |  6 ++++++
 src/libsysprof/sysprof-backport-autocleanups.h |  2 +-
 src/libsysprof/sysprof-polkit.c                |  8 ++++----
 src/tools/meson.build                          |  4 +---
 src/tools/sysprof-cli.c                        | 20 ++++++++++++++------
 5 files changed, 26 insertions(+), 14 deletions(-)
---
diff --git a/meson.build b/meson.build
index 8966a56..ed73d72 100644
--- a/meson.build
+++ b/meson.build
@@ -71,6 +71,12 @@ config_h.set('HAVE_EXECINFO_H', cc.has_header('execinfo.h'))
 config_h.set('HAVE_STRLCPY', cc.has_function('strlcpy'))
 config_h.set('HAVE_REALLOCARRAY', cc.has_function('reallocarray'))
 
+polkit_agent_dep = dependency('polkit-agent-1', required: false)
+polkit_dep = dependency('polkit-gobject-1', version: polkit_req_version, required: false)
+
+config_h.set10('HAVE_POLKIT_AGENT', polkit_agent_dep.found())
+config_h.set10('HAVE_POLKIT', polkit_dep.found())
+
 if get_option('libunwind')
   libunwind_dep = dependency('libunwind-generic', required: false)
   config_h.set('ENABLE_LIBUNWIND', libunwind_dep.found())
diff --git a/src/libsysprof/sysprof-backport-autocleanups.h b/src/libsysprof/sysprof-backport-autocleanups.h
index f686ca2..381b273 100644
--- a/src/libsysprof/sysprof-backport-autocleanups.h
+++ b/src/libsysprof/sysprof-backport-autocleanups.h
@@ -4,7 +4,7 @@
 
 #include <glib.h>
 
-#ifdef HAVE_POLKIT
+#if HAVE_POLKIT
 # ifndef HAVE_POLKIT_AUTOPTR
 #  include <polkit/polkit.h>
 
diff --git a/src/libsysprof/sysprof-polkit.c b/src/libsysprof/sysprof-polkit.c
index a39eba1..fa787f2 100644
--- a/src/libsysprof/sysprof-polkit.c
+++ b/src/libsysprof/sysprof-polkit.c
@@ -22,14 +22,14 @@
 
 #include "config.h"
 
-#ifdef HAVE_POLKIT
+#if HAVE_POLKIT
 # include <polkit/polkit.h>
 #endif
 
 #include "sysprof-polkit-private.h"
 #include "sysprof-backport-autocleanups.h"
 
-#ifdef HAVE_POLKIT
+#if HAVE_POLKIT
 typedef struct
 {
   const gchar   *policy;
@@ -137,7 +137,7 @@ _sysprof_polkit_authorize_for_bus_async (GDBusConnection     *bus,
                                          gpointer             user_data)
 {
   g_autoptr(GTask) task = NULL;
-#ifdef HAVE_POLKIT
+#if HAVE_POLKIT
   const gchar *bus_name;
   Authorize *auth;
 #endif
@@ -149,7 +149,7 @@ _sysprof_polkit_authorize_for_bus_async (GDBusConnection     *bus,
   task = g_task_new (NULL, cancellable, callback, user_data);
   g_task_set_source_tag (task, _sysprof_polkit_authorize_for_bus_async);
 
-#ifdef HAVE_POLKIT
+#if HAVE_POLKIT
   bus_name = g_dbus_connection_get_unique_name (bus);
 
   auth = g_slice_new0 (Authorize);
diff --git a/src/tools/meson.build b/src/tools/meson.build
index 6b49511..3246ecb 100644
--- a/src/tools/meson.build
+++ b/src/tools/meson.build
@@ -7,9 +7,7 @@ tools_deps = [
 
 tools_cflags = [ '-DSYSPROF_COMPILATION ']
 
-if get_option('libsysprof') and host_machine.system() == 'linux'
-  polkit_agent_dep = dependency('polkit-agent-1')
-  polkit_dep = dependency('polkit-gobject-1', version: polkit_req_version, required: false)
+if get_option('libsysprof')
   sysprof_cli = executable('sysprof-cli', 'sysprof-cli.c',
     dependencies: tools_deps + [libsysprof_dep, polkit_dep, polkit_agent_dep],
           c_args: tools_cflags,
diff --git a/src/tools/sysprof-cli.c b/src/tools/sysprof-cli.c
index 354d719..cfd138f 100644
--- a/src/tools/sysprof-cli.c
+++ b/src/tools/sysprof-cli.c
@@ -25,16 +25,19 @@
 #include <glib-unix.h>
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
-#include <polkit/polkit.h>
-#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE
-#include <polkitagent/polkitagent.h>
 #include <signal.h>
 #include <stdlib.h>
-#include <sys/eventfd.h>
 #include <sys/types.h>
 #include <signal.h>
 #include <sysprof.h>
 
+#if HAVE_POLKIT && HAVE_POLKIT_AGENT
+# define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE
+# include <polkit/polkit.h>
+# include <polkitagent/polkitagent.h>
+# define USE_POLKIT
+#endif
+
 #include "sysprof-capture-util-private.h"
 
 static GMainLoop  *main_loop;
@@ -184,10 +187,13 @@ gint
 main (gint   argc,
       gchar *argv[])
 {
-  g_auto(GStrv) child_argv = NULL;
-  g_auto(GStrv) envs = NULL;
+#ifdef USE_POLKIT
   PolkitAgentListener *polkit = NULL;
   PolkitSubject *subject = NULL;
+#endif
+
+  g_auto(GStrv) child_argv = NULL;
+  g_auto(GStrv) envs = NULL;
   SysprofCaptureWriter *writer;
   SysprofSource *source;
   GMainContext *main_context;
@@ -317,6 +323,7 @@ Examples:\n\
 
   main_loop = g_main_loop_new (NULL, FALSE);
 
+#ifdef USE_POLKIT
   /* Start polkit agent so that we can elevate privileges from a TTY */
   if (g_getenv ("DESKTOP_SESSION") == NULL &&
       (subject = polkit_unix_process_new_for_owner (getpid (), 0, -1)))
@@ -338,6 +345,7 @@ Examples:\n\
                       pkerror->message);
         }
     }
+#endif
 
   profiler = sysprof_local_profiler_new ();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]