forked from autotest/autotest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautotest-daemon
executable file
·60 lines (45 loc) · 1.51 KB
/
autotest-daemon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
try:
import autotest.common # pylint: disable=W0611
except ImportError:
import common # pylint: disable=W0611
import fcntl
import os
import subprocess
import sys
from autotest.client import os_dep
try:
autotest = os_dep.command('autotest-local')
except ValueError:
bindir = os.path.dirname(__file__)
autotest = os.path.join(bindir, 'autotest-local')
logdir = sys.argv[1]
# We want to simulate the behaviour of autotest_client, where fd3 would be
# routed to stderr and fd1 & fd2 to stdout
# HACK: grab fd3 for now
os.dup2(2, 3)
# open up log files to use for std*
stdout = open(os.path.join(logdir, 'stdout'), 'a', 0)
stderr = open(os.path.join(logdir, 'stderr'), 'a', 0)
# set up the file descriptors now, simulating the old behaviour
os.dup2(stdout.fileno(), 1)
os.dup2(stdout.fileno(), 2)
os.dup2(stderr.fileno(), 3)
# we don't need the file objects any more
stdout.close()
stderr.close()
args = [autotest] + sys.argv[2:]
if '-H' not in args:
args[1:1] = ['-H', 'autoserv']
cmd = ' '.join(args)
# open up a log file for saving off the exit code
exit_file = open(os.path.join(logdir, 'exit_code'), 'w', 0)
fcntl.flock(exit_file, fcntl.LOCK_EX)
# touch a 'started' file to indicate we've been initialized
open(os.path.join(logdir, 'started'), 'w').close()
# run the actual autotest client and write the exit code into the log file
exit_code = subprocess.call(cmd, shell=True)
exit_file.write('%+04d' % exit_code)
exit_file.flush()
fcntl.flock(exit_file, fcntl.LOCK_UN)
exit_file.close()