Skip to content

Commit ed0dad1

Browse files
committed
fix aardvark-dns error handling
Big ops, we didn't handle any error when starting aardvark-dns. While we waited for the fork to happen we never checked the exit status of the command thus all errors were silently ignored. Also the command is supposed to capture the error message so we can return it as proper error string to podman. Before we should wrote to stderr which will not show up for podman-remote users. Of course right now aardvark-dns doesn't actually report many errors so we never cought this but I am trying to make bind failures visible to users so we need this. Signed-off-by: Paul Holzinger <[email protected]>
1 parent 384fa52 commit ed0dad1

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/dns/aardvark.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,35 @@ impl Aardvark {
116116
// After https://github.com/containers/aardvark-dns/pull/148 this command
117117
// will block till aardvark-dns's parent process returns back and let
118118
// aardvark inherit all the fds.
119-
Command::new(aardvark_args[0])
119+
let out = Command::new(aardvark_args[0])
120120
.args(&aardvark_args[1..])
121-
.stdin(Stdio::inherit())
122-
.stdout(Stdio::inherit())
123-
.stderr(Stdio::inherit())
121+
.stdin(Stdio::null())
122+
.stdout(Stdio::null())
124123
// set RUST_LOG for aardvark
125124
.env("RUST_LOG", log::max_level().as_str())
126125
.output()?;
127126

128-
Ok(())
127+
if out.status.success() {
128+
return Ok(());
129+
}
130+
if out.stderr.is_empty() {
131+
return Err(std::io::Error::new(
132+
std::io::ErrorKind::Other,
133+
"aardvark-dns exited unexpectedly without error message",
134+
));
135+
}
136+
// aardvark-dns failed capture stderr
137+
let msg = String::from_utf8(out.stderr).map_err(|e| {
138+
std::io::Error::new(
139+
std::io::ErrorKind::Other,
140+
format!("failed to parse aardvark-dns stderr message: {e}"),
141+
)
142+
})?;
143+
144+
Err(std::io::Error::new(
145+
std::io::ErrorKind::Other,
146+
format!("aardvark-dns failed to start: {}", msg),
147+
))
129148
}
130149

131150
fn check_netns(&self, pid: pid_t) {

0 commit comments

Comments
 (0)