Commit Graph

23 Commits

Author SHA1 Message Date
Earnestly 1c4fbda36c sx: traps can explicitly set an exit status
The prior commit 666b87e would still fail if the sx program itself was
killed leaving an xorg server behind.  While trap handlers aren't
typically allowed to change the exit status, if we explicitly exit with
a value then it is honoured.

This works around the subshell setting an exit status of 138 (due to
SIGUSR1) by explicitly using the return value from the last wait or the
last command if the server never started at all.
2017-12-13 13:53:44 +00:00
Earnestly 666b87ef26 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
2017-12-11 16:52:07 +00:00
Earnestly 8d21a607bf doc: mention that the login tty is reused 2017-12-11 16:47:46 +00:00
Earnestly a488db27fa doc: mention that we don't use -listen 2017-12-09 23:34:20 +00:00
Earnestly 015319b2d7 doc: manuals should not have empty lines 2017-12-09 19:51:53 +00:00
Earnestly 9f2c0c5fb4 sx: no longer attempt to send SIGKILL
Sending SIGKILL is not an appropriate response in most cases especially
after an arbitrary timeout.  If signals are being ignored it's likely
due to D state.  If the process is busy spinning in an infinite loop
then bug reports need to be made.  Papering over significant issues is
worse for everyone in the end.

This commit also trusts the PID we get is an xorg server process.  I
have no real reason to check outside of paranoia which borders on theater.

Instead I check the PID is still alive and send TERM.  Then we wait
until it is done.  Anything else is surely abnormal and needs manual
intervention.
2017-12-08 17:23:07 +00:00
Earnestly 1b3506d21f doc: mention XDG_CONFIG_HOME environments 2017-12-08 17:18:15 +00:00
Earnestly 29953f64b7 sx: silence kill -0 diagnostics
This condition will always be triggered even if the Xorg server
terminates promptly.  This will simply result in confusing diagnostics
being printed in the common case.  As kill has no quiet option, I will
have to unfortunately silence them instead.
2017-12-08 11:35:31 +00:00
Earnestly 24a0495086 sx: test -a may not be short-circuiting
I was under the false assumption that -a, like &&, was used
short-circuit semantics.  However the behaviour of -a is not specified
by POSIX.

At least on Linux using bash or dash the behaviour is not
short-circuiting.

As there's no reason to test the RHS if the LHS is false I've switched
back to [ ] && notation which is defined to be short-circuiting.
2017-12-07 15:38:44 +00:00
Earnestly f783766e2c 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.
2017-12-07 13:06:46 +00:00
Earnestly ef5ed45959 sx: mention openssl requirement 2017-12-07 12:08:19 +00:00
Earnestly 718add311c doc: clarify purpose and bump the manual date 2017-12-07 12:03:43 +00:00
Earnestly 30457a3139 sx: drop dependencies on coreutils and util-linux
Upon review of GNU tail I discovered that the implemention of --pid was
the same method as polling kill -0 on a sleep interval, which defaults
to 1 second unless -s is used.

This is perhaps expected due to the lack of a pwait(2) system call, I
decided to implement the same mechanic myself and drop both the
requirement on GNU tail and GNU timeout at the same time.

This commit also replaces mcookie from util-linux with openssl rand
which is used to generate a random MD5 checksum for use in the
MIT-MAGIC-COOKIE-1 value.
2017-12-07 11:58:40 +00:00
Earnestly 39702615b7 sx: fgconsole is no longer needed 2017-12-05 10:04:27 +00:00
Earnestly 64038adef2 sx: create XAUTHORITY directory components
We need to do this in sx as neither xauth(1) or touch(1) will create the
path.  Requiring the user to do this would lead to additional code on
their side to account for a detail that sx already controls.  There
is no obvious benefit for omitting this functionality.
2017-12-04 11:58:32 +00:00
Earnestly 60762a5487 doc: clarify how XAUTHORITY is used 2017-12-04 11:58:00 +00:00
Earnestly f25cbb415d sx: test has clearer syntax when AND or OR is used 2017-12-04 11:56:45 +00:00
Earnestly a5fc2e3907 sx: combine export and assignment 2017-12-02 11:40:28 +00:00
Earnestly e08bc130c0 sx: use the default logfile
There's not a lot of point in absorbing the xserver's log file when it
will just be less intuitive for those looking for it in the standard
location.  Since the log is generated by Xorg and not sx, it only seems
reasonable.

This commit also renames xauthfile to xauthority for a little more
consistency with documentation and prior art.
2017-12-02 02:22:29 +00:00
Earnestly 29e20b2e41 sx: remove unused code 2017-12-02 02:17:10 +00:00
Earnestly 95f648452f README: mention the Xorg.wrap bypass
Xorg.wrap default system of autodetection of root rights requirement is
wrong in every case I've seen it used.  The result is the Xorg server
runs as the root user when it is not necessary.

The main autodetection failure case is when the proprietary nvidia
drivers are used, incorrectly assuming Xorg needs to be run as root.
2017-12-01 21:15:06 +00:00
Earnestly 6b089b8d50 sx: unconditionally run xauth remove in cleanup
Even if xauth(1) fails before we get a $pid for cleanup, make sure to
run xauth remove during cleanup.
2017-12-01 20:59:00 +00:00
Earnestly 161b8be6f5 introduce sx 2017-12-01 20:14:54 +00:00