use super::ceiling::Mark;
use super::{Backlog, Body, Claim, Member, Started, Tail, process, storage};
use kernel::{Address, AxCode, AxError, RunId};
use std::process::{Command, Stdio};
impl Backlog {
pub fn run(
&self,
owner: RunId,
scope: &Address,
what: String,
mut command: Command,
) -> Result<Started, AxError> {
let id = self.mint()?;
let dir = self.scratch.dir(id);
std::fs::create_dir_all(&dir).map_err(|err| storage(&dir, &err))?;
let out = std::fs::File::create(dir.join("out")).map_err(|err| storage(&dir, &err))?;
let errs = std::fs::File::create(dir.join("err")).map_err(|err| storage(&dir, &err))?;
command
.stdin(Stdio::null())
.stdout(Stdio::from(out))
.stderr(Stdio::from(errs));
let child = command.spawn().map_err(|err| {
AxError::failure(
AxCode::ToolUnavailable,
"start a command",
format!("{what}: {err}"),
)
.with_recovery("check the program name, or use the shell arm")
})?;
self.enrol(
id,
Member {
scope: scope.clone(),
what: what.clone(),
body: Body::Command {
child: process::Process::Host(child),
dir: dir.clone(),
claim: Claim::Window(owner),
tail: Tail::default(),
ceiling: Mark::NotAsked,
},
},
)?;
self.watch(id, owner, what, dir)
}
}