| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Waits for the go signal and replaces itself with the command to be run. | 6 """Executes with the command to be run and optionally waits for the go signal. |
| 7 | 7 |
| 8 Not meant to be used directly, only meant to be used by trace_inputs.py. | 8 Not meant to be used directly, only meant to be used by trace_inputs.py. |
| 9 |
| 10 This script is used by the tracer as a signal for the log parser that the child |
| 11 process is the process we care about. It is especially important on kernel based |
| 12 tracer because we want it to trace the relevant process tree. |
| 9 """ | 13 """ |
| 10 | 14 |
| 11 import os | |
| 12 import subprocess | 15 import subprocess |
| 13 import sys | 16 import sys |
| 14 | 17 |
| 15 | 18 |
| 16 def main(): | 19 def main(): |
| 17 signal = 'Go!' | |
| 18 value = sys.stdin.read(len(signal)) | |
| 19 assert value == signal | |
| 20 sys.stdin.close() | |
| 21 # Replace the executable with an absolute path to make it easier to grok. | |
| 22 cmd = sys.argv[1:] | 20 cmd = sys.argv[1:] |
| 23 cmd[0] = os.path.abspath(cmd[0]) | 21 if sys.argv[1] == '--wait': |
| 24 if cmd[0].endswith('.py'): | 22 cmd = cmd[1:] |
| 25 cmd.insert(0, sys.executable) | 23 signal = 'Go!' |
| 26 p = subprocess.Popen(cmd) | 24 value = sys.stdin.read(len(signal)) |
| 27 #print 'Child pid: %d' % p.pid | 25 assert value == signal |
| 28 p.wait() | 26 sys.stdin.close() |
| 29 return p.returncode | 27 |
| 28 # The reason os.execve() is not used is that we don't want the modules |
| 29 # imported here to influence the executable being traced, so we need a fresh |
| 30 # pid and need to fork. |
| 31 return subprocess.call(cmd) |
| 30 | 32 |
| 31 | 33 |
| 32 if __name__ == '__main__': | 34 if __name__ == '__main__': |
| 33 sys.exit(main()) | 35 sys.exit(main()) |
| OLD | NEW |