diff options
| author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-02-10 11:50:16 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-02-10 11:51:48 +0000 |
| commit | 296866c38e1b88df42d66bdc32cfed2d5212914c (patch) | |
| tree | f56631b4a7ed520ad4c7198c14a8746cc30cd01b /scripts | |
| parent | d3d236b2bf2784d7454dcb7fce595b6aac6967cd (diff) | |
| download | poky-296866c38e1b88df42d66bdc32cfed2d5212914c.tar.gz | |
image-swab: Convert to attach strace to the process to obtain the required swabber data
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
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 | |||
