Closed johnnybubonic closed 7 years ago
Your initial code wasn't allowing the mount namespace to do its magic. Basically the code forks a child which setups up a mount namespace and then the mounts are performed inside that. Thus when the child exits, all the mounts get unmounted because the namespace also vanishes.
Really, you shouldn't explicitly call chroot.mount() unless you really want to do everything manually. Just creating the context manager and using it as such should be enough. I could probably help people realize this by documenting things a bit better and perhaps "privatizing" some function names for internal use only. :smile:
Closing this as it's not a bug and is working as intended. See the pychroot script as a simple example of how to use the Chroot context manager that operates as an extended chroot(1) equivalent. If you want more help, feel free to drop me an email.
so i'm calling pychroot in a function, and i have a bunch of custom bind mounts (and don't want to use the defaults, as it doesn't allow for e.g. Arch's pacman, which requires the chroot to be bind mounted as /)...
so all well and good. the mounts create and the chrooted command executes. HOWEVER, the mounts created don't unmount after execution, not even with the chrootcmd.cleanup().
With the following, however:
It does indeed unmount the mounted dirs. (I should note that it also backgrounds on the command completion, which seems odd to me, but only from the python shell.)
am i doing something wrong or is this a bug? the documentation is admittedly a bit sparse, so apologies if i'm going about this the wrong way.
Arch Linux x86_64, fully up to date. python 3.5 pychroot 0.9.16 snakeoil 0.7.1