diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/swabber-strace-attach | 30 |
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 | ||
2 | import os | ||
3 | import 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 | |||
8 | pid = os.fork() | ||
9 | if (pid == 0): | ||
10 | os.setsid() | ||
11 | pid = os.fork() | ||
12 | if (pid != 0): | ||
13 | os._exit(0) | ||
14 | else: | ||
15 | sys.exit() | ||
16 | |||
17 | |||
18 | si = file(os.devnull, 'r') | ||
19 | so = file(sys.argv[2], 'w') | ||
20 | se = so | ||
21 | |||
22 | # Replace those fds with our own | ||
23 | os.dup2(si.fileno(), sys.stdin.fileno()) | ||
24 | os.dup2(so.fileno(), sys.stdout.fileno()) | ||
25 | os.dup2(se.fileno(), sys.stderr.fileno()) | ||
26 | |||
27 | ret = os.system(sys.argv[1]) | ||
28 | |||
29 | os._exit(ret) | ||
30 | |||