3
# Copyright (c) 2014 OpenStack Foundation
5
# Licensed under the Apache License, Version 2.0 (the "License");
6
# you may not use this file except in compliance with the License.
7
# You may obtain a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
23
log = logging.getLogger()
24
hdlr = logging.FileHandler(sys.argv[0]+".log")
25
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
26
hdlr.setFormatter(formatter)
28
log.setLevel(logging.DEBUG)
32
def handle_signal(signum, stack):
34
log.info("Sent SIGINT to subprocess")
37
log.info("Running %s" % ' '.join(sys.argv[1:]))
40
# "Unignore" SIGINT before the subprocess is launched
41
# in case this process is running in the background
42
# (background processes ignore SIGINT)
43
signal.signal(signal.SIGINT, signal.SIG_DFL)
45
# Interpret all command line args as the command to run
46
a = subprocess.Popen(sys.argv[1:],
47
stdout=open("stdout", "w"),
48
stderr=open("stderr", "w"))
50
# Set our handler to trap SIGINT and propagate to the child
51
# The expectation is that the child process handles SIGINT
53
signal.signal(signal.SIGINT, make_handler(a))
55
# Write out the childpid just in case there is a
56
# need to send special signals directly to the child process
57
open("childpid", "w").write("%s\n" % a.pid)
59
# Wait for child to exit and write result file
60
log.info("Waiting for subprocess %s" % a.pid)
62
log.info("Subprocess exit status %s" % ret)
63
open("result", "w").write("%s\n" % ret)
65
except Exception as e: