From f5f2242f8582e32462823d25cca9e2d980e29c74 Mon Sep 17 00:00:00 2001 From: Toru Komatsu Date: Mon, 12 Jun 2023 13:50:53 +0900 Subject: [PATCH] Don't create a file when it already exists when mounting with bind (#2031) For example, it is more likely that the /etc/hosts file already exists. In that case, it fails because it tries to open the file with write permission while it is RO. Signed-off-by: utam0k --- crates/libcontainer/src/rootfs/mount.rs | 2 +- hack/debug.bt | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/libcontainer/src/rootfs/mount.rs b/crates/libcontainer/src/rootfs/mount.rs index 647a71c6..e86e05ef 100644 --- a/crates/libcontainer/src/rootfs/mount.rs +++ b/crates/libcontainer/src/rootfs/mount.rs @@ -497,7 +497,7 @@ impl Mount { err })?; - if src.is_file() { + if src.is_file() && !dest.exists() { OpenOptions::new() .create(true) .write(true) diff --git a/hack/debug.bt b/hack/debug.bt index 6b104330..4d2e78dc 100755 --- a/hack/debug.bt +++ b/hack/debug.bt @@ -78,8 +78,6 @@ tracepoint:syscalls:sys_enter_setresuid printf("ruid=%d, euid=%d, suid=%d\n", args->ruid, args->euid, args->suid); } - - END { clear(@filename);