2
我chroot的使用下面的命令目錄:Python。 Unchroot目錄
os.chroot("/mydir")
如何返回目錄上一個 - 前Chroot環境? 也許有可能unchroot目錄?
SOLUTION:
感謝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)
謝謝!您的建議有效。 – Martynas 2012-04-10 11:00:58