Skip to content

Commit

Permalink
install: Centralize PID1 definition
Browse files Browse the repository at this point in the history
Hooray for `const`.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Nov 25, 2024
1 parent 5b748d4 commit 0cf5516
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use ostree_ext::ostree;
use ostree_ext::prelude::Cast;
use ostree_ext::sysroot::SysrootLock;
use rustix::fs::{FileTypeExt, MetadataExt as _};
use rustix::thread::Pid;
use serde::{Deserialize, Serialize};

use self::baseline::InstallBlockDeviceOpts;
Expand Down Expand Up @@ -1641,9 +1640,10 @@ pub(crate) async fn install_to_filesystem(
&& fsopts.root_path.as_str() == ALONGSIDE_ROOT_MOUNT
&& !fsopts.root_path.try_exists()?
{
tracing::debug!("Mounting host / to {ALONGSIDE_ROOT_MOUNT}");
std::fs::create_dir(ALONGSIDE_ROOT_MOUNT)?;
crate::mount::bind_mount_from_pidns(
Pid::from_raw(1).unwrap(),
crate::mount::PID1,
"/".into(),
ALONGSIDE_ROOT_MOUNT.into(),
true,
Expand Down
10 changes: 9 additions & 1 deletion lib/src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ use serde::Deserialize;

use crate::task::Task;

/// Well known identifier for pid 1
pub(crate) const PID1: Pid = const {
match Pid::from_raw(1) {
Some(v) => v,
None => panic!("Expected to parse pid1"),
}
};

#[derive(Deserialize, Debug)]
#[serde(rename_all = "kebab-case")]
#[allow(dead_code)]
Expand Down Expand Up @@ -266,5 +274,5 @@ pub(crate) fn ensure_mirrored_host_mount(path: impl AsRef<Utf8Path>) -> Result<(
return Ok(());
}
tracing::debug!("Propagating host mount: {path}");
bind_mount_from_pidns(Pid::from_raw(1).unwrap(), path, path, true)
bind_mount_from_pidns(PID1, path, path, true)
}

0 comments on commit 0cf5516

Please sign in to comment.