Commit d355a78e by Eric Coissac

Change the comportement and API of the run function

parent aa244fd7
...@@ -49,8 +49,13 @@ __LECABASH__trap_function__() { ...@@ -49,8 +49,13 @@ __LECABASH__trap_function__() {
loginfo "Signal ${signal} trapped" loginfo "Signal ${signal} trapped"
echo "#@#@#@"
eval echo "\${${stackname}[*]}"
echo "#@#@#@"
if [[ $(stacksize $stackname) > 0 ]]; then if [[ $(stacksize $stackname) > 0 ]]; then
while popvalue "$stackname" cmd ; do while popvalue "$stackname" cmd ; do
logdebug "Running ${signal} command : $cmd"
eval "$cmd" eval "$cmd"
done done
loginfo "Commands registered on signal $signal run." loginfo "Commands registered on signal $signal run."
...@@ -94,20 +99,31 @@ __LECABASH__registered_trap__() { ...@@ -94,20 +99,31 @@ __LECABASH__registered_trap__() {
split($0,parts,"--");\ split($0,parts,"--");\
print parts[2]}') print parts[2]}')
eval "echo $command" echo "$command"
}
__LECABASH__kill_running_command__() {
local signal=$1
local pid=$2
loginfo "Sending signal ${signal} to process ${pid}"
kill -s ${signal} ${pid}
} }
function registertrap() { function registertrap() {
local signal=$1 local signal=$1
shift shift
local cmd="${*}"
local stackname="$(__LECABASH__signal_trap_stack_name__ ${signal})" local stackname="$(__LECABASH__signal_trap_stack_name__ ${signal})"
if ! __LECABASH__istrapregistred__ "$signal" ; then if ! __LECABASH__istrapregistred__ "$signal" ; then
local stackname="$(__LECABASH__signal_trap_stack_name__ ${signal})"
newstack $stackname newstack $stackname
local oldcmd=$(__LECABASH__registered_trap__ "$signal") local oldcmd=$(__LECABASH__registered_trap__ "$signal")
if [[ oldcmd != "" ]] ; then if [[ oldcmd != "" ]] ; then
logdebug "Save previous trap function for signal $signal"
pushvalue "$stackname" "${oldcmd}" pushvalue "$stackname" "${oldcmd}"
fi fi
...@@ -115,11 +131,24 @@ function registertrap() { ...@@ -115,11 +131,24 @@ function registertrap() {
trap "__LECABASH__trap_function__ $signal" "$signal" trap "__LECABASH__trap_function__ $signal" "$signal"
fi fi
loginfo "Register new command on $signal : ${*}" loginfo "Register new command on $signal : ${cmd}"
pushvalue "$stackname" "${*}" pushvalue "$stackname" "${cmd}"
} }
function run() { function run() {
${*} & local signal=$1
shift
local signalto=$1
shift
local stackname="$(__LECABASH__signal_trap_stack_name__ ${signal})"
eval ${*} &
fpid=$!
registertrap ${signal} __LECABASH__kill_running_command__ ${signalto} ${fpid}
killid=$(( $(stacksize "$stackname") - 1 ))
wait wait
logdebug "Remove kill action on $fpid for $signal signal"
eval "${stackname}[${killid}]='sleep 0'"
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment