helpers: try harder to avoid D-Bus to daemon

This commit is contained in:
Christian Hergert
2019-05-21 21:56:39 -07:00
parent 86aeb56f41
commit 13b3edcbf6

View File

@ -344,11 +344,8 @@ sysprof_helpers_get_proc_file (SysprofHelpers *self,
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE); g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
/* try locally first if we can */ /* try locally first if we can */
if (!g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS)) if (helpers_can_see_pids ())
{ return helpers_get_proc_file (path, contents, &len);
if (helpers_get_proc_file (path, contents, &len))
return TRUE;
}
if (self->proxy != NULL) if (self->proxy != NULL)
{ {
@ -644,7 +641,7 @@ sysprof_helpers_get_process_info (SysprofHelpers *self,
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
g_assert (info != NULL); g_assert (info != NULL);
if (no_proxy) if (no_proxy || helpers_can_see_pids ())
{ {
*info = helpers_get_process_info (attributes); *info = helpers_get_process_info (attributes);
return TRUE; return TRUE;
@ -672,6 +669,32 @@ sysprof_helpers_get_process_info_cb (IpcService *service,
g_task_return_pointer (task, g_steal_pointer (&info), (GDestroyNotify)g_variant_unref); g_task_return_pointer (task, g_steal_pointer (&info), (GDestroyNotify)g_variant_unref);
} }
static void
sysprof_helpers_get_process_info_worker (GTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
{
const gchar *attributes = task_data;
g_autoptr(GError) error = NULL;
g_autoptr(GVariant) ret = NULL;
g_assert (G_IS_TASK (task));
g_assert (SYSPROF_IS_HELPERS (source_object));
g_assert (attributes != NULL);
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
if ((ret = helpers_get_process_info (attributes)))
g_task_return_pointer (task,
g_steal_pointer (&ret),
(GDestroyNotify) g_variant_unref);
else
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"Failed to retrieve proc info");
}
void void
sysprof_helpers_get_process_info_async (SysprofHelpers *self, sysprof_helpers_get_process_info_async (SysprofHelpers *self,
const gchar *attributes, const gchar *attributes,
@ -688,6 +711,13 @@ sysprof_helpers_get_process_info_async (SysprofHelpers *self,
task = g_task_new (self, cancellable, callback, user_data); task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, sysprof_helpers_get_process_info_async); g_task_set_source_tag (task, sysprof_helpers_get_process_info_async);
if (helpers_can_see_pids ())
{
g_task_set_task_data (task, g_strdup (attributes), g_free);
g_task_run_in_thread (task, sysprof_helpers_get_process_info_worker);
return;
}
ipc_service_call_get_process_info (self->proxy, ipc_service_call_get_process_info (self->proxy,
attributes, attributes,
cancellable, cancellable,