From 25455bd06d8467338ba864d43331f0473c126a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Tue, 21 Jul 2020 15:03:36 +0200 Subject: [PATCH] fix #2871: close FDs when scanning backup group MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit otherwise we leak those descriptors and run into EMFILE when a backup group contains many snapshots. fcntl::openat and Dir::openat are not the same ;) Signed-off-by: Fabian Grünbichler --- src/backup/backup_info.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backup/backup_info.rs b/src/backup/backup_info.rs index 352d81e4..f8ea11bd 100644 --- a/src/backup/backup_info.rs +++ b/src/backup/backup_info.rs @@ -106,7 +106,11 @@ impl BackupGroup { use nix::fcntl::{openat, OFlag}; match openat(l2_fd, &manifest_path, OFlag::O_RDONLY, nix::sys::stat::Mode::empty()) { - Ok(_) => { /* manifest exists --> assume backup was successful */ }, + Ok(rawfd) => { + /* manifest exists --> assume backup was successful */ + /* close else this leaks! */ + nix::unistd::close(rawfd)?; + }, Err(nix::Error::Sys(nix::errno::Errno::ENOENT)) => { return Ok(()); } Err(err) => { bail!("last_successful_backup: unexpected error - {}", err);