Skip to content

Commit aa9bc7c

Browse files
committed
install: Split out helper to detect systemd as pid 1
Prep for usage elsewhere. Signed-off-by: Colin Walters <[email protected]>
1 parent 652771d commit aa9bc7c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/src/install.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,7 @@ pub(crate) fn finalize_filesystem(fs: &Utf8Path) -> Result<()> {
646646
Ok(())
647647
}
648648

649-
/// Preparation for an install; validates and prepares some (thereafter immutable) global state.
650-
async fn prepare_install(
651-
config_opts: InstallConfigOpts,
652-
target_opts: InstallTargetOpts,
653-
) -> Result<Arc<State>> {
654-
// We need full root privileges, i.e. --privileged in podman
655-
crate::cli::require_root()?;
649+
fn require_systemd_pid1() -> Result<()> {
656650
// We require --pid=host
657651
let pid = std::fs::read_link("/proc/1/exe").context("reading /proc/1/exe")?;
658652
let pid = pid
@@ -661,6 +655,17 @@ async fn prepare_install(
661655
if !pid.contains("systemd") {
662656
anyhow::bail!("This command must be run with --pid=host")
663657
}
658+
Ok(())
659+
}
660+
661+
/// Preparation for an install; validates and prepares some (thereafter immutable) global state.
662+
async fn prepare_install(
663+
config_opts: InstallConfigOpts,
664+
target_opts: InstallTargetOpts,
665+
) -> Result<Arc<State>> {
666+
// We need full root privileges, i.e. --privileged in podman
667+
crate::cli::require_root()?;
668+
require_systemd_pid1()?;
664669

665670
// This command currently *must* be run inside a privileged container.
666671
let container_info = crate::containerenv::get_container_execution_info()?;

0 commit comments

Comments
 (0)