Monorepo for Tangled tangled.org
2

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