def doshell(chrootPath=None, environ=None, uid=None, gid=None, cmd=None,
nspawn_args=None,
unshare_ipc=True,
unshare_net=False):
log = getLog()
log.debug("doshell: chrootPath:%s, uid:%d, gid:%d", chrootPath, uid, gid)
if environ is None:
environ = clean_env()
if 'PROMPT_COMMAND' not in environ:
environ['PROMPT_COMMAND'] = r'printf "\033]0;<mock-chroot>\007"'
if 'PS1' not in environ:
environ['PS1'] = r'<mock-chroot> \s-\v\$ '
if 'SHELL' not in environ:
environ['SHELL'] = '/bin/sh'
log.debug("doshell environment: %s", environ)
if cmd:
if not isinstance(cmd, list):
cmd = [cmd]
cmd = ['/bin/sh', '-c'] + cmd
else:
cmd = ["/bin/sh", "-i", "-l"]
if USE_NSPAWN:
# nspawn cannot set gid
cmd = _prepare_nspawn_command(chrootPath, uid, cmd, nspawn_args=nspawn_args, env=environ)
preexec = ChildPreExec(personality=None, chrootPath=chrootPath, cwd=None,
uid=uid, gid=gid, env=environ, shell=True,
unshare_ipc=unshare_ipc, unshare_net=unshare_net)
log.debug("doshell: command: %s", cmd)
return subprocess.call(cmd, preexec_fn=preexec, env=environ, shell=False)
评论列表
文章目录