synit-pid1
This commit is contained in:
parent
e907de2deb
commit
728c97a263
|
@ -0,0 +1 @@
|
||||||
|
target/
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,23 @@
|
||||||
|
[package]
|
||||||
|
name = "synit-pid1"
|
||||||
|
version = "0.0.1"
|
||||||
|
authors = ["Tony Garnock-Jones <tonyg@leastfixedpoint.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
description = "synit PID 1."
|
||||||
|
homepage = "https://syndicate-lang.org/synit/"
|
||||||
|
repository = "https://git.syndicate-lang.org/syndicate-lang/syndicate-system"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
syndicate = { path = "/home/tonyg/src/syndicate-rs/syndicate" }
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
syndicate = "0.9.1"
|
||||||
|
syndicate-macros = "0.4.1"
|
||||||
|
|
||||||
|
clap = "3.0.0-beta.2"
|
||||||
|
clap_generate = "3.0.0-beta.2"
|
||||||
|
nix = "^0.22"
|
||||||
|
tokio = { version = "1.10.0", features = ["process"] }
|
||||||
|
tracing = "0.1.14"
|
|
@ -0,0 +1,74 @@
|
||||||
|
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<CommandLine>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Pid1Listener {
|
||||||
|
fn new(config: Arc<CommandLine>) -> Self {
|
||||||
|
Self {
|
||||||
|
config,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Entity<AnyValue> for Pid1Listener {
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
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(())
|
||||||
|
}
|
Loading…
Reference in New Issue