Skip to content

Commit

Permalink
cli: Detect non-ostree and error out earlier
Browse files Browse the repository at this point in the history
Before we even check for root, verify that we are on an ostree-booted
host.

Signed-off-by: Colin Walters <walters@verbum.org>
  • Loading branch information
cgwalters committed May 22, 2024
1 parent 6a19638 commit 5bf05e5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ pub(crate) async fn prepare_for_write() -> Result<()> {
if ostree_ext::container_utils::running_in_container() {
anyhow::bail!("Detected container; this command requires a booted host system.");
}
if !std::path::Path::new("/run/ostree-booted").exists() {
anyhow::bail!("This command requires an ostree-booted host system");
}
crate::cli::require_root()?;
ensure_self_unshared_mount_namespace().await?;
if crate::lsm::selinux_enabled()? && !crate::lsm::selinux_ensure_install()? {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/privtests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub(crate) fn impl_run_container() -> Result<()> {
assert!(!st.success());
let stderr = String::from_utf8(o.stderr)?;
assert!(
stderr.contains("This command requires full root privileges"),
stderr.contains("this command requires a booted host system"),
"stderr: {stderr}",
);
}
Expand Down

0 comments on commit 5bf05e5

Please sign in to comment.