chiark / gitweb /
ipif: Introduce OptionPrefixColon
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Aug 2021 00:10:31 +0000 (01:10 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Aug 2021 00:10:31 +0000 (01:10 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/client.rs
src/ipif.rs
src/reporter.rs

index 04d6cac60bc739aaae04c84e4dd294008087db16..2f2e676ed6b3f266dfbaab59d872fc22a12f0a98 100644 (file)
@@ -179,7 +179,7 @@ async fn run_client<C:HCC>(
     ic: &ic,
   };
 
-  let mut ipif = Ipif::start(&ic.ipif, ic.to_string())?;
+  let mut ipif = Ipif::start(&ic.ipif, Some(ic.to_string()))?;
 
   let mut req_num: ReqNum = 0;
 
index 196b6b38ac7015945705f67bd502c0627bab3c8d..14f9d6d54346c01faacdd4d0542b47197672fa23 100644 (file)
@@ -13,7 +13,7 @@ pub struct Ipif {
 
 impl Ipif {
   #[throws(AE)]
-  pub fn start(cmd: &str, ic_name: String) -> Self {
+  pub fn start(cmd: &str, ic_name: Option<String>) -> Self {
     let mut child = tokio::process::Command::new("sh")
       .args(&["-c", cmd])
       .stdin (process::Stdio::piped())
@@ -27,7 +27,9 @@ impl Ipif {
     let stderr_task = task::spawn(async move {
       let mut stderr = t_io::BufReader::new(stderr).lines();
       while let Some(l) = stderr.next_line().await? {
-        error!("{}: ipif stderr: {}", ic_name, l.trim_end());
+        error!("{}ipif stderr: {}",
+               OptionPrefixColon(ic_name.as_ref()),
+               l.trim_end());
       }
       Ok::<_,io::Error>(())
     });
index 8a92b39a9866ae079faf5f55a902433393b13889..49b784bf0e3bf1b582d42b81fb6ecafff334d4ad 100644 (file)
@@ -31,6 +31,14 @@ impl LogOpts {
   }
 }
 
+pub struct OptionPrefixColon<T>(pub Option<T>);
+impl<T:Display> Display for OptionPrefixColon<T> {
+  #[throws(fmt::Error)]
+  fn fmt(&self, f: &mut fmt::Formatter) {
+    if let Some(x) = &self.0 { write!(f, "{}: ", x)? }
+  }
+}
+
 // For clients only, really.
 pub struct Reporter<'r> {
   ic: &'r InstanceConfig,