diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-10-24 22:11:51 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-10-24 22:11:51 +0200 |
commit | 524985f9449eb2f3a1d01b5f88dc74123d40c43a (patch) | |
tree | ed3659a099b207e0b62198b2d73703af987b6a53 | |
parent | e5dc4ac22715225740544a799c06f0172d0e96d0 (diff) | |
download | rebel-524985f9449eb2f3a1d01b5f88dc74123d40c43a.tar rebel-524985f9449eb2f3a1d01b5f88dc74123d40c43a.zip |
Move util modules to container runner
The ipc module was unused and is removed completely.
-rw-r--r-- | src/runner/container/init.rs | 8 | ||||
-rw-r--r-- | src/runner/container/jobserver.rs | 3 | ||||
-rw-r--r-- | src/runner/container/mod.rs | 9 | ||||
-rw-r--r-- | src/runner/container/ns.rs | 3 | ||||
-rw-r--r-- | src/runner/container/tar.rs | 9 | ||||
-rw-r--r-- | src/runner/container/task.rs | 11 | ||||
-rw-r--r-- | src/runner/container/util/cjson.rs (renamed from src/util/cjson.rs) | 0 | ||||
-rw-r--r-- | src/runner/container/util/clone.rs (renamed from src/util/clone.rs) | 0 | ||||
-rw-r--r-- | src/runner/container/util/fs.rs (renamed from src/util/fs.rs) | 0 | ||||
-rw-r--r-- | src/runner/container/util/mod.rs | 42 | ||||
-rw-r--r-- | src/runner/container/util/unix.rs (renamed from src/util/unix.rs) | 0 | ||||
-rw-r--r-- | src/util/ipc.rs | 23 | ||||
-rw-r--r-- | src/util/mod.rs | 43 |
13 files changed, 62 insertions, 89 deletions
diff --git a/src/runner/container/init.rs b/src/runner/container/init.rs index a1a1d49..8ebbdd0 100644 --- a/src/runner/container/init.rs +++ b/src/runner/container/init.rs @@ -2,12 +2,8 @@ use std::fs::File; use nix::mount::{self, MsFlags}; -use crate::{ - paths, - util::{error::*, fs}, -}; - -use super::tar; +use super::{tar, util::fs}; +use crate::{paths, util::error::*}; fn prepare_rootfs(rootfs: &str) -> Result<()> { tar::unpack(File::open(paths::ROOTFS_ARCHIVE)?, rootfs) diff --git a/src/runner/container/jobserver.rs b/src/runner/container/jobserver.rs index 29fb064..b8fc9f3 100644 --- a/src/runner/container/jobserver.rs +++ b/src/runner/container/jobserver.rs @@ -2,7 +2,8 @@ use std::{os::unix::prelude::RawFd, slice}; use nix::{errno::Errno, fcntl::OFlag, poll, unistd}; -use crate::util::{error::*, unix}; +use super::util::unix; +use crate::util::error::*; #[derive(Debug)] pub struct Jobserver { diff --git a/src/runner/container/mod.rs b/src/runner/container/mod.rs index 02a493b..17f4042 100644 --- a/src/runner/container/mod.rs +++ b/src/runner/container/mod.rs @@ -3,6 +3,7 @@ mod jobserver; mod ns; mod tar; mod task; +mod util; use capctl::prctl; use ipc_channel::ipc; @@ -13,11 +14,11 @@ use nix::{ }; use serde::{Deserialize, Serialize}; -use self::jobserver::Jobserver; -use crate::{ - runner, - util::{clone, error::*, unix}, +use self::{ + jobserver::Jobserver, + util::{clone, unix}, }; +use crate::{runner, util::error::*}; #[derive(Debug, Deserialize, Serialize)] enum Message { diff --git a/src/runner/container/ns.rs b/src/runner/container/ns.rs index 1d22bd0..f0abb6f 100644 --- a/src/runner/container/ns.rs +++ b/src/runner/container/ns.rs @@ -4,7 +4,8 @@ use nix::{ unistd::{self, Gid, Pid, Uid}, }; -use crate::util::{clone, error::*}; +use super::util::clone; +use crate::util::error::*; pub fn mount_proc() { mount::mount::<_, _, _, str>(Some("proc"), "/proc", Some("proc"), MsFlags::empty(), None) diff --git a/src/runner/container/tar.rs b/src/runner/container/tar.rs index a0bbd3c..2b61520 100644 --- a/src/runner/container/tar.rs +++ b/src/runner/container/tar.rs @@ -12,12 +12,11 @@ use nix::{ sys::wait, }; -use crate::{ - paths, - util::{error::*, fs, Checkable}, +use super::{ + ns, + util::{fs, Checkable}, }; - -use super::ns; +use crate::{paths, util::error::*}; pub fn pack<W: Write, P: AsRef<Path>>(archive: &mut W, source: P) -> Result<()> { let (mut piper, pipew) = fs::pipe()?; diff --git a/src/runner/container/task.rs b/src/runner/container/task.rs index 2b79f54..39dcd81 100644 --- a/src/runner/container/task.rs +++ b/src/runner/container/task.rs @@ -17,13 +17,12 @@ use nix::{ use serde::Serialize; use tee_readwrite::TeeWriter; -use crate::{ - paths, runner, - types::*, - util::{cjson, error::*, fs, Checkable}, +use super::{ + jobserver::Jobserver, + ns, tar, + util::{cjson, fs, Checkable}, }; - -use super::{jobserver::Jobserver, ns, tar}; +use crate::{paths, runner, types::*, util::error::*}; const BUILD_UID: Uid = Uid::from_raw(1000); const BUILD_GID: Gid = Gid::from_raw(1000); diff --git a/src/util/cjson.rs b/src/runner/container/util/cjson.rs index 5990943..5990943 100644 --- a/src/util/cjson.rs +++ b/src/runner/container/util/cjson.rs diff --git a/src/util/clone.rs b/src/runner/container/util/clone.rs index 4835b53..4835b53 100644 --- a/src/util/clone.rs +++ b/src/runner/container/util/clone.rs diff --git a/src/util/fs.rs b/src/runner/container/util/fs.rs index cfc7610..cfc7610 100644 --- a/src/util/fs.rs +++ b/src/runner/container/util/fs.rs diff --git a/src/runner/container/util/mod.rs b/src/runner/container/util/mod.rs new file mode 100644 index 0000000..eff589d --- /dev/null +++ b/src/runner/container/util/mod.rs @@ -0,0 +1,42 @@ +pub mod cjson; +pub mod clone; +pub mod fs; +pub mod unix; + +use std::{ + io::{Error, ErrorKind, Result}, + process::ExitStatus, +}; + +use nix::sys::wait; + +pub trait Checkable { + fn check(&self) -> Result<()>; +} + +impl Checkable for ExitStatus { + fn check(&self) -> Result<()> { + if self.success() { + Ok(()) + } else { + Err(Error::new( + ErrorKind::Other, + format!("Process exited with {}", self), + )) + } + } +} + +impl Checkable for wait::WaitStatus { + fn check(&self) -> Result<()> { + let message = match self { + wait::WaitStatus::Exited(_, 0) => return Ok(()), + wait::WaitStatus::Exited(_, code) => format!("Process exited with exit code: {}", code), + wait::WaitStatus::Signaled(_, signal, _) => { + format!("Process exited with signal: {}", signal) + } + _ => format!("Process in unexpected status: {:?}", self), + }; + Err(Error::new(ErrorKind::Other, message)) + } +} diff --git a/src/util/unix.rs b/src/runner/container/util/unix.rs index 1b7722c..1b7722c 100644 --- a/src/util/unix.rs +++ b/src/runner/container/util/unix.rs diff --git a/src/util/ipc.rs b/src/util/ipc.rs deleted file mode 100644 index 45fd823..0000000 --- a/src/util/ipc.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::result; - -use ipc_channel::ipc; - -use crate::util::error::*; - -pub trait CheckDisconnect { - type Output; - - fn check_disconnect(self) -> Result<Self::Output>; -} - -impl<T> CheckDisconnect for result::Result<T, ipc::IpcError> { - type Output = result::Result<(), T>; - - fn check_disconnect(self) -> Result<Self::Output> { - match self { - Ok(v) => Ok(Err(v)), - Err(ipc::IpcError::Disconnected) => Ok(Ok(())), - Err(error) => Err(Error::new(error)), - } - } -} diff --git a/src/util/mod.rs b/src/util/mod.rs index bd6756f..a91e735 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,44 +1 @@ -pub mod cjson; -pub mod clone; pub mod error; -pub mod fs; -pub mod ipc; -pub mod unix; - -use std::{ - io::{Error, ErrorKind, Result}, - process::ExitStatus, -}; - -use nix::sys::wait; - -pub trait Checkable { - fn check(&self) -> Result<()>; -} - -impl Checkable for ExitStatus { - fn check(&self) -> Result<()> { - if self.success() { - Ok(()) - } else { - Err(Error::new( - ErrorKind::Other, - format!("Process exited with {}", self), - )) - } - } -} - -impl Checkable for wait::WaitStatus { - fn check(&self) -> Result<()> { - let message = match self { - wait::WaitStatus::Exited(_, 0) => return Ok(()), - wait::WaitStatus::Exited(_, code) => format!("Process exited with exit code: {}", code), - wait::WaitStatus::Signaled(_, signal, _) => { - format!("Process exited with signal: {}", signal) - } - _ => format!("Process in unexpected status: {:?}", self), - }; - Err(Error::new(ErrorKind::Other, message)) - } -} |