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).
This commit is contained in:
parent
afb6105a51
commit
614483ecd1
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue