[gnome-initial-setup/mcatanzaro/resurrect-software-page] pkexec: Modernize with g_autoptr()



commit baf392034bb9f1d94e1bc69ad90ae729124cb6a3
Author: Will Thompson <wjt endlessos org>
Date:   Mon Aug 9 11:24:38 2021 +0100

    pkexec: Modernize with g_autoptr()
    
    The original version of this function (in Endless's fork) either
    predated g_autoptr() being available for GSubprocess[Launcher], or
    predated me knowing about it.

 gnome-initial-setup/gis-pkexec.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
---
diff --git a/gnome-initial-setup/gis-pkexec.c b/gnome-initial-setup/gis-pkexec.c
index 5fb88090..9e1bfa9a 100644
--- a/gnome-initial-setup/gis-pkexec.c
+++ b/gnome-initial-setup/gis-pkexec.c
@@ -31,12 +31,11 @@ gis_pkexec (const gchar  *command,
             const gchar  *user,
             GError      **error)
 {
-  GSubprocessLauncher *launcher = NULL;
-  GSubprocess *process = NULL;
+  g_autoptr(GSubprocessLauncher) launcher = NULL;
+  g_autoptr(GSubprocess) process = NULL;
   const gchar * const root_argv[] = { "pkexec", command, arg1, NULL };
   const gchar * const user_argv[] = { "pkexec", "--user", user, command, arg1, NULL };
   const gchar * const *argv = user == NULL ? root_argv : user_argv;
-  gboolean ret = FALSE;
 
   launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
 
@@ -48,18 +47,13 @@ gis_pkexec (const gchar  *command,
 
   if (!process) {
     g_prefix_error (error, "Failed to create %s process: ", command);
-    goto out;
+    return FALSE;
   }
 
   if (!g_subprocess_wait_check (process, NULL, error)) {
     g_prefix_error (error, "%s failed: ", command);
-    goto out;
+    return FALSE;
   }
 
-  ret = TRUE;
-
-out:
-  g_clear_object (&process);
-  g_clear_object (&launcher);
-  return ret;
+  return TRUE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]