From f783766e2c1e291cff84b503675460f7d3d3dece Mon Sep 17 00:00:00 2001 From: Earnestly Date: Thu, 7 Dec 2017 13:06:46 +0000 Subject: [PATCH] sx: drop dependency on openssl Turns out openssl rand would obnoxiously create a HOME/.rnd dotfile unless told otherwise with the RANDFILE environment. Unfortunately this neither options are compelling and neither can openssl rand be told to not write this file. Instead I'm going to use /dev/urandom which appears to be available on practically every UNIX. This commit also tidies up the timeout kill logic to better express what I am doing. --- README | 2 +- sx | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) 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