I want to write a chroot wrapper in python. The script will be copying some files, setting up some other stuff and then executing chroot and should land me in a chroot shell.
The tricky part is that I want no python processes running after I am in the chroot.
In other words, python should do the setup work, call chroot and terminate itself, leaving me in a chroot shell. When I exit the chroot, I should be in a directory where I was when I invoked the python script.
Is this possible?
My first thought would be to use one of the os.exec*
functions. These will replace the Python process with the chroot
process (or whatever you decide to run with exec*
).
# ... do setup work
os.execl('/bin/chroot', '/bin/chroot', directory_name, shell_path)
(or something like that)