core: Use new libgsystem GSSubprocess API

It's less screwing around with GPtrArray in most cases.
This commit is contained in:
Colin Walters 2012-12-21 11:52:28 -05:00
parent b3d8c8c0e5
commit 19df2d372d
8 changed files with 44 additions and 94 deletions

@ -1 +1 @@
Subproject commit 0734be8c1211ba04ecdd14ff30b6c07dbf3b9a84 Subproject commit b11ad335f459e3c61b317308da57de441660efd0

View File

@ -26,31 +26,6 @@
#include <string.h> #include <string.h>
gboolean
ot_spawn_sync_checked (const char *cwd,
char **argv,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
gs_unref_object GSSubprocessContext *context = NULL;
gs_unref_object GSSubprocess *proc = NULL;
context = gs_subprocess_context_new (argv);
if (cwd)
gs_subprocess_context_set_cwd (context, cwd);
if ((proc = gs_subprocess_new (context, cancellable, error)) == NULL)
goto out;
if (!gs_subprocess_wait_sync_check (proc, cancellable, error))
goto out;
ret = TRUE;
out:
return ret;
}
/** /**
* ot_thread_pool_new_nproc: * ot_thread_pool_new_nproc:
* *

View File

@ -27,11 +27,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
gboolean ot_spawn_sync_checked (const char *cwd,
char **argv,
GCancellable *cancellable,
GError **error);
GThreadPool * ot_thread_pool_new_nproc (GFunc func, GThreadPool * ot_thread_pool_new_nproc (GFunc func,
gpointer user_data); gpointer user_data);

View File

@ -579,19 +579,16 @@ do_update_kernel (OtAdminDeploy *self,
GError **error) GError **error)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
ot_lptrarray GPtrArray *args = NULL;
args = g_ptr_array_new (); if (!gs_subprocess_simple_run_sync (gs_file_get_path_cached (self->ostree_dir),
ot_ptrarray_add_many (args, "ostree", "admin", GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
"--ostree-dir", gs_file_get_path_cached (self->ostree_dir), cancellable, error,
"update-kernel", "ostree", "admin",
gs_file_get_path_cached (deploy_path), NULL); "--ostree-dir", gs_file_get_path_cached (self->ostree_dir),
if (opt_no_kernel) "update-kernel",
g_ptr_array_add (args, "--modules-only"); gs_file_get_path_cached (deploy_path),
g_ptr_array_add (args, NULL); opt_no_kernel ? "--modules-only" : NULL,
NULL))
if (!ot_spawn_sync_checked (gs_file_get_path_cached (self->ostree_dir),
(char**)args->pdata, cancellable, error))
goto out; goto out;
ret = TRUE; ret = TRUE;

View File

@ -156,18 +156,15 @@ ot_admin_builtin_prune (int argc, char **argv, GFile *ostree_dir, GError **error
if (!opt_no_repo_prune) if (!opt_no_repo_prune)
{ {
ot_lptrarray GPtrArray *prune_argv = NULL;
ot_lfree char *repo_arg = NULL; ot_lfree char *repo_arg = NULL;
repo_arg = g_strconcat ("--repo=", gs_file_get_path_cached (repo_path), NULL); repo_arg = g_strconcat ("--repo=", gs_file_get_path_cached (repo_path), NULL);
prune_argv = g_ptr_array_new ();
ot_ptrarray_add_many (prune_argv, "ostree", repo_arg, "prune", "--refs-only", "--depth=0", NULL);
g_ptr_array_add (prune_argv, NULL);
if (!ot_spawn_sync_checked (gs_file_get_path_cached (ostree_dir), if (!gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir),
(char**)prune_argv->pdata, GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
cancellable, error)) cancellable, error,
"ostree", repo_arg, "prune", "--refs-only",
"--depth=0", NULL))
goto out; goto out;
} }

View File

@ -144,34 +144,27 @@ ot_admin_builtin_pull_deploy (int argc, char **argv, GFile *ostree_dir, GError *
remote_name = remote_name_from_path (ostree_repo_get_config (repo), remote_name = remote_name_from_path (ostree_repo_get_config (repo),
deploy_name); deploy_name);
subproc_args = g_ptr_array_new ();
{ {
ot_lfree char *repo_arg = g_strconcat ("--repo=", ot_lfree char *repo_arg = g_strconcat ("--repo=",
gs_file_get_path_cached (repo_path), gs_file_get_path_cached (repo_path),
NULL); NULL);
ot_ptrarray_add_many (subproc_args, "ostree", "pull", repo_arg, remote_name, NULL);
g_ptr_array_add (subproc_args, NULL);
if (!ot_spawn_sync_checked (gs_file_get_path_cached (ostree_dir), if (!gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir),
(char**)subproc_args->pdata, GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
cancellable, error)) cancellable, error,
"ostree", "pull", repo_arg, remote_name, NULL))
goto out; goto out;
g_clear_pointer (&subproc_args, (GDestroyNotify)g_ptr_array_unref);
} }
subproc_args = g_ptr_array_new ();
{ {
ot_lfree char *opt_ostree_dir_arg = g_strconcat ("--ostree-dir=", ot_lfree char *opt_ostree_dir_arg = g_strconcat ("--ostree-dir=",
gs_file_get_path_cached (ostree_dir), gs_file_get_path_cached (ostree_dir),
NULL); NULL);
ot_ptrarray_add_many (subproc_args, "ostree", "admin", opt_ostree_dir_arg, "deploy", if (!gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir),
deploy_name, NULL); GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
g_ptr_array_add (subproc_args, NULL); cancellable, error,
"ostree", "admin", opt_ostree_dir_arg, "deploy",
if (!ot_spawn_sync_checked (gs_file_get_path_cached (ostree_dir), deploy_name, NULL))
(char**)subproc_args->pdata,
cancellable, error))
goto out; goto out;
} }

View File

@ -84,7 +84,6 @@ update_initramfs (OtAdminUpdateKernel *self,
initramfs_file = ot_gfile_from_build_path ("/boot", initramfs_name, NULL); initramfs_file = ot_gfile_from_build_path ("/boot", initramfs_name, NULL);
if (!g_file_query_exists (initramfs_file, NULL)) if (!g_file_query_exists (initramfs_file, NULL))
{ {
ot_lptrarray GPtrArray *mkinitramfs_args = NULL;
ot_lobj GFile *tmpdir = NULL; ot_lobj GFile *tmpdir = NULL;
ot_lfree char *initramfs_tmp_path = NULL; ot_lfree char *initramfs_tmp_path = NULL;
ot_lobj GFile *ostree_vardir = NULL; ot_lobj GFile *ostree_vardir = NULL;
@ -110,27 +109,24 @@ update_initramfs (OtAdminUpdateKernel *self,
if (!g_output_stream_close (tmp_log_out, cancellable, error)) if (!g_output_stream_close (tmp_log_out, cancellable, error))
goto out; goto out;
mkinitramfs_args = g_ptr_array_new ();
/* Note: the hardcoded /tmp path below is not actually a /* Note: the hardcoded /tmp path below is not actually a
* security flaw, because we've bind-mounted dracut's view * security flaw, because we've bind-mounted dracut's view
* of /tmp to the securely-created tmpdir above. * of /tmp to the securely-created tmpdir above.
*/ */
ot_ptrarray_add_many (mkinitramfs_args,
"linux-user-chroot",
"--mount-readonly", "/",
"--mount-proc", "/proc",
"--mount-bind", "/dev", "/dev",
"--mount-bind", gs_file_get_path_cached (ostree_vardir), "/var",
"--mount-bind", gs_file_get_path_cached (tmpdir), "/tmp",
"--mount-bind", gs_file_get_path_cached (ostree_moduledir), "/lib/modules",
deploy_path,
"dracut", "-f", "/tmp/initramfs-ostree.img", release,
NULL);
g_ptr_array_add (mkinitramfs_args, NULL);
g_print ("Generating initramfs using %s...\n", deploy_path); g_print ("Generating initramfs using %s...\n", deploy_path);
if (!ot_spawn_sync_checked (NULL, (char**)mkinitramfs_args->pdata, if (!gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
cancellable, error)) cancellable, error,
"linux-user-chroot",
"--mount-readonly", "/",
"--mount-proc", "/proc",
"--mount-bind", "/dev", "/dev",
"--mount-bind", gs_file_get_path_cached (ostree_vardir), "/var",
"--mount-bind", gs_file_get_path_cached (tmpdir), "/tmp",
"--mount-bind", gs_file_get_path_cached (ostree_moduledir), "/lib/modules",
deploy_path,
"dracut", "-f", "/tmp/initramfs-ostree.img", release,
NULL))
goto out; goto out;
initramfs_tmp_file = g_file_get_child (tmpdir, "initramfs-ostree.img"); initramfs_tmp_file = g_file_get_child (tmpdir, "initramfs-ostree.img");
@ -241,7 +237,6 @@ update_grub (OtAdminUpdateKernel *self,
if (!have_grub_entry) if (!have_grub_entry)
{ {
ot_lptrarray GPtrArray *grubby_args = NULL;
ot_lfree char *add_kernel_arg = NULL; ot_lfree char *add_kernel_arg = NULL;
ot_lfree char *initramfs_arg = NULL; ot_lfree char *initramfs_arg = NULL;
ot_lobj GFile *kernel_path = NULL; ot_lobj GFile *kernel_path = NULL;
@ -257,16 +252,13 @@ update_grub (OtAdminUpdateKernel *self,
goto out; goto out;
} }
grubby_args = g_ptr_array_new ();
add_kernel_arg = g_strconcat ("--add-kernel=", gs_file_get_path_cached (kernel_path), NULL); add_kernel_arg = g_strconcat ("--add-kernel=", gs_file_get_path_cached (kernel_path), NULL);
initramfs_arg = g_strconcat ("--initrd=", "/boot/initramfs-ostree-", release, ".img", NULL); initramfs_arg = g_strconcat ("--initrd=", "/boot/initramfs-ostree-", release, ".img", NULL);
ot_ptrarray_add_many (grubby_args, "grubby", "--grub", add_kernel_arg, initramfs_arg,
"--copy-default", "--title=OSTree", NULL);
g_ptr_array_add (grubby_args, NULL);
g_print ("Adding OSTree grub entry...\n"); g_print ("Adding OSTree grub entry...\n");
if (!ot_spawn_sync_checked (NULL, (char**)grubby_args->pdata, if (!gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
cancellable, error)) cancellable, error,
"grubby", "--grub", add_kernel_arg, initramfs_arg,
"--copy-default", "--title=OSTree", NULL))
goto out; goto out;
} }
else else

View File

@ -55,9 +55,10 @@ ot_admin_ensure_initialized (GFile *ostree_dir,
{ {
ot_lfree char *opt_repo_arg = g_strdup_printf ("--repo=%s/repo", ot_lfree char *opt_repo_arg = g_strdup_printf ("--repo=%s/repo",
gs_file_get_path_cached (ostree_dir)); gs_file_get_path_cached (ostree_dir));
const char *child_argv[] = { "ostree", opt_repo_arg, "init", NULL };
if (!ot_spawn_sync_checked (NULL, (char**)child_argv, cancellable, error)) if (!gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
cancellable, error,
"ostree", opt_repo_arg, "init", NULL))
{ {
g_prefix_error (error, "Failed to initialize repository: "); g_prefix_error (error, "Failed to initialize repository: ");
goto out; goto out;