* [pbs-devel] [PATCH vma-to-pbs] fix #5994: wait for decompression processes to exit
@ 2024-12-17 15:12 Filip Schauer
0 siblings, 0 replies; only message in thread
From: Filip Schauer @ 2024-12-17 15:12 UTC (permalink / raw)
To: pbs-devel
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-12-17 15:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-17 15:12 [pbs-devel] [PATCH vma-to-pbs] fix #5994: wait for decompression processes to exit Filip Schauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox