mirror of
https://git.proxmox.com/git/vma-to-pbs
synced 2025-04-28 14:42:50 +00:00
fix #5994: wait for decompression processes to exit
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>
This commit is contained in:
parent
65cca800bf
commit
cafd76d1f3
@ -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")?;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user