Skip to content

Commit

Permalink
Merge pull request #88 from blocklessnetwork/feature/nat
Browse files Browse the repository at this point in the history
refactor:use the io_wrap
  • Loading branch information
Joinhack authored Jul 28, 2024
2 parents 16fd0e1 + d595a87 commit 7e50128
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crates/wasi/src/nat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ impl Nat {
command.args(&["-t", "nat", "-A", "POSTROUTING", "-j", "MASQUERADE", "-o", &active_if]);
command.stdout(Stdio::piped());
command.stderr(Stdio::piped());
let child = command.spawn().map_err(|e| NatError::IoError(e))?;
let output = child.wait_with_output()
.map_err(|e| NatError::IoError(e))?;
let child = io_wrap!(command.spawn());
let output = io_wrap!(child.wait_with_output());
if output.status.success() {
Ok(())
} else {
Expand All @@ -105,8 +104,8 @@ impl Nat {
command.args(&["-w", &format!("net.inet.ip.forwarding={enable}")]);
command.stdout(Stdio::piped());
command.stderr(Stdio::piped());
let mut child = command.spawn().map_err(|e| NatError::IoError(e))?;
let exit_code = child.wait().map_err(|e| NatError::IoError(e))?;
let mut child = io_wrap!(command.spawn());
let exit_code = io_wrap!(child.wait());
if exit_code.success() {
Ok(())
} else {
Expand All @@ -116,11 +115,11 @@ impl Nat {

fn pfctl() -> Result<(), NatError> {
let mut command = Command::new("pfctl");
let child = command.args( &["-f", "/etc/pf.anchors/bls-vm-nat", "-e" ])
let child = io_wrap!(command.args(&["-f", "/etc/pf.anchors/bls-vm-nat", "-e" ])
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn().map_err(|e| NatError::IoError(e))?;
let output = child.wait_with_output().map_err(|e| NatError::IoError(e))?;
.spawn());
let output = io_wrap!(child.wait_with_output());
if output.status.success() {
return Ok(());
} else {
Expand Down

0 comments on commit 7e50128

Please sign in to comment.