aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2007-12-14 10:26:11 +0000
committerKeir Fraser <keir.fraser@citrix.com>2007-12-14 10:26:11 +0000
commit80197aaf427fe32302e8cbfc84a1aeeedfdc80df (patch)
tree38a05b4d2aca2545554ace1679ba3ca6e0b18726
parent29070efe2046543429dddf92a6b36c19f974c7f2 (diff)
downloadxen-80197aaf427fe32302e8cbfc84a1aeeedfdc80df.tar.gz
xen-80197aaf427fe32302e8cbfc84a1aeeedfdc80df.tar.bz2
xen-80197aaf427fe32302e8cbfc84a1aeeedfdc80df.zip
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>
-rw-r--r--tools/python/xen/util/xsm/acm/acm.py49
1 files changed, 36 insertions, 13 deletions
diff --git a/tools/python/xen/util/xsm/acm/acm.py b/tools/python/xen/util/xsm/acm/acm.py
index 7973a5b704..8bb0928c6e 100644
--- a/tools/python/xen/util/xsm/acm/acm.py
+++ b/tools/python/xen/util/xsm/acm/acm.py
@@ -1545,21 +1545,44 @@ def get_security_label(self, xspol=None):
label = self.info.get('security_label', label)
return label
+
+__cond = threading.Condition()
+__script_runner = None
+__orders = []
+
def run_resource_label_change_script(resource, label, command):
- def __run_resource_label_change_script(label, command):
+ global __cond, __orders, __script_runner
+
+ def __run_resource_label_change_script():
+ global __cond, __orders
script = XendOptions.instance().get_resource_label_change_script()
if script:
- parms = {
- 'resource' : resource,
- 'label' : label,
- 'command' : command,
- }
- log.info("Running resource label change script %s: %s" %
- (script, parms))
- parms.update(os.environ)
- os.spawnve(os.P_WAIT, script[0], script, parms)
+ parms = {}
+ while True:
+ __cond.acquire()
+ if len(__orders) == 0:
+ __cond.wait()
+
+ parms['label'], \
+ parms['command'], \
+ parms['resource'] = __orders[0]
+
+ __orders = __orders[1:]
+ __cond.release()
+
+ log.info("Running resource label change script %s: %s" %
+ (script, parms))
+ parms.update(os.environ)
+ os.spawnve(os.P_WAIT, script[0], script, parms)
else:
log.info("No script given for relabeling of resources.")
- thread = threading.Thread(target=__run_resource_label_change_script,
- args=(label,command))
- thread.start()
+ if not __script_runner:
+ __script_runner = \
+ threading.Thread(target=__run_resource_label_change_script,
+ args=())
+ __script_runner.start()
+
+ __cond.acquire()
+ __orders.append((label,command,resource))
+ __cond.notify()
+ __cond.release()