summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2021-01-31 19:18:20 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2021-01-31 19:18:20 +0100
commitb9e28bd7990b597d707fb9a81880dc14accc9c41 (patch)
treefbb54d67bac841728450b62cd192095b9d3993b5 /src/main.rs
parent6eb0851420b358132dd8a72312b25a1f7efd02de (diff)
downloadrebel-b9e28bd7990b597d707fb9a81880dc14accc9c41.tar
rebel-b9e28bd7990b597d707fb9a81880dc14accc9c41.zip
Unshare/subuid handling
Buildah is too slow for our usecase. Handle userns setup ourselves, so we can call runc directly.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 72178be..8d4787d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,12 +1,47 @@
mod executor;
+mod prepared_command;
mod recipe;
mod resolve;
mod runner;
mod types;
+mod unshare;
+mod util;
-use std::path::Path;
+use nix::{
+ mount::{self, MsFlags},
+ unistd,
+};
+use std::{io::Result, path::Path};
use types::*;
+use util::ToIOResult;
+
+fn mount_buildtmp() -> Result<()> {
+ mount::mount::<_, _, _, str>(
+ Some("buildtmp"),
+ "build/tmp",
+ Some("tmpfs"),
+ MsFlags::empty(),
+ None,
+ )
+ .to_io_result()
+}
+
+fn exec_shell() -> Result<std::convert::Infallible> {
+ let bin_sh = std::ffi::CString::new("/bin/sh").unwrap();
+ unistd::execv(&bin_sh, &[&bin_sh]).to_io_result()
+}
+
+fn execute(mut exc: executor::Executor) -> Result<()> {
+ unshare::unshare()?;
+ mount_buildtmp()?;
+
+ exc.run()?;
+
+ exec_shell()?;
+
+ Ok(())
+}
fn main() {
let recipes = recipe::read_recipes(Path::new("examples")).unwrap();
@@ -29,10 +64,9 @@ fn main() {
std::process::exit(1);
}
let taskset = rsv.to_taskset();
- let mut executor = executor::Executor::new(&tasks, taskset);
+ let exc = executor::Executor::new(&tasks, taskset);
- let result = executor.run();
- if let Err(error) = result {
+ if let Err(error) = execute(exc) {
eprintln!("{}", error);
std::process::exit(1);
}