deb: create special device nodes inside chroot
All checks were successful
CI / build (push) Successful in 9m5s
All checks were successful
CI / build (push) Successful in 9m5s
This commit is contained in:
@@ -102,6 +102,10 @@ impl EphemeralContextGuard {
|
|||||||
log::debug!("Extracting chroot tarball to {}...", chroot_path.display());
|
log::debug!("Extracting chroot tarball to {}...", chroot_path.display());
|
||||||
Self::extract_tarball(&tarball_path, chroot_path)?;
|
Self::extract_tarball(&tarball_path, chroot_path)?;
|
||||||
|
|
||||||
|
// Create device nodes in the chroot
|
||||||
|
log::debug!("Creating device nodes in chroot...");
|
||||||
|
Self::create_device_nodes(chroot_path)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,6 +171,57 @@ impl EphemeralContextGuard {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_device_nodes(chroot_path: &Path) -> Result<(), Box<dyn Error>> {
|
||||||
|
let ctx = context::current();
|
||||||
|
let dev_null_path = chroot_path.join("dev/null");
|
||||||
|
let dev_zero_path = chroot_path.join("dev/zero");
|
||||||
|
|
||||||
|
// Ensure /dev directory exists
|
||||||
|
fs::create_dir_all(chroot_path.join("dev"))?;
|
||||||
|
|
||||||
|
// Remove existing device nodes if they exist
|
||||||
|
let _ = ctx
|
||||||
|
.command("rm")
|
||||||
|
.arg("-f")
|
||||||
|
.arg(dev_null_path.to_string_lossy().to_string())
|
||||||
|
.status();
|
||||||
|
|
||||||
|
let _ = ctx
|
||||||
|
.command("rm")
|
||||||
|
.arg("-f")
|
||||||
|
.arg(dev_zero_path.to_string_lossy().to_string())
|
||||||
|
.status();
|
||||||
|
|
||||||
|
// Create new device nodes using fakeroot and mknod
|
||||||
|
let status_null = ctx
|
||||||
|
.command("sudo")
|
||||||
|
.arg("mknod")
|
||||||
|
.arg("-m")
|
||||||
|
.arg("666")
|
||||||
|
.arg(dev_null_path.to_string_lossy().to_string())
|
||||||
|
.arg("c")
|
||||||
|
.arg("1")
|
||||||
|
.arg("3")
|
||||||
|
.status()?;
|
||||||
|
|
||||||
|
let status_zero = ctx
|
||||||
|
.command("sudo")
|
||||||
|
.arg("mknod")
|
||||||
|
.arg("-m")
|
||||||
|
.arg("666")
|
||||||
|
.arg(dev_zero_path.to_string_lossy().to_string())
|
||||||
|
.arg("c")
|
||||||
|
.arg("1")
|
||||||
|
.arg("5")
|
||||||
|
.status()?;
|
||||||
|
|
||||||
|
if !status_null.success() || !status_zero.success() {
|
||||||
|
return Err("Failed to create device nodes".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for EphemeralContextGuard {
|
impl Drop for EphemeralContextGuard {
|
||||||
|
|||||||
Reference in New Issue
Block a user