Index: build/android/forked_adb_logcat_monitor.py |
diff --git a/build/android/forked_adb_logcat_monitor.py b/build/android/forked_adb_logcat_monitor.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..dc7764015fdac2686fb47320dc15f0c620703971 |
--- /dev/null |
+++ b/build/android/forked_adb_logcat_monitor.py |
@@ -0,0 +1,60 @@ |
+#!/usr/bin/env python |
+# |
+# Copyright 2013 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Saves logcats from all connected devices but in a separate, forked process. |
+ |
+Usage: forked_adb_logcat_monitor.py <base_dir> [<adb_binary_path>] |
+ |
+This script is similar to adb_logcat_monitor.py, but spawns logcat watchers in |
+separate forked process. See adb_logcat_monitor.py for more info. |
+""" |
+ |
+import os |
+import sys |
+ |
+import adb_logcat_monitor |
+ |
+if __name__ == '__main__': |
navabi
2013/10/03 23:51:04
move the body of this into a main function.
if 2 <
|
+ if 2 <= len(sys.argv) <= 3: |
+ print 'adb_logcat_monitor: Initializing' |
+ # Spawn a detached child process. |
+ try: |
+ pid = os.fork() |
+ if pid > 0: |
+ # exit first parent |
+ sys.exit(0) |
+ except OSError, e: |
+ sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror)) |
+ sys.exit(1) |
+ |
+ # decouple from parent environment |
+ os.chdir("/") |
+ os.setsid() |
+ os.umask(0) |
+ |
+ # do second fork |
navabi
2013/10/03 23:51:04
Why is there a second fork? For the adb_reboot_on_
|
+ try: |
+ pid = os.fork() |
+ if pid > 0: |
+ # exit from second parent |
+ sys.exit(0) |
+ except OSError, e: |
+ sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror)) |
+ sys.exit(1) |
+ |
+ # redirect standard file descriptors |
+ sys.stdout.flush() |
+ sys.stderr.flush() |
+ si = file('/dev/null', 'r') |
+ so = file('/dev/null', 'a+') |
+ se = file('/dev/null', 'a+', 0) |
+ os.dup2(si.fileno(), sys.stdin.fileno()) |
+ os.dup2(so.fileno(), sys.stdout.fileno()) |
+ os.dup2(se.fileno(), sys.stderr.fileno()) |
+ |
+ sys.exit(adb_logcat_monitor.SpawnLogcatWatchers(*sys.argv[1:3])) |
+ |
+ print 'Usage: %s <base_dir> [<adb_binary_path>]' % sys.argv[0] |