From aff916d015dd17cd8e34c2a0f5a09aea0818ee74 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 10 Feb 2022 16:42:13 +0100 Subject: [PATCH 1/2] set RUST_LOG for aardvark Signed-off-by: Paul Holzinger --- src/dns/aardvark.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dns/aardvark.rs b/src/dns/aardvark.rs index 705a456b8..86463b8d5 100644 --- a/src/dns/aardvark.rs +++ b/src/dns/aardvark.rs @@ -104,6 +104,8 @@ impl Aardvark { .args(&aardvark_args[1..]) .stdout(Stdio::null()) .stderr(Stdio::null()) + // set RUST_LOG for aardvark + .env("RUST_LOG", log::max_level().as_str()) .spawn()?; Ok(()) From adfb2334d4c9aae2082e20bca519a175024db473 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 10 Feb 2022 21:08:15 +0100 Subject: [PATCH 2/2] keep aardvark stderr open with debug log level It is important to read stderr output from aardvark to debug things like panics. Since keeping the stderr open can cause EPIPE when aardvark tries to write to it and the user closed the original stderr, this is only done for debug/trace level. Signed-off-by: Paul Holzinger --- src/dns/aardvark.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dns/aardvark.rs b/src/dns/aardvark.rs index 86463b8d5..6ea99f320 100644 --- a/src/dns/aardvark.rs +++ b/src/dns/aardvark.rs @@ -1,4 +1,5 @@ use crate::network::types; +use log::log_enabled; use nix::sys::signal::{self, Signal}; use nix::unistd::Pid; use std::collections::HashMap; @@ -9,6 +10,7 @@ use std::io::prelude::*; use std::io::Result; use std::net::IpAddr; use std::net::Ipv4Addr; +use std::os::unix::prelude::FromRawFd; use std::path::Path; use std::process::{Command, Stdio}; @@ -100,10 +102,15 @@ impl Aardvark { log::debug!("start aardvark-dns: {:?}", aardvark_args); + let output = match log_enabled!(log::Level::Debug) { + true => Stdio::null(), + false => unsafe { Stdio::from_raw_fd(2) }, + }; + Command::new(&aardvark_args[0]) .args(&aardvark_args[1..]) .stdout(Stdio::null()) - .stderr(Stdio::null()) + .stderr(output) // set RUST_LOG for aardvark .env("RUST_LOG", log::max_level().as_str()) .spawn()?;