1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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(())
}
|