From 9f2c0c5fb457b4da3d29d67ccbc12010481dcf68 Mon Sep 17 00:00:00 2001 From: Earnestly Date: Fri, 8 Dec 2017 17:23:07 +0000 Subject: [PATCH] sx: no longer attempt to send SIGKILL Sending SIGKILL is not an appropriate response in most cases especially after an arbitrary timeout. If signals are being ignored it's likely due to D state. If the process is busy spinning in an infinite loop then bug reports need to be made. Papering over significant issues is worse for everyone in the end. This commit also trusts the PID we get is an xorg server process. I have no real reason to check outside of paranoia which borders on theater. Instead I check the PID is still alive and send TERM. Then we wait until it is done. Anything else is surely abnormal and needs manual intervention. --- sx | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/sx b/sx index da8c4d5..ef2a25e 100755 --- a/sx +++ b/sx @@ -8,26 +8,9 @@ set -o errexit cleanup() { - # Return to conventional flow control here as we need to continue - # regardless of failure. - set +o errexit - - if [ "$1" ] && [ "$(ps -o comm= "$1")" = Xorg ]; then - kill "$1" - - # Send SIGKILL after 10 seconds if the xserver is taking too long to - # terminate. - interval=10 - while kill -0 "$1" 2> /dev/null; do - if [ "$interval" -le 0 ]; then - if [ "$(ps -o comm= "$1")" = Xorg ]; then - kill -s KILL "$1" - fi - break - fi - interval=$((interval - 1)) - sleep 1 - done + if kill -0 "$1" 2> /dev/null; then + kill -s TERM "$1" + wait "$1" fi if ! stty "$stty"; then @@ -35,6 +18,7 @@ cleanup() { fi xauth remove :"$tty" + exit }