public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-firewall 1/2] firewall: wait for nft process
Date: Fri, 19 Apr 2024 15:00:25 +0200	[thread overview]
Message-ID: <20240419130026.268310-1-s.hanreich@proxmox.com> (raw)

NftClient never waits for the child process to terminate leading to
defunct leftover processes.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 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<Option<CommandOutput>, NftError> {
-- 
2.39.2


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


             reply	other threads:[~2024-04-19 13:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19 13:00 Stefan Hanreich [this message]
2024-04-19 13:00 ` [pve-devel] [PATCH proxmox-firewall 2/2] firewall: improve systemd unit file Stefan Hanreich
2024-04-19 17:45 ` [pve-devel] applied-series: [PATCH proxmox-firewall 1/2] firewall: wait for nft process Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240419130026.268310-1-s.hanreich@proxmox.com \
    --to=s.hanreich@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal