summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-09-10 15:42:33 +0200
committerSimon Rettberg2019-09-10 15:42:33 +0200
commitce94a54717f657dd0305fb75c3294cd36742bad6 (patch)
treed4d7b210f175e413733ae4bfb41903733ad9b912
parent[run-virt] Add window manager respawn loop (diff)
downloadmltk-ce94a54717f657dd0305fb75c3294cd36742bad6.tar.gz
mltk-ce94a54717f657dd0305fb75c3294cd36742bad6.tar.xz
mltk-ce94a54717f657dd0305fb75c3294cd36742bad6.zip
[run-virt] Run cleanup functions in parallel
Spawns a subshell for each cleanup function, then waits for up to 4 seconds for them to complete...
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc30
1 files changed, 18 insertions, 12 deletions
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
index 08ab4f72..2bd8edad 100644
--- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
@@ -127,18 +127,24 @@ cleanexit() {
trap "" SIGHUP SIGINT SIGTERM EXIT
writelog "Cleanexit '$1' triggered by '${BASH_SOURCE[1]}:${FUNCNAME[1]}'"
usleep 250000
- while isset CLEANUP_TASKS; do
- local TASK=${CLEANUP_TASKS[-1]}
- unset -v CLEANUP_TASKS[-1]
- if ! is_function $TASK; then
- writelog "Registered cleanup function '$TASK' is not a function. This should not be..."
- continue
- fi
- if ! ${TASK}; then
- writelog "Failed to run cleanup function '$TASK'! Exit code: $RET"
- fi
- done
- usleep 250000
+ local TASK
+ if [ "${#CLEANUP_TASKS[@]}" -gt 0 ]; then
+ declare -a cleanups=
+ declare -a copy=( "${CLEANUP_TASKS[@]}" )
+ unset CLEANUP_TASKS
+ for TASK in "${copy[@]}"; do
+ if ! is_function "$TASK"; then
+ writelog "Registered cleanup function '$TASK' is not a function. This should not be..."
+ continue
+ fi
+ "${TASK}" &
+ cleanups+=( "$!" )
+ done
+ for i in 1 1 2 2 3 3 4 4; do
+ usleep 500000
+ kill -0 "${cleanups[@]}" &> /dev/null || break
+ done
+ fi
# kill potential remaining background jobs
kill $(jobs -p)