Monorepo for Tangled tangled.org
6

Configure Feed

Select the types of activity you want to include in your feed.

1#![cfg(target_os = "linux")] 2 3mod activation; 4mod cache; 5mod command; 6mod dns_proxy; 7mod exec; 8mod host_proxy; 9mod logging; 10mod nix_config; 11mod protocol; 12mod pty; 13mod session; 14 15use std::env; 16use std::time::Duration; 17use tracing::warn; 18 19#[macro_export] 20macro_rules! cfg { 21 (@val $key:expr) => { 22 std::env::var(concat!("SHUTTLE_", $key)) 23 }; 24 ($key:expr, $default:expr) => { 25 cfg!(@val $key) 26 .ok() 27 .and_then(|s| s.parse().ok()) 28 .unwrap_or($default.to_owned()) 29 .into() 30 }; 31} 32 33fn cmdline_param(key: &str) -> Option<String> { 34 let cmdline = std::fs::read_to_string("/proc/cmdline").ok()?; 35 cmdline 36 .split_whitespace() 37 .find_map(|tok| Some(tok.strip_prefix(key)?.strip_prefix('=')?.to_owned())) 38} 39 40#[tokio::main] 41async fn main() { 42 logging::init(); 43 44 let args: Vec<String> = env::args().collect(); 45 if args.get(1).map(String::as_str) == Some("enqueue-built-paths") { 46 cache::enqueue_built_paths(&args[2..]).await; 47 return; 48 } 49 50 let port: u32 = cfg!(@val "VSOCK_PORT") 51 .ok() 52 .or_else(|| cmdline_param("shuttle.vsock_port")) 53 .and_then(|s| s.parse().ok()) 54 .unwrap_or(protocol::DEFAULT_PORT); 55 let host_cid: u32 = cfg!("HOST_CID", tokio_vsock::VMADDR_CID_HOST); 56 57 loop { 58 if let Err(error) = session::run(host_cid, port).await { 59 warn!(host_cid, port, %error, "agent session failed"); 60 } 61 tokio::time::sleep(Duration::from_secs(1)).await; 62 } 63}