proc: authorize before starting source

This commit is contained in:
Christian Hergert
2020-08-21 13:14:48 -07:00
parent e647a83557
commit 0a529b7670

View File

@ -53,6 +53,7 @@ struct _SysprofProcSource
SysprofCaptureWriter *writer; SysprofCaptureWriter *writer;
GArray *pids; GArray *pids;
SysprofMountinfo *mountinfo; SysprofMountinfo *mountinfo;
guint is_ready : 1;
}; };
static void source_iface_init (SysprofSourceInterface *iface); static void source_iface_init (SysprofSourceInterface *iface);
@ -301,6 +302,47 @@ sysprof_proc_source_add_pid (SysprofSource *source,
g_array_append_val (self->pids, pid); g_array_append_val (self->pids, pid);
} }
static void
sysprof_proc_source_auth_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
SysprofHelpers *helpers = (SysprofHelpers *)object;
g_autoptr(SysprofProcSource) self = user_data;
g_autoptr(GError) error = NULL;
g_assert (SYSPROF_IS_HELPERS (helpers));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (SYSPROF_IS_PROC_SOURCE (self));
if (!sysprof_helpers_authorize_finish (helpers, result, &error))
{
sysprof_source_emit_failed (SYSPROF_SOURCE (self), error);
}
else
{
self->is_ready = TRUE;
sysprof_source_emit_ready (SYSPROF_SOURCE (self));
}
}
static void
sysprof_proc_source_prepare (SysprofSource *source)
{
g_assert (SYSPROF_IS_PROC_SOURCE (source));
sysprof_helpers_authorize_async (sysprof_helpers_get_default (),
NULL,
sysprof_proc_source_auth_cb,
g_object_ref (source));
}
static gboolean
sysprof_proc_source_get_is_ready (SysprofSource *source)
{
return SYSPROF_PROC_SOURCE (source)->is_ready;
}
static void static void
source_iface_init (SysprofSourceInterface *iface) source_iface_init (SysprofSourceInterface *iface)
{ {
@ -308,6 +350,8 @@ source_iface_init (SysprofSourceInterface *iface)
iface->start = sysprof_proc_source_start; iface->start = sysprof_proc_source_start;
iface->stop = sysprof_proc_source_stop; iface->stop = sysprof_proc_source_stop;
iface->add_pid = sysprof_proc_source_add_pid; iface->add_pid = sysprof_proc_source_add_pid;
iface->prepare = sysprof_proc_source_prepare;
iface->get_is_ready = sysprof_proc_source_get_is_ready;
} }
static void static void