Skip to content

Commit

Permalink
Don't create a file when it already exists when mounting with bind (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
utam0k authored Jun 12, 2023
1 parent 3251599 commit f5f2242
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
2 changes: 1 addition & 1 deletion crates/libcontainer/src/rootfs/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ impl Mount {
err
})?;

if src.is_file() {
if src.is_file() && !dest.exists() {
OpenOptions::new()
.create(true)
.write(true)
Expand Down
2 changes: 0 additions & 2 deletions hack/debug.bt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f5f2242

Please sign in to comment.