Earnestly / sx

Start an xorg server
MIT License
234 stars 16 forks source link

X left unkilled with `i3-msg exit` after 93f5000 #19

Closed tomty89 closed 3 years ago

tomty89 commented 4 years ago

Only the i3 processes are killed but not Xorg and sx (and others)

Earnestly commented 4 years ago

Yeah, that is somewhat the consequence of using -noreset. This is a tricky problem.

Earnestly commented 4 years ago

Can you try this diff?

diff --git a/sx b/sx
index 45371cb..35d06da 100755
--- a/sx
+++ b/sx
@@ -3,12 +3,10 @@
 # requires xauth Xorg /dev/urandom

 cleanup() {
-    for pid; do
-        if kill -0 "$pid" 2> /dev/null; then
-            kill "$pid"
-            wait "$pid"
-        fi
-    done
+    if kill -0 "$pid" 2> /dev/null; then
+        kill "$pid"
+        wait "$pid"
+    fi

     if ! stty "$stty"; then
         stty sane
@@ -31,10 +29,7 @@ touch -- "$XAUTHORITY"
 xauth add :"$tty" MIT-MAGIC-COOKIE-1 "$(od -An -N16 -tx /dev/urandom | tr -d ' ')"

 for signal in HUP INT TERM; do
-    # The client variable is set by the USR1 signal trap and contains the
-    # client's PID.
-    # shellcheck disable=SC2154
-    trap 'cleanup "$client" "$server"; trap - "$signal"; kill -s "$signal" "$$"' "$signal"
+    trap 'cleanup; trap - "$signal"; kill -s "$signal" "$$"' "$signal"
 done
 trap cleanup EXIT

@@ -43,8 +38,7 @@ trap cleanup EXIT
 # is ready to accept connections.
 # Taking advantage of this feature allows launching the client directly from a
 # USR1 signal trap which obviates the need to poll for server readiness.
-trap 'DISPLAY=:$tty "${@:-$cfgdir/sxrc}" & client=$!; wait' USR1
+trap 'trap - USR1; DISPLAY=:$tty "${@:-$cfgdir/sxrc}" & wait "$!"' USR1

-(trap '' USR1 && exec Xorg :"$tty" -keeptty vt"$tty" -noreset -auth "$XAUTHORITY") &
-server=$!
-wait
+(trap '' USR1 && exec Xorg :"$tty" -keeptty vt"$tty" -noreset -auth "$XAUTHORITY" ) & pid=$!
+wait "$pid"
tomty89 commented 3 years ago

That works

Earnestly commented 3 years ago

Hopefully this addresses all potential cases.