diff options
author | Colin Walters <walters@verbum.org> | 2021-11-22 13:35:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-22 13:35:28 -0500 |
commit | 48dfff27541250c4063bc65fa11d7529897719af (patch) | |
tree | 75d36604b332137eff08f1a64ec87ee8f0907c7c | |
parent | f552e30c0bb8096ca21dc3f7723c9828e4ef3e5c (diff) | |
parent | 947acbf178152f860d3d8f9896b2ce51645419f6 (diff) | |
download | ostree-48dfff27541250c4063bc65fa11d7529897719af.tar.gz |
Merge pull request #2486 from jlebon/pr/remount-ostree
app: Only remount /sysroot if needed
-rw-r--r-- | src/ostree/ot-main.c | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c index bbaba8b0..849a74ef 100644 --- a/src/ostree/ot-main.c +++ b/src/ostree/ot-main.c @@ -238,7 +238,7 @@ ostree_run (int argc, return 0; } -/* Process a --repo arg; used below, and for the remote builtins */ +/* Process a --repo arg. */ static OstreeRepo * parse_repo_option (GOptionContext *context, const char *repo_path, @@ -248,19 +248,6 @@ parse_repo_option (GOptionContext *context, { g_autoptr(OstreeRepo) repo = NULL; - /* This is a bit of a brutal hack; we set up a mount - * namespace if it appears that we may need it. It'd - * be better to do this more precisely in the future. - */ - gboolean setup_ns = FALSE; - if (!maybe_setup_mount_namespace (&setup_ns, error)) - return FALSE; - if (setup_ns) - { - if (mount ("/sysroot", "/sysroot", NULL, MS_REMOUNT | MS_SILENT, NULL) < 0) - return glnx_null_throw_errno_prefix (error, "Remounting /sysroot read-write"); - } - if (repo_path == NULL) { g_autoptr(GError) local_error = NULL; @@ -300,6 +287,43 @@ parse_repo_option (GOptionContext *context, return g_steal_pointer (&repo); } +/* Process a --repo arg, determining if we should remount /sysroot; used below, and for the remote builtins */ +static OstreeRepo * +parse_repo_option_and_maybe_remount (GOptionContext *context, + const char *repo_path, + gboolean skip_repo_open, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(OstreeRepo) repo = parse_repo_option (context, repo_path, skip_repo_open, cancellable, error); + if (!repo) + return NULL; + + /* This is a bit of a brutal hack; we set up a mount + * namespace if it appears that we may need it. It'd + * be better to do this more precisely in the future. + */ + if (ostree_repo_is_system (repo) && !ostree_repo_is_writable (repo, NULL)) + { + gboolean setup_ns = FALSE; + if (!maybe_setup_mount_namespace (&setup_ns, error)) + return FALSE; + if (setup_ns) + { + if (mount ("/sysroot", "/sysroot", NULL, MS_REMOUNT | MS_SILENT, NULL) < 0) + return glnx_null_throw_errno_prefix (error, "Remounting /sysroot read-write"); + + /* Reload the repo so it's actually writable. */ + g_clear_pointer (&repo, g_object_unref); + repo = parse_repo_option (context, repo_path, skip_repo_open, cancellable, error); + if (!repo) + return NULL; + } + } + + return g_steal_pointer (&repo); +} + /* Used by the remote builtins which are special in taking --sysroot or --repo */ gboolean ostree_parse_sysroot_or_repo_option (GOptionContext *context, @@ -323,7 +347,7 @@ ostree_parse_sysroot_or_repo_option (GOptionContext *context, } else { - repo = parse_repo_option (context, repo_path, FALSE, cancellable, error); + repo = parse_repo_option_and_maybe_remount (context, repo_path, FALSE, cancellable, error); if (!repo) return FALSE; } @@ -424,8 +448,8 @@ ostree_option_context_parse (GOptionContext *context, if (!(flags & OSTREE_BUILTIN_FLAG_NO_REPO)) { - repo = parse_repo_option (context, opt_repo, (flags & OSTREE_BUILTIN_FLAG_NO_CHECK) > 0, - cancellable, error); + repo = parse_repo_option_and_maybe_remount (context, opt_repo, (flags & OSTREE_BUILTIN_FLAG_NO_CHECK) > 0, + cancellable, error); if (!repo) return FALSE; } |