summaryrefslogtreecommitdiffstats
path: root/core/modules/run-virt/data/opt/openslx/vmchooser
diff options
context:
space:
mode:
authorSimon Rettberg2023-06-05 16:19:22 +0200
committerSimon Rettberg2023-06-05 16:19:22 +0200
commit64893302017a8dacd25e4946a6ef5648fe59235b (patch)
treed6b99ee918240067303aa42ce6933ffde54d64aa /core/modules/run-virt/data/opt/openslx/vmchooser
parent[run-virt] Start fspanel after WM, refine traps in subshell (diff)
downloadmltk-64893302017a8dacd25e4946a6ef5648fe59235b.tar.gz
mltk-64893302017a8dacd25e4946a6ef5648fe59235b.tar.xz
mltk-64893302017a8dacd25e4946a6ef5648fe59235b.zip
[run-virt] Make sure cleanexit is not run from subshell
Diffstat (limited to 'core/modules/run-virt/data/opt/openslx/vmchooser')
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc12
-rwxr-xr-xcore/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt2
2 files changed, 13 insertions, 1 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 fe624ab5..3bfa8bb5 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
@@ -90,6 +90,11 @@ $BODY"
declare -ag CLEANUP_TASKS=()
add_cleanup() {
[ $# -lt 1 ] && writelog "'${FUNCNAME[0]}' needs at least one argument! $# given." && return
+ if [ "$BASHPID" != "$MAINPID" ]; then
+ writelog "WARNING: '${BASH_SOURCE[1]}:${FUNCNAME[1]}' tried to add cleanup hook '$1' in a subshell, this does not work... (main: $MAINPID, current: $BASHPID)"
+ else
+ writelog "Normal add_cleanup from '${BASH_SOURCE[1]}:${FUNCNAME[1]}' for '$1'"
+ fi
# check if the given function name is already used
while [ $# -ne 0 ]; do
if array_contains CLEANUP_TASKS "$1"; then
@@ -121,6 +126,11 @@ add_cleanup() {
cleanexit() {
trap "" SIGHUP SIGINT SIGTERM EXIT
writelog "Cleanexit '$1' triggered by '${BASH_SOURCE[1]}:${FUNCNAME[1]}'"
+ if [ "$BASHPID" != "$MAINPID" ]; then
+ writelog "Running in a subshell, killing parent... (main: $MAINPID, current: $BASHPID)"
+ kill "$MAINPID"
+ exit 0
+ fi
usleep 250000
local TASK
if [ "${#CLEANUP_TASKS[@]}" -gt 0 ]; then
@@ -151,7 +161,7 @@ cleanexit() {
# Now see if we need to do the catch all error stuff
# if 0 given, exit 0
- [ "x$1" = "x0" ] && exit 0
+ [ "$1" = "0" ] && exit 0
# if no code was given, exit 129
[ $# -eq 0 ] && writelog "Cleanexit called without arguments! Dev error?"
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt b/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt
index f5b79012..241e0f9e 100755
--- a/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt
@@ -85,6 +85,8 @@ fi
readonly LOGFILE
main() {
+ declare -rg MAINPID="$BASHPID"
+ writelog "MAINPID: $MAINPID"
# Functions needed by vmchooser-run_virt (writelog(), cleanexit(), safesource())
declare -rg RUN_VIRT_INCLUDE_DIR="${VMCHOOSER_DIR}/run-virt-includes"
if ! source "${RUN_VIRT_INCLUDE_DIR}/vmchooser_runvirt_functions.inc"; then