次のコマンドを使用してディレクトリをchrootしました。
os.chroot("/mydir")
前のディレクトリに戻る方法-chrootする前に?たぶん、ディレクトリをunchrootすることは可能ですか?
解決:
Phihagに感謝します。私は解決策を見つけました。簡単な例:
import os
os.mkdir('/tmp/new_dir')
dir1 = os.open('.', os.O_RDONLY)
dir2 = os.open('/tmp/new_dir', os.O_RDONLY)
os.getcwd() # we are in 'tmp'
os.chroot('/tmp/new_dir') # chrooting 'new_dir' directory
os.fchdir(dir2)
os.getcwd() # we are in chrooted directory, but path is '/'. It's OK.
os.fchdir(dir1)
os.getcwd() # we came back to not chrooted 'tmp' directory
os.close(dir1)
os.close(dir2)