I have enabled seccomp via python-prctl in a project. I can't quite figure out how to exit cleanly - the result is always a kill.
I saw some examples that use ctypes or ffi to try to reference libc, but if I expect them with WIFEXITED they also seem to have the same issue.
Example code below. The result is always "We were killed to death".
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))
Quick update since I forgot the libc stuff:
Defining _exit() above with either of these still resulted in a kill.
# FFI Method
ffi = cffi.FFI()
# Use _exit, which avoids atexit(), etc
ffi.cdef('void _exit(int);')
libc = ffi.dlopen(None)
_exit = libc._exit
.... or ....
# ctypes method
libc = cdll.LoadLibrary('libc-2.18.so')
_exit = libc._exit