boot-tree: live systemd boot dependency tree on a dedicated VT
This commit is contained in:
commit
097caf81a2
24 files changed
+4817
No files matched your search
@@ -0,0 +1,35 @@
|
||||
use std::{os::fd::OwnedFd, path::Path};
|
||||
|
||||
use rustix::{
|
||||
fs::{Mode, OFlags, open},
|
||||
io::Errno,
|
||||
process::{chdir, chroot, fchdir},
|
||||
};
|
||||
|
||||
const SYSROOT: &str = "/sysroot";
|
||||
const INITRD_RELEASE: &str = "/etc/initrd-release";
|
||||
|
||||
pub fn running_in_initrd() -> bool {
|
||||
Path::new(INITRD_RELEASE).exists()
|
||||
}
|
||||
|
||||
pub struct Sysroot {
|
||||
directory: OwnedFd,
|
||||
}
|
||||
|
||||
impl Sysroot {
|
||||
pub fn hold() -> Result<Self, Errno> {
|
||||
let directory = open(
|
||||
SYSROOT,
|
||||
OFlags::DIRECTORY | OFlags::RDONLY | OFlags::CLOEXEC,
|
||||
Mode::empty(),
|
||||
)?;
|
||||
Ok(Self { directory })
|
||||
}
|
||||
|
||||
pub fn enter(self) -> Result<(), Errno> {
|
||||
fchdir(&self.directory)?;
|
||||
chroot(".")?;
|
||||
chdir("/")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user