From 6b089b8d5034af49c459c21b52f4f0b228c8eb50 Mon Sep 17 00:00:00 2001 From: Earnestly Date: Fri, 1 Dec 2017 20:59:00 +0000 Subject: [PATCH] sx: unconditionally run xauth remove in cleanup Even if xauth(1) fails before we get a $pid for cleanup, make sure to run xauth remove during cleanup. --- sx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sx b/sx index c5c9411..6e40359 100755 --- a/sx +++ b/sx @@ -23,7 +23,7 @@ cleanup() { # regardless of failure. set +o errexit - if [ "$(ps -o comm= "$1")" = Xorg ]; then + if [ "$1" ] && [ "$(ps -o comm= "$1")" = Xorg ]; then kill "$1" # Send SIGKILL after 10 seconds if the xserver is taking too long to @@ -34,18 +34,17 @@ cleanup() { 124) kill -s KILL "$1" esac - xauth remove :"$tty" fi if ! stty "$stty"; then stty sane fi + xauth remove :"$tty" exit } stty=$(stty -g) - tty=$(ps -o tty= $$) case $tty in @@ -58,11 +57,11 @@ XAUTHORITY=${XAUTHORITY:-$cfgdir/xauthfile} mkdir -p "$cfgdir" "$datadir" -trap 'cleanup "$pid"' EXIT - touch "$XAUTHORITY" export XAUTHORITY +trap 'cleanup "$pid"' EXIT + xauth add :"$tty" MIT-MAGIC-COOKIE-1 "$(mcookie)" # Xorg will check if SIGUSR1 was set to SIG_IGN in its environment and issue