Skip to content

Commit bcc5029

Browse files
committed
Move all source files to separate directory
0 parents  commit bcc5029

File tree

11 files changed

+2192
-0
lines changed

11 files changed

+2192
-0
lines changed

src/minion/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "minion"
3+
version = "0.1.0"
4+
authors = ["Mikail Bagishov <bagishov.mikail@yandex.ru>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
libc= "0.2.62"
9+
errno= "0.2.4"
10+
rand = "0.7.2"
11+
cfg-if = "0.1.10"
12+
serde = { version = "1.0.101", features = ["derive"] }
13+
serde_json = "1.0.40"
14+
tiny-nix-ipc = { git = "https://github.com/mikailbag/tiny-nix-ipc", rev = "bfd29b8b05098c132dd30cd1c7909377e88cb789", features = ["ser_json"] }
15+
procfs = "0.5.3"
16+
nix = "0.15.0"
17+
downcast-rs = "1.0.4"
18+
snafu = { version = "0.5.0", features = ["rust_1_30"] }
19+
base64 = "0.10.1"
20+
backtrace = "0.3.38"

src/minion/src/command.rs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
use crate::{
2+
Backend, ChildProcess, ChildProcessOptions, DominionRef, InputSpecification,
3+
OutputSpecification, StdioSpecification,
4+
};
5+
use std::{
6+
collections::HashMap,
7+
ffi::{OsStr, OsString},
8+
path::{Path, PathBuf},
9+
};
10+
11+
/// Child process builder
12+
#[derive(Default)]
13+
pub struct Command {
14+
dominion: Option<DominionRef>,
15+
exe: Option<PathBuf>,
16+
argv: Vec<OsString>,
17+
env: HashMap<OsString, OsString>,
18+
stdin: Option<InputSpecification>,
19+
stdout: Option<OutputSpecification>,
20+
stderr: Option<OutputSpecification>,
21+
current_dir: Option<PathBuf>,
22+
}
23+
24+
impl Command {
25+
pub fn build(&self) -> Option<ChildProcessOptions> {
26+
let create_default_in_channel = || InputSpecification::empty();
27+
let create_default_out_channel = || OutputSpecification::ignore();
28+
let opts = ChildProcessOptions {
29+
path: self.exe.clone()?,
30+
arguments: self.argv.clone(),
31+
environment: self.env.clone(),
32+
dominion: self.dominion.clone()?,
33+
stdio: StdioSpecification {
34+
stdin: self.stdin.clone().unwrap_or_else(create_default_in_channel),
35+
stdout: self
36+
.stdout
37+
.clone()
38+
.unwrap_or_else(create_default_out_channel),
39+
stderr: self
40+
.stderr
41+
.clone()
42+
.unwrap_or_else(create_default_out_channel),
43+
},
44+
pwd: self.current_dir.clone().unwrap_or_else(|| "/".into()),
45+
};
46+
Some(opts)
47+
}
48+
49+
pub fn new() -> Command {
50+
Default::default()
51+
}
52+
53+
pub fn spawn(&self, backend: &dyn Backend) -> crate::Result<Box<dyn ChildProcess>> {
54+
let options = self
55+
.build()
56+
.expect("spawn() was requested, but required fields were not set");
57+
backend.spawn(options)
58+
}
59+
60+
pub fn dominion(&mut self, dominion: DominionRef) -> &mut Self {
61+
self.dominion.replace(dominion);
62+
self
63+
}
64+
65+
pub fn path<S: AsRef<Path>>(&mut self, path: S) -> &mut Self {
66+
self.exe.replace(path.as_ref().to_path_buf());
67+
self
68+
}
69+
70+
pub fn arg<S: AsRef<OsStr>>(&mut self, a: S) -> &mut Self {
71+
self.argv.push(a.as_ref().to_os_string());
72+
self
73+
}
74+
75+
pub fn args(&mut self, args: impl IntoIterator<Item = impl AsRef<OsStr>>) -> &mut Self {
76+
self.argv
77+
.extend(args.into_iter().map(|s| s.as_ref().to_os_string()));
78+
self
79+
}
80+
81+
pub fn env(&mut self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> &mut Self {
82+
self.env
83+
.insert(key.as_ref().to_os_string(), value.as_ref().to_os_string());
84+
self
85+
}
86+
87+
pub fn envs(
88+
&mut self,
89+
items: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
90+
) -> &mut Self {
91+
self.env.extend(
92+
items
93+
.into_iter()
94+
.map(|(k, v)| (k.as_ref().to_os_string(), v.as_ref().to_os_string())),
95+
);
96+
self
97+
}
98+
99+
pub fn current_dir<S: AsRef<Path>>(&mut self, a: S) -> &mut Self {
100+
self.current_dir.replace(a.as_ref().to_path_buf());
101+
self
102+
}
103+
104+
pub fn stdin(&mut self, stdin: InputSpecification) -> &mut Self {
105+
self.stdin.replace(stdin);
106+
self
107+
}
108+
109+
pub fn stdout(&mut self, stdout: OutputSpecification) -> &mut Self {
110+
self.stdout.replace(stdout);
111+
self
112+
}
113+
114+
pub fn stderr(&mut self, stderr: OutputSpecification) -> &mut Self {
115+
self.stderr.replace(stderr);
116+
self
117+
}
118+
}

0 commit comments

Comments
 (0)