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.
This commit is contained in:
Earnestly 2017-12-07 13:06:46 +00:00
parent ef5ed45959
commit f783766e2c
2 changed files with 10 additions and 12 deletions

2
README
View File

@ -37,7 +37,7 @@ REQUIRES
* Xorg
* xauth
* openssl (used to generate the MIT-MAGIC-COOKIE-1 value)
* /dev/urandom
INSTALL

24
sx
View File

@ -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
break
fi
sleep 1
interval=$((interval - 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
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
interval=$((interval - 1))
sleep 1
done
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