[gnome-software] Ensure all calls to pkexec use g_child_watch_add()
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Ensure all calls to pkexec use g_child_watch_add()
- Date: Thu, 19 Dec 2013 09:30:44 +0000 (UTC)
commit 99f308fa8e4d319e016d58e2be3cbfdbbce8304a
Author: Richard Hughes <richard hughsie com>
Date: Wed Dec 18 17:54:45 2013 +0000
Ensure all calls to pkexec use g_child_watch_add()
Otherwise the application asserts with new versions of GLib...
src/gs-offline-updates.c | 58 +++++++++++++++++++++------------------------
1 files changed, 27 insertions(+), 31 deletions(-)
---
diff --git a/src/gs-offline-updates.c b/src/gs-offline-updates.c
index 0fa0dd8..e19c451 100644
--- a/src/gs-offline-updates.c
+++ b/src/gs-offline-updates.c
@@ -33,27 +33,41 @@ child_exit_cb (GPid pid, gint status, gpointer user_data)
g_spawn_close_pid (pid);
}
-void
-gs_offline_updates_clear_status (void)
+
+static gboolean
+gs_spawn_pkexec (const gchar *command, const gchar *parameter, GError **error)
{
- gboolean ret;
- GError *error = NULL;
- const gchar *argv[3];
GPid pid;
+ const gchar *argv[4];
+ gboolean ret;
argv[0] = "pkexec";
- argv[1] = LIBEXECDIR "/pk-clear-offline-update";
- argv[2] = NULL;
+ argv[1] = command;
+ argv[2] = parameter;
+ argv[3] = NULL;
+ g_debug ("calling %s %s %s",
+ argv[0], argv[1], argv[2] != NULL ? argv[2] : "");
ret = g_spawn_async (NULL, (gchar**)argv, NULL,
G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
- NULL, NULL, &pid, &error);
+ NULL, NULL, &pid, error);
+ if (!ret)
+ return FALSE;
+ g_child_watch_add (pid, child_exit_cb, NULL);
+ return TRUE;
+}
+
+void
+gs_offline_updates_clear_status (void)
+{
+ gboolean ret;
+ GError *error = NULL;
+
+ ret = gs_spawn_pkexec (LIBEXECDIR "/pk-clear-offline-update", NULL, &error);
if (!ret) {
g_warning ("Failure clearing offline update message: %s",
error->message);
g_error_free (error);
- return;
}
- g_child_watch_add (pid, child_exit_cb, NULL);
}
void
@@ -61,19 +75,10 @@ gs_offline_updates_trigger (void)
{
gboolean ret;
GError *error = NULL;
- const gchar *argv[3];
GDateTime *now;
GSettings *settings;
- argv[0] = "pkexec";
- argv[1] = LIBEXECDIR "/pk-trigger-offline-update";
- argv[2] = NULL;
-
- g_debug ("calling %s %s", argv[0], argv[1]);
-
- ret = g_spawn_sync (NULL, (gchar**)argv, NULL,
- G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
- NULL, NULL, NULL, NULL, NULL, &error);
+ ret = gs_spawn_pkexec (LIBEXECDIR "/pk-trigger-offline-update", NULL, &error);
if (!ret) {
g_warning ("Failure triggering offline update: %s",
error->message);
@@ -93,18 +98,9 @@ gs_offline_updates_cancel (void)
{
gboolean ret;
GError *error = NULL;
- const gchar *argv[4];
-
- argv[0] = "pkexec";
- argv[1] = LIBEXECDIR "/pk-trigger-offline-update";
- argv[2] = "--cancel";
- argv[3] = NULL;
-
- g_debug ("calling %s %s %s", argv[0], argv[1], argv[2]);
- ret = g_spawn_sync (NULL, (gchar**)argv, NULL,
- G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
- NULL, NULL, NULL, NULL, NULL, &error);
+ ret = gs_spawn_pkexec (LIBEXECDIR "/pk-trigger-offline-update",
+ "--cancel", &error);
if (!ret) {
g_warning ("Failure cancelling offline update: %s",
error->message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]