4 import sys
, os
, subprocess
, fcntl
7 bindir
= os
.path
.dirname(__file__
)
8 autotest
= os
.path
.join(bindir
, 'autotest')
13 # We want to simulate the behaviour of autotest_client, where fd3 would be
14 # routed to stderr and fd1 & fd2 to stdout
16 # HACK: grab fd3 for now
19 # open up log files to use for std*
20 stdout
= open(os
.path
.join(logdir
, 'stdout'), 'a', 0)
21 stderr
= open(os
.path
.join(logdir
, 'stderr'), 'a', 0)
23 # set up the file descriptors now, simulating the old behaviour
24 os
.dup2(stdout
.fileno(), 1)
25 os
.dup2(stdout
.fileno(), 2)
26 os
.dup2(stderr
.fileno(), 3)
28 # we don't need the file objects any more
33 args
= [autotest
] + sys
.argv
[2:]
35 args
[1:1] = ['-H', 'autoserv']
38 # open up a log file for saving off the exit code
39 exit_file
= open(os
.path
.join(logdir
, 'exit_code'), 'w', 0)
40 fcntl
.flock(exit_file
, fcntl
.LOCK_EX
)
42 # touch a 'started' file to indicate we've been initialized
43 open(os
.path
.join(logdir
, 'started'), 'w').close()
45 # run the actual autotest client and write the exit code into the log file
46 exit_code
= subprocess
.call(cmd
, shell
=True)
47 exit_file
.write('%+04d' % exit_code
)
49 fcntl
.flock(exit_file
, fcntl
.LOCK_UN
)