ia64/xen-unstable

changeset 16615:61ff9b393c83

acm, xend: Serialize the execution of external scripts.

Instead of starting a thread per script, run a single thread and send
orders to it. This serializes the execution of the scripts.

Signed-off-by: Stefan Berger <stefanB@us.ibm.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Dec 14 10:26:11 2007 +0000 (2007-12-14)
parents 8aa377fb1b1f
children 301507ac350a
files tools/python/xen/util/xsm/acm/acm.py
line diff
     1.1 --- a/tools/python/xen/util/xsm/acm/acm.py	Fri Dec 14 10:25:00 2007 +0000
     1.2 +++ b/tools/python/xen/util/xsm/acm/acm.py	Fri Dec 14 10:26:11 2007 +0000
     1.3 @@ -1545,21 +1545,44 @@ def get_security_label(self, xspol=None)
     1.4          label = self.info.get('security_label', label)
     1.5      return label
     1.6  
     1.7 +
     1.8 +__cond = threading.Condition()
     1.9 +__script_runner = None
    1.10 +__orders = []
    1.11 +
    1.12  def run_resource_label_change_script(resource, label, command):
    1.13 -    def __run_resource_label_change_script(label, command):
    1.14 +    global __cond, __orders, __script_runner
    1.15 +
    1.16 +    def __run_resource_label_change_script():
    1.17 +        global __cond, __orders
    1.18          script = XendOptions.instance().get_resource_label_change_script()
    1.19          if script:
    1.20 -            parms = {
    1.21 -                'resource' : resource,
    1.22 -                'label'    : label,
    1.23 -                'command'  : command,
    1.24 -            }
    1.25 -            log.info("Running resource label change script %s: %s" %
    1.26 -                     (script, parms))
    1.27 -            parms.update(os.environ)
    1.28 -            os.spawnve(os.P_WAIT, script[0], script, parms)
    1.29 +            parms = {}
    1.30 +            while True:
    1.31 +                __cond.acquire()
    1.32 +                if len(__orders) == 0:
    1.33 +                    __cond.wait()
    1.34 +
    1.35 +                parms['label'], \
    1.36 +                   parms['command'], \
    1.37 +                   parms['resource'] = __orders[0]
    1.38 +
    1.39 +                __orders = __orders[1:]
    1.40 +                __cond.release()
    1.41 +
    1.42 +                log.info("Running resource label change script %s: %s" %
    1.43 +                         (script, parms))
    1.44 +                parms.update(os.environ)
    1.45 +                os.spawnve(os.P_WAIT, script[0], script, parms)
    1.46          else:
    1.47              log.info("No script given for relabeling of resources.")
    1.48 -    thread = threading.Thread(target=__run_resource_label_change_script,
    1.49 -                              args=(label,command))
    1.50 -    thread.start()
    1.51 +    if not __script_runner:
    1.52 +        __script_runner = \
    1.53 +                 threading.Thread(target=__run_resource_label_change_script,
    1.54 +                                  args=())
    1.55 +        __script_runner.start()
    1.56 +
    1.57 +    __cond.acquire()
    1.58 +    __orders.append((label,command,resource))
    1.59 +    __cond.notify()
    1.60 +    __cond.release()