public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Filip Schauer <f.schauer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH vma-to-pbs] fix #5994: wait for decompression processes to exit
Date: Tue, 17 Dec 2024 16:12:55 +0100	[thread overview]
Message-ID: <20241217151255.155032-1-f.schauer@proxmox.com> (raw)

Wait for zstd, lzop or zcat processes to exit when uploading a
compressed VMA file. This prevents these processes from lingering as
zombies. Also check the exit code of the processes, to detect potential
failures during decompression.

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
 src/vma2pbs.rs | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/vma2pbs.rs b/src/vma2pbs.rs
index 7457b9a..1be52b9 100644
--- a/src/vma2pbs.rs
+++ b/src/vma2pbs.rs
@@ -4,7 +4,7 @@ use std::collections::HashMap;
 use std::ffi::{c_char, CStr, CString, OsString};
 use std::fs::File;
 use std::io::{stdin, BufRead, BufReader, Read};
-use std::process::{Command, Stdio};
+use std::process::{Child, Command, Stdio};
 use std::ptr;
 use std::sync::atomic::{AtomicU64, Ordering};
 use std::sync::Arc;
@@ -515,7 +515,7 @@ fn upload_vma_file(pbs_args: &PbsArgs, backup_args: &VmaBackupArgs) -> Result<()
         None => log::info!("Uploading VMA backup from (stdin)"),
     };
 
-    let vma_file: Box<dyn BufRead> = match &backup_args.compression {
+    let (vma_file, decompproc): (Box<dyn BufRead>, Option<Child>) = match &backup_args.compression {
         Some(compression) => {
             let vma_file_path = backup_args
                 .vma_file_path
@@ -534,16 +534,16 @@ fn upload_vma_file(pbs_args: &PbsArgs, backup_args: &VmaBackupArgs) -> Result<()
                 }
                 Compression::GZip => Command::new("zcat"),
             };
-            let process = cmd.arg(vma_file_path).stdout(Stdio::piped()).spawn()?;
-            let stdout = process.stdout.expect("Failed to capture stdout");
-            Box::new(BufReader::new(stdout))
+            let mut process = cmd.arg(vma_file_path).stdout(Stdio::piped()).spawn()?;
+            let stdout = process.stdout.take().expect("Failed to capture stdout");
+            (Box::new(BufReader::new(stdout)), Some(process))
         }
         None => match &backup_args.vma_file_path {
             Some(vma_file_path) => match File::open(vma_file_path) {
                 Err(why) => return Err(anyhow!("Couldn't open file: {why}")),
-                Ok(file) => Box::new(BufReader::new(file)),
+                Ok(file) => (Box::new(BufReader::new(file)), None),
             },
-            None => Box::new(BufReader::new(stdin())),
+            None => (Box::new(BufReader::new(stdin())), None),
         },
     };
 
@@ -565,6 +565,14 @@ fn upload_vma_file(pbs_args: &PbsArgs, backup_args: &VmaBackupArgs) -> Result<()
     upload_configs(&vma_reader, pbs)?;
     upload_block_devices(vma_reader, pbs)?;
 
+    if let Some(mut decompproc) = decompproc {
+        let status = decompproc.wait()?;
+
+        if !status.success() {
+            bail!("Failed to decompress file with exit code: {status}");
+        }
+    }
+
     if proxmox_backup_finish(pbs, &mut pbs_err) < 0 {
         handle_pbs_error(pbs_err, "proxmox_backup_finish")?;
     }
-- 
2.39.5



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


                 reply	other threads:[~2024-12-17 15:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20241217151255.155032-1-f.schauer@proxmox.com \
    --to=f.schauer@proxmox.com \
    --cc=pbs-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