(ruleset: &str)
| 564 | } |
| 565 | |
| 566 | fn run_nft_stdin(ruleset: &str) -> Result<(), String> { |
| 567 | use std::io::Write; |
| 568 | |
| 569 | let mut child = StdCommand::new("nft") |
| 570 | .args(["-f", "-"]) |
| 571 | .stdin(Stdio::piped()) |
| 572 | .stdout(Stdio::piped()) |
| 573 | .stderr(Stdio::piped()) |
| 574 | .spawn() |
| 575 | .map_err(|e| format!("failed to run nft: {e}"))?; |
| 576 | |
| 577 | if let Some(mut stdin) = child.stdin.take() { |
| 578 | stdin |
| 579 | .write_all(ruleset.as_bytes()) |
| 580 | .map_err(|e| format!("failed to write nft ruleset: {e}"))?; |
| 581 | } |
| 582 | |
| 583 | let output = child |
| 584 | .wait_with_output() |
| 585 | .map_err(|e| format!("failed to wait for nft: {e}"))?; |
| 586 | |
| 587 | if output.status.success() { |
| 588 | Ok(()) |
| 589 | } else { |
| 590 | let stderr = String::from_utf8_lossy(&output.stderr); |
| 591 | Err(format!("nft -f - failed: {stderr}")) |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | /// RAII guard that tears down TAP networking on drop. |
| 596 | struct TapGuard { |
no test coverage detected