sx: split out termination from cleanup handler

Due to the use of errexit when Xorg replied back to us with SIGUSR1 the
subshell would return an exit status of 128 + 10 (SIGUSR1)[1].

This combined with trap handlers not changing the exit value unless
explicitly done with exit $? means sx was always exiting with a status
of 138.

This change instead removes errexit and simply lets unset or erroneous
commands leak through until it hits a point where the combined errors
result in non-zero termination.

By splitting out the termination of Xorg to the end we can simply return
the return value from the last wait, which is the wait associated with
Xorg itself.

1. http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_28
This commit is contained in:
Earnestly 2017-12-11 16:52:07 +00:00
parent 8d21a607bf
commit 666b87ef26
1 changed files with 7 additions and 11 deletions

18
sx
View File

@ -3,22 +3,12 @@
# requires xauth Xorg # requires xauth Xorg
# I'm willing to take advantage of errexit for this script as roughly 85% of
# the error checking would just be exiting on command failure.
set -o errexit
cleanup() { cleanup() {
if kill -0 "$1" 2> /dev/null; then
kill -s TERM "$1"
wait "$1"
fi
if ! stty "$stty"; then if ! stty "$stty"; then
stty sane stty sane
fi fi
xauth remove :"$tty" xauth remove :"$tty"
exit
} }
stty=$(stty -g) stty=$(stty -g)
@ -48,4 +38,10 @@ trap 'DISPLAY=:$tty "${@:-$cfgdir/sxrc}"' USR1
trap '' USR1 trap '' USR1
exec /usr/lib/xorg-server/Xorg :"$tty" -keeptty vt"$tty" -noreset -auth "$XAUTHORITY" exec /usr/lib/xorg-server/Xorg :"$tty" -keeptty vt"$tty" -noreset -auth "$XAUTHORITY"
) & pid=$! ) & pid=$!
wait
wait "$pid"
if kill -0 "$pid" 2> /dev/null; then
kill -s TERM "$pid"
wait "$pid"
fi