| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Saves logcats from all connected devices. | 7 """Saves logcats from all connected devices. |
| 8 | 8 |
| 9 Usage: adb_logcat_monitor.py <base_dir> [<adb_binary_path>] | 9 Usage: adb_logcat_monitor.py <base_dir> [<adb_binary_path>] |
| 10 | 10 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 return [] | 89 return [] |
| 90 except (IOError, OSError): | 90 except (IOError, OSError): |
| 91 logging.exception('Exception from "adb devices"') | 91 logging.exception('Exception from "adb devices"') |
| 92 return [] | 92 return [] |
| 93 finally: | 93 finally: |
| 94 signal.alarm(0) | 94 signal.alarm(0) |
| 95 | 95 |
| 96 | 96 |
| 97 def main(base_dir, adb_cmd='adb'): | 97 def main(base_dir, adb_cmd='adb'): |
| 98 """Monitor adb forever. Expects a SIGINT (Ctrl-C) to kill.""" | 98 """Monitor adb forever. Expects a SIGINT (Ctrl-C) to kill.""" |
| 99 # Spawn a detached child process. | |
| 100 pid = os.fork() | |
| 101 if pid > 0: | |
| 102 os._exit(os.EX_OK) | |
| 103 elif pid < 0: | |
| 104 sys.exit('Unable to spawn a detached child process.') | |
| 105 os.setsid() | |
| 106 # The rest happens in the child process. | |
| 107 | |
| 108 # We create the directory to ensure 'run once' semantics | 99 # We create the directory to ensure 'run once' semantics |
| 109 if os.path.exists(base_dir): | 100 if os.path.exists(base_dir): |
| 110 print 'adb_logcat_monitor: %s already exists? Cleaning' % base_dir | 101 print 'adb_logcat_monitor: %s already exists? Cleaning' % base_dir |
| 111 shutil.rmtree(base_dir, ignore_errors=True) | 102 shutil.rmtree(base_dir, ignore_errors=True) |
| 112 | 103 |
| 113 os.makedirs(base_dir) | 104 os.makedirs(base_dir) |
| 114 logging.basicConfig(filename=os.path.join(base_dir, 'eventlog'), | 105 logging.basicConfig(filename=os.path.join(base_dir, 'eventlog'), |
| 115 level=logging.INFO, | 106 level=logging.INFO, |
| 116 format='%(asctime)-2s %(levelname)-8s %(message)s') | 107 format='%(asctime)-2s %(levelname)-8s %(message)s') |
| 117 | 108 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 pass | 147 pass |
| 157 os.remove(pid_file_path) | 148 os.remove(pid_file_path) |
| 158 | 149 |
| 159 | 150 |
| 160 if __name__ == '__main__': | 151 if __name__ == '__main__': |
| 161 if 2 <= len(sys.argv) <= 3: | 152 if 2 <= len(sys.argv) <= 3: |
| 162 print 'adb_logcat_monitor: Initializing' | 153 print 'adb_logcat_monitor: Initializing' |
| 163 sys.exit(main(*sys.argv[1:3])) | 154 sys.exit(main(*sys.argv[1:3])) |
| 164 | 155 |
| 165 print 'Usage: %s <base_dir> [<adb_binary_path>]' % sys.argv[0] | 156 print 'Usage: %s <base_dir> [<adb_binary_path>]' % sys.argv[0] |
| OLD | NEW |