From 666b87ef260339ae16526dd2673ccbbd1ba2b981 Mon Sep 17 00:00:00 2001 From: Earnestly Date: Mon, 11 Dec 2017 16:52:07 +0000 Subject: [PATCH] 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 --- sx | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/sx b/sx index 8ffed4a..bad8d13 100755 --- a/sx +++ b/sx @@ -3,22 +3,12 @@ # 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() { - if kill -0 "$1" 2> /dev/null; then - kill -s TERM "$1" - wait "$1" - fi - if ! stty "$stty"; then stty sane fi xauth remove :"$tty" - exit } stty=$(stty -g) @@ -48,4 +38,10 @@ trap 'DISPLAY=:$tty "${@:-$cfgdir/sxrc}"' USR1 trap '' USR1 exec /usr/lib/xorg-server/Xorg :"$tty" -keeptty vt"$tty" -noreset -auth "$XAUTHORITY" ) & pid=$! -wait + +wait "$pid" + +if kill -0 "$pid" 2> /dev/null; then + kill -s TERM "$pid" + wait "$pid" +fi