diff options
Diffstat (limited to 'src/runner/runc')
-rw-r--r-- | src/runner/runc/init.rs | 47 | ||||
-rw-r--r-- | src/runner/runc/run.rs | 18 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/runner/runc/init.rs b/src/runner/runc/init.rs new file mode 100644 index 0000000..02b89e4 --- /dev/null +++ b/src/runner/runc/init.rs @@ -0,0 +1,47 @@ +use std::io; + +use nix::{ + mount::{self, MsFlags}, + sched::{self, CloneFlags}, +}; +use serde::{Deserialize, Serialize}; + +fn mount_buildtmp() -> nix::Result<()> { + mount::mount::<_, _, _, str>( + Some("buildtmp"), + "build/tmp", + Some("tmpfs"), + MsFlags::empty(), + None, + ) +} + +#[derive(Debug, Deserialize, Serialize)] +pub enum Error { + Code(i32), + String(String), +} + +impl From<nix::Error> for Error { + fn from(error: nix::Error) -> Self { + match error { + nix::Error::Sys(code) => Error::Code(code as i32), + _ => Error::String(error.to_string()), + } + } +} + +impl From<Error> for io::Error { + fn from(error: Error) -> Self { + match error { + Error::Code(code) => io::Error::from_raw_os_error(code), + Error::String(string) => io::Error::new(io::ErrorKind::Other, string), + } + } +} + +pub fn runc_initialize() -> Result<(), Error> { + sched::unshare(CloneFlags::CLONE_NEWUSER | CloneFlags::CLONE_NEWNS)?; + mount_buildtmp()?; + Ok(()) +} diff --git a/src/runner/runc/run.rs b/src/runner/runc/run.rs new file mode 100644 index 0000000..2d13330 --- /dev/null +++ b/src/runner/runc/run.rs @@ -0,0 +1,18 @@ +use std::io; + +use serde::{Deserialize, Serialize}; + +use crate::types::*; +#[derive(Debug, Deserialize, Serialize)] +pub struct Error; + +impl From<Error> for io::Error { + fn from(_: Error) -> Self { + io::Error::new(io::ErrorKind::Other, "Failed to run task") + } +} + +pub fn handle_task(task: TaskRef, task_def: Task) -> Result<(), Error> { + println!("{}:\n\t{:?}", task, task_def); + Ok(()) +} |