OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 """Saves logcats from all connected devices but in a separate, forked process. | |
8 | |
9 Usage: forked_adb_logcat_monitor.py <base_dir> [<adb_binary_path>] | |
10 | |
11 This script is similar to adb_logcat_monitor.py, but spawns logcat watchers in | |
12 separate forked process. See adb_logcat_monitor.py for more info. | |
13 """ | |
14 | |
15 import os | |
16 import sys | |
17 | |
18 import adb_logcat_monitor | |
19 | |
20 if __name__ == '__main__': | |
navabi
2013/10/03 23:51:04
move the body of this into a main function.
if 2 <
| |
21 if 2 <= len(sys.argv) <= 3: | |
22 print 'adb_logcat_monitor: Initializing' | |
23 # Spawn a detached child process. | |
24 try: | |
25 pid = os.fork() | |
26 if pid > 0: | |
27 # exit first parent | |
28 sys.exit(0) | |
29 except OSError, e: | |
30 sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror)) | |
31 sys.exit(1) | |
32 | |
33 # decouple from parent environment | |
34 os.chdir("/") | |
35 os.setsid() | |
36 os.umask(0) | |
37 | |
38 # do second fork | |
navabi
2013/10/03 23:51:04
Why is there a second fork? For the adb_reboot_on_
| |
39 try: | |
40 pid = os.fork() | |
41 if pid > 0: | |
42 # exit from second parent | |
43 sys.exit(0) | |
44 except OSError, e: | |
45 sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror)) | |
46 sys.exit(1) | |
47 | |
48 # redirect standard file descriptors | |
49 sys.stdout.flush() | |
50 sys.stderr.flush() | |
51 si = file('/dev/null', 'r') | |
52 so = file('/dev/null', 'a+') | |
53 se = file('/dev/null', 'a+', 0) | |
54 os.dup2(si.fileno(), sys.stdin.fileno()) | |
55 os.dup2(so.fileno(), sys.stdout.fileno()) | |
56 os.dup2(se.fileno(), sys.stderr.fileno()) | |
57 | |
58 sys.exit(adb_logcat_monitor.SpawnLogcatWatchers(*sys.argv[1:3])) | |
59 | |
60 print 'Usage: %s <base_dir> [<adb_binary_path>]' % sys.argv[0] | |
OLD | NEW |