improved terminate/kill

This commit is contained in:
Michael Krayer 2021-04-19 20:42:01 +02:00
parent 5ec382f839
commit 2597e61256
1 changed files with 11 additions and 12 deletions

23
session
View File

@ -294,11 +294,9 @@ case $mode in
"terminate"|"term"|"t"|"kill"|"k") "terminate"|"term"|"t"|"kill"|"k")
# Check if we are in terminate/kill mode # Check if we are in terminate/kill mode
if [[ ${mode::1} == "k" ]]; then if [[ ${mode::1} == "k" ]]; then
SIGNAL="-9" # SIGKILL SIGNAL="-SIGKILL"
CLEANUP=1 # requires manual cleanup
else else
SIGNAL="-15" # SIGTERM SIGNAL="-SIGTERM"
CLEANUP=0
fi fi
# If no session name specified: terminate all sessions # If no session name specified: terminate all sessions
if [ -z "$1" ]; then if [ -z "$1" ]; then
@ -317,15 +315,16 @@ case $mode in
exit_if_nonexisting_session $session_name exit_if_nonexisting_session $session_name
fi fi
for sname in ${session_name[@]}; do for sname in ${session_name[@]}; do
logpath=$(get_log_path $sname)
PID=$(get_session_pid $sname) PID=$(get_session_pid $sname)
if [ ! -z "$PID" ]; then session_path=$(get_session_path $sname)
CMD="kill $SIGNAL $PID" log_path=$(get_log_path $sname)
eval $CMD fifo_path=$(get_fifo_path $sname)
else # this seems to be an orphan [[ -a $fifo_path ]] && echo > $fifo_path
CLEANUP=1 [[ ! -z "$PID" ]] && kill $SIGNAL $PID
fi tail --pid=$PID -f /dev/null
[[ "$CLEANUP" -eq 1 ]] && rm $(get_session_path $sname) [[ -a $session_path ]] && rm -f $session_path
[[ -a $fifo_path ]] && rm -f $fifo_path
[[ -f $log_path ]] && rm -f $log_path
done done
exit $EXIT_SUCCESS exit $EXIT_SUCCESS
;; ;;