From 00b2e9bb80e7fcd310fa0b0a719726665d2fcbe2 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 27 Jun 2025 19:57:00 +0100 Subject: Pass packet metadata as arguments DUP, QoS, RETAIN and the packet identifier --- src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index cf451dd..bc59b0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,12 +14,17 @@ mod config; const PROGRAM: &str = "mqttr"; async fn run(program: &[String], message: &Publish) -> anyhow::Result<()> { - // TODO: Set environment variables - let mut proc = Command::new(&program[0]) + let mut command = Command::new(&program[0]); + command .args(&program[1..]) .arg(&message.topic) - .stdin(Stdio::piped()) - .spawn()?; + .arg(format!("{}", message.dup as u8)) + .arg(format!("{}", message.qos as u8)) + .arg(format!("{}", message.retain as u8)); + if message.qos == QoS::AtLeastOnce || message.qos == QoS::ExactlyOnce { + command.arg(format!("{}", message.pkid)); + } + let mut proc = command.stdin(Stdio::piped()).spawn()?; let mut stdin = proc.stdin.take().context("No stdin")?; stdin.write(&message.payload).await?; drop(stdin); @@ -88,7 +93,9 @@ async fn main() -> anyhow::Result<()> { let p = p.clone(); tokio::spawn(async move { match timeout(Duration::from_secs(60), run(&program, &p)).await { - Err(_) => eprintln!("error: Execution of {program:?} for message {p:?} timed out"), + Err(_) => eprintln!( + "error: Execution of {program:?} for message {p:?} timed out" + ), Ok(Err(e)) => eprintln!("error: Failed to run {program:?}: {e:?}"), _ => (), } -- cgit v1.2.3-70-g09d2