From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 8F7E31FF380 for ; Fri, 19 Apr 2024 15:00:28 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4C20495F7; Fri, 19 Apr 2024 15:00:30 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Date: Fri, 19 Apr 2024 15:00:25 +0200 Message-Id: <20240419130026.268310-1-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.271 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pve-devel] [PATCH proxmox-firewall 1/2] firewall: wait for nft process X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" NftClient never waits for the child process to terminate leading to defunct leftover processes. Signed-off-by: Stefan Hanreich --- proxmox-nftables/src/client.rs | 38 ++++++++-------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/proxmox-nftables/src/client.rs b/proxmox-nftables/src/client.rs index 69e464b..eaa3dd2 100644 --- a/proxmox-nftables/src/client.rs +++ b/proxmox-nftables/src/client.rs @@ -36,35 +36,15 @@ impl NftClient { return Err(NftError::from(error)); }; - let mut error_output = String::new(); - - match child - .stderr - .take() - .expect("can get stderr") - .read_to_string(&mut error_output) - { - Ok(_) if !error_output.is_empty() => { - return Err(NftError::Command(error_output)); - } - Err(error) => { - return Err(NftError::from(error)); - } - _ => (), - }; - - let mut output = String::new(); - - if let Err(error) = child - .stdout - .take() - .expect("can get stdout") - .read_to_string(&mut output) - { - return Err(NftError::from(error)); - }; - - Ok(output) + let output = child.wait_with_output().map_err(NftError::from)?; + + if output.status.success() { + Ok(String::from_utf8(output.stdout).expect("output is valid utf-8")) + } else { + Err(NftError::Command( + String::from_utf8(output.stderr).expect("output is valid utf-8"), + )) + } } pub fn run_json_commands(commands: &Commands) -> Result, NftError> { -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel