Skip to content

Commit

Permalink
fix(network/linux): correctly handle subprocess errors
Browse files Browse the repository at this point in the history
  • Loading branch information
M0dEx committed Oct 27, 2024
1 parent 37e9a01 commit 00d73a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/network/dns/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ pub fn add_dns_servers(dns_servers: &[IpAddr], interface_name: &str) -> Result<(
.join("\n");

let mut process = run_command(RESOLVCONF_COMMAND, set_args)?;
let mut process_in = process
.stdin
.take()
.ok_or(anyhow!("failed to open stdin"))?;

process_in
.write_all(input.as_bytes())
.context("failed to write to stdin")?;

if let Some(mut stdin) = process.stdin.take() {
stdin
.write_all(input.as_bytes())
.context("failed to write to stdin")?;
} else {
return Err(anyhow!("failed to open stdin"));
}

let output = process
.wait_with_output()
.context("failed to wait for process to exit")?;
Expand Down
6 changes: 4 additions & 2 deletions src/network/route/posix.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::command::run_command;
use anyhow::{anyhow, Result};
use anyhow::{anyhow, Context, Result};
use ipnet::IpNet;
use std::net::IpAddr;

Expand Down Expand Up @@ -40,7 +40,9 @@ fn add_route(network: &IpNet, gateway: &IpAddr) -> Result<()> {
let route_program = route_command_split[0];
let route_args = &route_command_split[1..];

let output = run_command(route_program, route_args)?.wait_with_output()?;
let output = run_command(route_program, route_args)?
.wait_with_output()
.context("failed to create child process")?;

if !output.status.success() {
return Err(anyhow!(
Expand Down

0 comments on commit 00d73a3

Please sign in to comment.