1 #!/usr/bin/python 2 3 import common 4 import sys, os, subprocess, fcntl 5 6 7 bindir = os.path.dirname(__file__) 8 autotest = os.path.join(bindir, 'autotest') 9 10 logdir = sys.argv[1] 11 12 13 # We want to simulate the behaviour of autotest_client, where fd3 would be 14 # routed to stderr and fd1 & fd2 to stdout 15 16 # HACK: grab fd3 for now 17 os.dup2(2, 3) 18 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) 22 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) 27 28 # we don't need the file objects any more 29 stdout.close() 30 stderr.close() 31 32 33 args = [autotest] + sys.argv[2:] 34 if '-H' not in args: 35 args[1:1] = ['-H', 'autoserv'] 36 cmd = ' '.join(args) 37 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) 41 42 # touch a 'started' file to indicate we've been initialized 43 open(os.path.join(logdir, 'started'), 'w').close() 44 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) 48 exit_file.flush() 49 fcntl.flock(exit_file, fcntl.LOCK_UN) 50 exit_file.close() 51