From afadd90834e488423261e5df3ab7703e22ffd32a Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Sun, 24 Apr 2016 17:49:03 -0700 Subject: [PATCH] perf: ping the sysprofd service before we consider it up This should help catch failures where the peer is not yet up and might fail to start, before we actually block on communicating with it. --- lib/sp-perf-counter.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/sp-perf-counter.c b/lib/sp-perf-counter.c index f08039d3..f2cdc59b 100644 --- a/lib/sp-perf-counter.c +++ b/lib/sp-perf-counter.c @@ -503,6 +503,27 @@ get_authorized_proxy (void) return NULL; } +static void +sp_perf_counter_ping_cb (GObject *object, + GAsyncResult *result, + gpointer user_data) +{ + GDBusProxy *proxy = (GDBusProxy *)object; + g_autoptr(GTask) task = user_data; + g_autoptr(GVariant) ret = NULL; + GError *error = NULL; + + g_assert (G_IS_DBUS_PROXY (proxy)); + g_assert (G_IS_TASK (task)); + g_assert (G_IS_ASYNC_RESULT (result)); + + ret = g_dbus_proxy_call_finish (proxy, result, &error); + + if (error != NULL) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); +} static void sp_perf_counter_acquire_cb (GObject *object, @@ -511,6 +532,7 @@ sp_perf_counter_acquire_cb (GObject *object, { g_autoptr(GTask) task = user_data; GPermission *permission = (GPermission *)object; + g_autoptr(GDBusProxy) proxy = NULL; GError *error = NULL; g_assert (G_IS_PERMISSION (permission)); @@ -523,7 +545,26 @@ sp_perf_counter_acquire_cb (GObject *object, return; } - g_task_return_boolean (task, TRUE); + proxy = get_proxy (); + + if (proxy == NULL) + { + /* We don't connect at startup, shouldn't happen */ + g_task_return_new_error (task, + G_IO_ERROR, + G_IO_ERROR_FAILED, + "Failed to create proxy"); + return; + } + + g_dbus_proxy_call (proxy, + "org.freedesktop.DBus.Peer.Ping", + NULL, + G_DBUS_CALL_FLAGS_NONE, + 5000, + g_task_get_cancellable (task), + sp_perf_counter_ping_cb, + g_object_ref (task)); } static void