use super::*;
use std::fs;
use std::os::unix::fs::PermissionsExt;
mod detach;
mod exec;
mod run;
mod self_exe;
mod spawn;
mod stream;
mod streamed;
mod wrap;
fn write_script(dir: &Path, name: &str, body: &str) -> PathBuf {
let path = dir.join(name);
fs::write(&path, body).unwrap();
let mut perms = fs::metadata(&path).unwrap().permissions();
perms.set_mode(0o755);
fs::set_permissions(&path, perms).unwrap();
path
}
fn collect(stream: Stream) -> (Vec<u8>, Vec<u8>, ExitInfo) {
let mut out = Vec::new();
let mut err = Vec::new();
let mut exit = ExitInfo::Unknown;
for chunk in stream {
match chunk {
Chunk::Stdout(b) => out.extend(b),
Chunk::Stderr(b) => err.extend(b),
Chunk::Exited(e) => exit = e,
}
}
(out, err, exit)
}
fn process_exists(pid: u32) -> bool {
Path::new(&format!("/proc/{pid}")).exists()
}