Sample Header Ad - 728x90

Making a bind-mount take effect only in the context of the current process and its descendants

1 vote
3 answers
1437 views
I have 2 files: /MyDir/a and /MyDir/MySubDir/b and am running a bash script, to which I want to add code to make file /a point to file /b, but only in the current process and its descendants. In hopes of making /MyDir/a point to /MyDir/MySubDir/b in the context of only the current process (not including its descendants, yet) I tried to first make the current process run in its own mount namespace by running a small C program in my script that performs unshare(CLONE_NEWNS) and then mount --bind /MyDir/MySubDir/b /MyDir/a. Unfortunately, this didn't work as I expected since the mount was still visible by other processes, despite the system call reporting success. In another attempt, I tried to make the mount from the C code by calling mount("/MyDir/a", "/MyDir/MySubDir/b", "ext3", MS_BIND, null) But this didn't work as the mount didn't take effect at all (despite the call reporting success). Is there a way of making /MyDir/a point to /MyDir/MySubDir/b in the context of only the current process and its descendants using a bash script? I also read a little about chroot, but this applies only to the / directory... Is there anything similar to chroot that applies only to a particular subdirectory? Thanks for your time!
Asked by Ben S. (13 rep)
May 18, 2018, 07:03 PM
Last activity: Jan 10, 2023, 06:16 PM