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.
This commit is contained in:
Earnestly 2017-12-01 20:59:00 +00:00
parent 161b8be6f5
commit 6b089b8d50
1 changed files with 4 additions and 5 deletions

9
sx
View File

@ -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