use clap::Clap; use std::sync::Arc; use syndicate::actor::*; use syndicate::relay; use syndicate::sturdy; use syndicate::value::NestedValue; use syndicate::value::Value; use tokio::process; #[derive(Clap, Clone, Debug)] #[clap(version)] pub struct CommandLine { #[clap(long, default_value="/sbin/syndicate-server")] server_path: String, } pub struct Pid1Listener { config: Arc, } impl Pid1Listener { fn new(config: Arc) -> Self { Self { config, } } } impl Entity for Pid1Listener { } #[tokio::main] async fn main() -> Result<(), Box> { syndicate::convenient_logging()?; match nix::unistd::setsid() { Ok(_pid) => tracing::info!("setsid(2): new session is {}", _pid), Err(e) => tracing::info!("setsid(2) failed: {:?}", &e), } let config = Arc::new(CommandLine::parse()); let server = process::Command::new(&config.server_path) .arg("--inferior") .arg("--port") .arg("1") .arg("--socket") .arg("/run/ds") .stdin(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped()) // .stderr(std::process::Stdio::null()) .spawn() .expect("Could not spawn main server"); Actor::new().boot(syndicate::name!("server-relay"), |t| { let listener = t.state.create(Pid1Listener::new(config)); let from_server = server.stdout.expect("Missing dataspace server stdout"); let to_server = server.stdin.expect("Missing dataspace server stdin"); let ds = &relay::TunnelRelay::run(t, relay::Input::Bytes(Box::pin(from_server)), relay::Output::Bytes(Box::pin(to_server)), None, Some(sturdy::Oid(0.into()))) .expect("Missing reference to dataspace") .underlying; t.assert(ds, Value::simple_record1("pid1", AnyValue::domain(Cap::new(&listener))).wrap()); Ok(()) }).await??; Ok(()) }