summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/swabber-strace-attach30
1 files changed, 30 insertions, 0 deletions
diff --git a/scripts/swabber-strace-attach b/scripts/swabber-strace-attach
new file mode 100755
index 0000000000..d4f80e4e91
--- /dev/null
+++ b/scripts/swabber-strace-attach
@@ -0,0 +1,30 @@
1#!/usr/bin/env python
2import os
3import sys
4
5# Detach from the controlling terminal and parent process by forking twice to daemonize ourselves,
6# then run the command passed as argv[1]. Send log data to argv[2].
7
8pid = os.fork()
9if (pid == 0):
10 os.setsid()
11 pid = os.fork()
12 if (pid != 0):
13 os._exit(0)
14else:
15 sys.exit()
16
17
18si = file(os.devnull, 'r')
19so = file(sys.argv[2], 'w')
20se = so
21
22# Replace those fds with our own
23os.dup2(si.fileno(), sys.stdin.fileno())
24os.dup2(so.fileno(), sys.stdout.fileno())
25os.dup2(se.fileno(), sys.stderr.fileno())
26
27ret = os.system(sys.argv[1])
28
29os._exit(ret)
30