[ostree] Use GSubprocess instead of GSSubprocess (libgsystem removal)



commit 614483ecd174c3e5f9c048ebd517d186c88caa89
Author: Colin Walters <walters verbum org>
Date:   Fri Mar 18 16:46:42 2016 -0400

    Use GSubprocess instead of GSSubprocess (libgsystem removal)
    
    Since we hard-depend on GLib 2.40, we can start using GSubprocess.
    This is part of dropping our dependency on libgsystem, which is
    deprecated in favor of libglnx (as well as migrating things to GLib).

 src/libostree/ostree-bootloader-grub2.c |   42 +++++++++++++-----------------
 src/ostree/ot-admin-builtin-switch.c    |   15 +++-------
 src/ostree/ot-admin-builtin-upgrade.c   |    9 ++----
 src/ostree/ot-admin-functions.c         |   17 ++++++++++++
 src/ostree/ot-admin-functions.h         |    3 ++
 src/ostree/ot-editor.c                  |   14 +++-------
 6 files changed, 50 insertions(+), 50 deletions(-)
---
diff --git a/src/libostree/ostree-bootloader-grub2.c b/src/libostree/ostree-bootloader-grub2.c
index 42ed5ac..11316e9 100644
--- a/src/libostree/ostree-bootloader-grub2.c
+++ b/src/libostree/ostree-bootloader-grub2.c
@@ -293,9 +293,9 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader      *bootloader,
   g_autoptr(GFile) efi_new_config_temp = NULL;
   g_autoptr(GFile) efi_orig_config = NULL;
   g_autoptr(GFile) new_config_path = NULL;
-  glnx_unref_object GSSubprocessContext *procctx = NULL;
-  glnx_unref_object GSSubprocess *proc = NULL;
-  g_auto(GStrv) child_env = g_get_environ ();
+  GSubprocessFlags subp_flags = 0;
+  glnx_unref_object GSubprocessLauncher *launcher = NULL;
+  glnx_unref_object GSubprocess *proc = NULL;
   g_autofree char *bootversion_str = g_strdup_printf ("%u", (guint)bootversion);
   g_autoptr(GFile) config_path_efi_dir = NULL;
   g_autofree char *grub2_mkconfig_chroot = NULL;
@@ -337,41 +337,35 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader      *bootloader,
                                                       bootversion);
     }
 
-  procctx = gs_subprocess_context_newv ("grub2-mkconfig", "-o",
-                                        gs_file_get_path_cached (new_config_path),
-                                        NULL);
-  child_env = g_environ_setenv (child_env, "_OSTREE_GRUB2_BOOTVERSION", bootversion_str, TRUE);
+  if (!g_getenv ("OSTREE_DEBUG_GRUB2"))
+    subp_flags |= (G_SUBPROCESS_FLAGS_STDOUT_SILENCE | G_SUBPROCESS_FLAGS_STDERR_SILENCE);
+  
+  launcher = g_subprocess_launcher_new (subp_flags);
+  g_subprocess_launcher_setenv (launcher, "_OSTREE_GRUB2_BOOTVERSION", bootversion_str, TRUE);
   /* We have to pass our state to the child */
   if (self->is_efi)
-    child_env = g_environ_setenv (child_env, "_OSTREE_GRUB2_IS_EFI", "1", TRUE);
-  gs_subprocess_context_set_environment (procctx, child_env);
-  gs_subprocess_context_set_stdout_disposition (procctx, GS_SUBPROCESS_STREAM_DISPOSITION_NULL);
-  if (g_getenv ("OSTREE_DEBUG_GRUB2"))
-    gs_subprocess_context_set_stderr_disposition (procctx, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT);
-  else
-    gs_subprocess_context_set_stderr_disposition (procctx, GS_SUBPROCESS_STREAM_DISPOSITION_NULL);
-
+    g_subprocess_launcher_setenv (launcher, "_OSTREE_GRUB2_IS_EFI", "1", TRUE);
+    
   /* We need to chroot() if we're not in /.  This assumes our caller has
    * set up the bind mounts outside.
    */
   if (grub2_mkconfig_chroot != NULL)
-    {
-      gs_subprocess_context_set_child_setup (procctx, grub2_child_setup, grub2_mkconfig_chroot);
-    }
+    g_subprocess_launcher_set_child_setup (launcher, grub2_child_setup, grub2_mkconfig_chroot, NULL);
 
   /* In the current Fedora grub2 package, this script doesn't even try
      to be atomic; it just does:
 
-cat ${grub_cfg}.new > ${grub_cfg}
-rm -f ${grub_cfg}.new
+     cat ${grub_cfg}.new > ${grub_cfg}
+     rm -f ${grub_cfg}.new
 
      Upstream is fixed though.
   */
-  proc = gs_subprocess_new (procctx, cancellable, error);
-  if (!proc)
-    goto out;
+  proc = g_subprocess_launcher_spawn (launcher, error,
+                                      "grub2-mkconfig", "-o",
+                                      gs_file_get_path_cached (new_config_path),
+                                      NULL);
 
-  if (!gs_subprocess_wait_sync_check (proc, cancellable, error))
+  if (!g_subprocess_wait_check (proc, cancellable, error))
     goto out;
 
   /* Now let's fdatasync() for the new file */
diff --git a/src/ostree/ot-admin-builtin-switch.c b/src/ostree/ot-admin-builtin-switch.c
index 4d82ca6..0e0101a 100644
--- a/src/ostree/ot-admin-builtin-switch.c
+++ b/src/ostree/ot-admin-builtin-switch.c
@@ -163,16 +163,11 @@ ot_admin_builtin_switch (int argc, char **argv, GCancellable *cancellable, GErro
   if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error))
     goto out;
   
-  {
-    g_autoptr(GFile) real_sysroot = g_file_new_for_path ("/");
-      
-    if (opt_reboot && g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot))
-      {
-        gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
-                                       cancellable, error,
-                                       "systemctl", "reboot", NULL);
-      }
-  }
+  if (opt_reboot)
+    {
+      if (!ot_admin_execve_reboot (sysroot, error))
+        goto out;
+    }
 
   ret = TRUE;
  out:
diff --git a/src/ostree/ot-admin-builtin-upgrade.c b/src/ostree/ot-admin-builtin-upgrade.c
index 90d0ce9..5d4796a 100644
--- a/src/ostree/ot-admin-builtin-upgrade.c
+++ b/src/ostree/ot-admin-builtin-upgrade.c
@@ -133,16 +133,13 @@ ot_admin_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GErr
     }
   else
     {
-      g_autoptr(GFile) real_sysroot = g_file_new_for_path ("/");
-
       if (!ostree_sysroot_upgrader_deploy (upgrader, cancellable, error))
         goto out;
 
-      if (opt_reboot && g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot))
+      if (opt_reboot)
         {
-          gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
-                                         cancellable, error,
-                                         "systemctl", "reboot", NULL);
+          if (!ot_admin_execve_reboot (sysroot, error))
+            goto out;
         }
     }
 
diff --git a/src/ostree/ot-admin-functions.c b/src/ostree/ot-admin-functions.c
index c818a00..bc9034e 100644
--- a/src/ostree/ot-admin-functions.c
+++ b/src/ostree/ot-admin-functions.c
@@ -155,3 +155,20 @@ ot_admin_sysroot_lock (OstreeSysroot  *sysroot,
   g_main_context_unref (state.mainctx);
   return ret;
 }
+
+gboolean
+ot_admin_execve_reboot (OstreeSysroot *sysroot, GError **error)
+{
+  g_autoptr(GFile) real_sysroot = g_file_new_for_path ("/");
+      
+  if (g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot))
+    {
+      if (execl ("systemctl", "systemctl", "reboot", NULL) < 0)
+        {
+          glnx_set_error_from_errno (error);
+          return FALSE;
+        }
+    }
+
+  return TRUE;
+}
diff --git a/src/ostree/ot-admin-functions.h b/src/ostree/ot-admin-functions.h
index 67164ca..8c0cf8e 100644
--- a/src/ostree/ot-admin-functions.h
+++ b/src/ostree/ot-admin-functions.h
@@ -45,5 +45,8 @@ gboolean
 ot_admin_sysroot_lock (OstreeSysroot  *sysroot,
                        GError        **error);
 
+gboolean
+ot_admin_execve_reboot (OstreeSysroot *sysroot,
+                        GError **error);
 
 G_END_DECLS
diff --git a/src/ostree/ot-editor.c b/src/ostree/ot-editor.c
index 2b2101f..4c29c81 100644
--- a/src/ostree/ot-editor.c
+++ b/src/ostree/ot-editor.c
@@ -62,8 +62,7 @@ ot_editor_prompt (OstreeRepo *repo,
                   GCancellable *cancellable,
                   GError **error)
 {
-  glnx_unref_object GSSubprocessContext *ctx = NULL;
-  glnx_unref_object GSSubprocess *proc = NULL;
+  glnx_unref_object GSubprocess *proc = NULL;
   g_autoptr(GFile) file = NULL;
   g_autoptr(GFileIOStream) io = NULL;
   GOutputStream *output;
@@ -92,16 +91,11 @@ ot_editor_prompt (OstreeRepo *repo,
     g_autofree char *quoted_file = g_shell_quote (gs_file_get_path_cached (file));
     args = g_strconcat (editor, " ", quoted_file, NULL);
   }
-  ctx = gs_subprocess_context_newv ("/bin/sh", "-c", args, NULL);
-  gs_subprocess_context_set_stdin_disposition (ctx, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT);
-  gs_subprocess_context_set_stdout_disposition (ctx, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT);
-  gs_subprocess_context_set_stderr_disposition (ctx, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT);
 
-  proc = gs_subprocess_new (ctx, cancellable, error);
-  if (proc == NULL)
-    goto out;
+  proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_INHERIT, error, 
+                           "/bin/sh", "-c", args, NULL);
 
-  if (!gs_subprocess_wait_sync_check (proc, cancellable, error))
+  if (!g_subprocess_wait_check (proc, cancellable, error))
     {
       g_prefix_error (error, "There was a problem with the editor '%s'", editor);
       goto out;


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