You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.3 KiB
59 lines
1.3 KiB
#![allow(unused_variables)]
|
|
#![allow(dead_code)]
|
|
|
|
use std::{
|
|
error::Error,
|
|
process::{Command, Stdio, Child, ChildStdin, ChildStdout,},
|
|
io::{self, Read, Write,},
|
|
};
|
|
|
|
mod arg;
|
|
mod multicast;
|
|
mod pipe;
|
|
|
|
fn link<'a>(oneesan: &'a mut Child, imouto: &'a mut Vec<Child>) -> Result<pipe::LeakyPipe<'a, ChildStdout, ChildStdin>, &'static str>
|
|
{
|
|
let pipe_read = oneesan.stdout.as_mut().ok_or("Failed to open oneesan stdout")?;
|
|
let mut pipe_write = multicast::MulticastStream::new();
|
|
|
|
for write in imouto.iter_mut() {
|
|
pipe_write.cast(write.stdin.as_mut().ok_or("Failed to open imouto stdin")?);
|
|
}
|
|
|
|
Ok(pipe::LeakyPipe::new(pipe_read, pipe_write))
|
|
}
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
let op = arg::parse()?;
|
|
|
|
let parent = op.parent();
|
|
let children = op.children();
|
|
|
|
let mut oneesan = Command::new(parent.name_path()?)
|
|
.args(&parent.args)
|
|
.stdout(Stdio::piped())
|
|
.stdin(Stdio::null())
|
|
.spawn()?;
|
|
|
|
let mut imouto = Vec::with_capacity(children.len());
|
|
for child in children.iter()
|
|
{
|
|
imouto.push(Command::new(child.name_path()?)
|
|
.args(&child.args)
|
|
.stdin(Stdio::piped())
|
|
.stdout(Stdio::inherit())
|
|
.spawn()?);
|
|
}
|
|
|
|
let leak = link(&mut oneesan, &mut imouto)?;
|
|
|
|
leak.pipe(1024, op.tty())?;
|
|
|
|
oneesan.wait()?;
|
|
for mut i in imouto.into_iter() {
|
|
i.wait()?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|