diff --git a/meson.build b/meson.build index 8966a56f..ed73d725 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 f686ca25..381b2735 100644 --- a/src/libsysprof/sysprof-backport-autocleanups.h +++ b/src/libsysprof/sysprof-backport-autocleanups.h @@ -4,7 +4,7 @@ #include -#ifdef HAVE_POLKIT +#if HAVE_POLKIT # ifndef HAVE_POLKIT_AUTOPTR # include diff --git a/src/libsysprof/sysprof-polkit.c b/src/libsysprof/sysprof-polkit.c index a39eba14..fa787f2a 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 #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 6b49511d..3246ecb7 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 354d719c..cfd138f7 100644 --- a/src/tools/sysprof-cli.c +++ b/src/tools/sysprof-cli.c @@ -25,16 +25,19 @@ #include #include #include -#include -#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE -#include #include #include -#include #include #include #include +#if HAVE_POLKIT && HAVE_POLKIT_AGENT +# define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE +# include +# include +# 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 ();