我在一个项目中通过pythonprctl启用了seccomp。我不太明白如何干净利落地退出——结果总是一场杀戮。在
我看到了一些使用ctypes或ffi来引用libc的示例,但是如果我期望它们带有WIFEXITED,它们似乎也有相同的问题。在
下面是示例代码。结果总是“我们被杀了”。在
def main():
pid = os.fork()
if not pid:
prctl.set_seccomp(True)
os.write(0, 'Hi\n')
# os._exit(0)
# _exit(0)
# sys._exit(0)
# return
# ?!@#(*! What do?
endpid, status = os.waitpid(pid, 0)
print 'Child forked as %d and returned with %d' % (endpid, status)
if not os.WIFEXITED(status):
print 'Exitted abnormally'
if os.WIFSIGNALED:
if os.WTERMSIG(status) == signal.SIGKILL:
print 'We were killed to death'
else:
print 'Returned with %d' % (os.WEXITSTATUS(status))
我忘了libc的东西后的快速更新:
在上面用这两种方法中的任何一种来定义exit(),仍然会导致一个kill。在
^{pr2}$。。。。或者。。。。在
# ctypes method
libc = cdll.LoadLibrary('libc-2.18.so')
_exit = libc._exit
有人帮我找到了答案:
由于“出口包装”退出“组”,而“出口”组不在seccomp筛选器中。。。。它会被杀死。python执行的strace显示exit_group调用。在
相关问题 更多 >
编程相关推荐