M7350/oe-core/scripts/swabber-strace-attach

32 lines
645 B
Plaintext
Raw Normal View History

2024-09-09 08:52:07 +00:00
#!/usr/bin/env python
import os
import sys
2024-09-09 08:57:42 +00:00
import subprocess
2024-09-09 08:52:07 +00:00
# Detach from the controlling terminal and parent process by forking twice to daemonize ourselves,
# then run the command passed as argv[1]. Send log data to argv[2].
pid = os.fork()
if (pid == 0):
os.setsid()
pid = os.fork()
if (pid != 0):
os._exit(0)
else:
sys.exit()
si = file(os.devnull, 'r')
so = file(sys.argv[2], 'w')
se = so
# Replace those fds with our own
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
2024-09-09 08:57:42 +00:00
ret = subprocess.call(sys.argv[1], shell=True)
2024-09-09 08:52:07 +00:00
os._exit(ret)