crates/heimdall-cli/tests/fixtures/chan_echo.rs
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2026 Ignalina ApS and Vetra Automation AB
//! Test program for `heimdall profile probe-container` (built static for
//! musl by tests/probe_container.rs): listens on a unix socket (argv[1]) and
//! answers each connection's first line with `pong <line>`. Heimdall is a
//! defensive sandbox; this program talks only to the test that drives it.
use std::io::{BufRead, BufReader, Write};
use std::os::unix::net::UnixListener;
fn main() {
let path = std::env::args()
.nth(1)
.unwrap_or_else(|| "/run/heimdall-channel/echo.sock".to_string());
let _ = std::fs::remove_file(&path);
let l = UnixListener::bind(&path).expect("bind");
println!("chan-echo: listening on {path}");
for s in l.incoming() {
let mut s = match s {
Ok(s) => s,
Err(e) => {
eprintln!("chan-echo: accept: {e}");
continue;
}
};
let mut line = String::new();
let mut r = BufReader::new(s.try_clone().expect("dup"));
if r.read_line(&mut line).is_ok() {
let _ = writeln!(s, "pong {}", line.trim());
}
}
}