diff --git a/README b/README index 360cc43..0192adf 100644 --- a/README +++ b/README @@ -37,7 +37,7 @@ REQUIRES * Xorg * xauth - * openssl (used to generate the MIT-MAGIC-COOKIE-1 value) + * /dev/urandom INSTALL diff --git a/sx b/sx index 22af665..54ff537 100755 --- a/sx +++ b/sx @@ -1,7 +1,7 @@ #!/bin/sh -- # sx - start an xserver -# requires openssl 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. @@ -18,18 +18,17 @@ cleanup() { # Send SIGKILL after 10 seconds if the xserver is taking too long to # terminate. interval=10 - until [ "$interval" -le 0 ]; do - if ! kill -0 "$1"; then + while kill -0 "$1"; do + if [ "$interval" -le 0 ]; then + # Make sure the PID is still (probably) an Xorg process. + if [ "$(ps -o comm= "$1")" = Xorg ]; then + kill -s KILL "$1" + fi break fi - sleep 1 interval=$((interval - 1)) + sleep 1 done - - # Make sure that the PID still refers to an Xorg process - if test "$interval" -le 0 -a "$(ps -o comm= "$1")" = Xorg; then - kill -s KILL "$1" - fi fi if ! stty "$stty"; then @@ -55,7 +54,7 @@ touch "$XAUTHORITY" trap 'cleanup "$pid"' EXIT -xauth add :"$tty" MIT-MAGIC-COOKIE-1 "$(openssl rand -hex 16)" +xauth add :"$tty" MIT-MAGIC-COOKIE-1 "$(od -An -N16 -tx /dev/urandom | tr -d ' ')" # Xorg will check if SIGUSR1 was set to SIG_IGN in its environment and issue # its own SIGUSR1 back to the parent process when it is ready to accept @@ -68,5 +67,4 @@ trap 'DISPLAY=:$tty "${@:-$cfgdir/sxrc}"' USR1 trap '' USR1 exec /usr/lib/xorg-server/Xorg :"$tty" -keeptty vt"$tty" -noreset -auth "$XAUTHORITY" ) & pid=$! - wait