Skip to content

Commit b212029

Browse files
committed
install: Centralize PID1 definition
Hooray for `const`. Signed-off-by: Colin Walters <walters@verbum.org>
1 parent f8979ab commit b212029

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/src/install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use ostree_ext::ostree;
4040
use ostree_ext::prelude::Cast;
4141
use ostree_ext::sysroot::SysrootLock;
4242
use rustix::fs::{FileTypeExt, MetadataExt as _};
43-
use rustix::thread::Pid;
4443
use serde::{Deserialize, Serialize};
4544

4645
use self::baseline::InstallBlockDeviceOpts;
@@ -1641,9 +1640,10 @@ pub(crate) async fn install_to_filesystem(
16411640
&& fsopts.root_path.as_str() == ALONGSIDE_ROOT_MOUNT
16421641
&& !fsopts.root_path.try_exists()?
16431642
{
1643+
tracing::debug!("Mounting host / to {ALONGSIDE_ROOT_MOUNT}");
16441644
std::fs::create_dir(ALONGSIDE_ROOT_MOUNT)?;
16451645
crate::mount::bind_mount_from_pidns(
1646-
Pid::from_raw(1).unwrap(),
1646+
crate::mount::PID1,
16471647
"/".into(),
16481648
ALONGSIDE_ROOT_MOUNT.into(),
16491649
true,

lib/src/mount.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ use serde::Deserialize;
2323

2424
use crate::task::Task;
2525

26+
/// Well known identifier for pid 1
27+
pub(crate) const PID1: Pid = const {
28+
match Pid::from_raw(1) {
29+
Some(v) => v,
30+
None => panic!("Expected to parse pid1"),
31+
}
32+
};
33+
2634
#[derive(Deserialize, Debug)]
2735
#[serde(rename_all = "kebab-case")]
2836
#[allow(dead_code)]
@@ -266,5 +274,5 @@ pub(crate) fn ensure_mirrored_host_mount(path: impl AsRef<Utf8Path>) -> Result<(
266274
return Ok(());
267275
}
268276
tracing::debug!("Propagating host mount: {path}");
269-
bind_mount_from_pidns(Pid::from_raw(1).unwrap(), path, path, true)
277+
bind_mount_from_pidns(PID1, path, path, true)
270278
}

0 commit comments

Comments
 (0)