[pbs-devel] [PATCH vma-to-pbs] fix #5994: wait for decompression processes to exit

Filip Schauer f.schauer at proxmox.com
Tue Dec 17 16:12:55 CET 2024


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 at 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





More information about the pbs-devel mailing list