def sane_execvp(filename, args, close_fds=True, restore_signals=True):
"""Execute a new program with sanitized environment.
"""
def _restore_signals():
"""Reset the default behavior to all signals.
"""
for i in _SIGNALS:
signal.signal(i, signal.SIG_DFL)
def _close_fds():
"""Close all file descriptors except 0, 1, 2.
"""
os.closerange(3, subprocess.MAXFD)
if close_fds:
_close_fds()
if restore_signals:
_restore_signals()
os.execvp(filename, args)
评论列表
文章目录