Commit Graph

47 Commits

Author SHA1 Message Date
randomuser bb8814b496 change /usr/local to home/.local 2022-12-22 15:28:11 -06:00
earnestly 8be499c200 doc: hopefully more clarity on need for xwrapper 2022-07-20 20:15:07 +01:00
earnestly b627ee1ab5 sx: several minor reworks
Calling exit directly in the relevant trap instead of using an argument
to decide when to trigger an exit in the cleanup function.

Additionally the EXIT trap is ignored in the INT trap so that when
running under bash the EXIT trap does not call cleanup again.

As `xauth remove :n' does not trigger warnings or problems for nonextant
entries it is safe to set the cleanup traps prior to using `xauth add'.
This removes a very minor potential race condition between adding an
entry and the script being interrupted before cleanup traps have been
established.  Suggested by @tomty89

Finally, attempt to make the main comment a little less awkward.
2021-08-10 14:59:58 +01:00
earnestly 73e70bc00d doc: update sx version and date
Regroup SEE ALSO section manuals by their section number.
2021-07-06 23:30:41 +01:00
earnestly 2ef0b3bf03 sx: The signal saga concludes
This ought to be the last effort on signal handling.

Prior to this design the resending of the signals was ineffective due to
the cleanup function explicitly calling exit.  As a result this would
prevent the subsequent commands in the trap from executing.

Instead a variable is employed to guard the exit on condition of not
receiving an INT signal.  On UNIX systems this particular signal needs
to be resent such that the calling program knows the process was
interrupted.  See https://www.cons.org/cracauer/sigint.html

This situation exists because, besides bash, all shells treat EXIT traps
as a mechanism to execute code after the program ends, as if the code it
runs was pasted at the end of the file, rather than to run it however the
program terminated.
2021-07-04 16:20:40 +01:00
earnestly e3687899a2 doc: Further rationale
Note that startx itself does call upon admins to improve the script for
their particular situation.

This also removes the example using DESTDIR as any package maintainer
would already be familiar with this standard and expect it to work
implicitly.  For those who aren't familiar it merely serves as minor
confusion.
2021-07-04 15:08:20 +01:00
Earnestly 2742daede4 sx: further tuning the signal situation
This commit removes the complication of trying to handle client PIDs as
doing so didn't provide any noticable gain.  The main issue was that
both `wait' commands didn't wait on their respective PIDs while the
final cleanup wasn't called with both client and server PIDs and so
the server remained running due to -noreset.

The exit status of `sx' should again reflect that of the Xorg's
which may be useful for scripts.

Also slightly improves the comments on how Xorg handles USR1 signals.

Fixes https://github.com/Earnestly/sx/issues/19
2020-10-06 19:31:07 +01:00
Earnestly 93f50006dc sx: implement more robust signal handling
This ought to address the majority of the issues presented in
https://github.com/Earnestly/sx/issues/15
2020-09-24 13:52:34 +01:00
Earnestly 72ae82f648 sx: prevent wordsplitting on export
Although there is apparently an update to this aspect of POSIX[0] it is
possible for an implementation[1] to induce wordsplitting during an export
assignment.

For example, with both mrsh and an older version of dash, the following
behaviour is observed:

        $ var='contains spaces'
        $ export ENVAR=$var
        $ printf '[%s]\n' "$ENVAR"
        [contains]

This commit additionally guards against file names containing leading
hyphens as is possible with user supplied inputs.

0. https://git.kernel.org/pub/scm/utils/dash/dash.git/commit/?id=cbb71a836874d176809a34e22f6b6e4e3ba8c85b
1. https://github.com/emersion/mrsh/issues/150
2020-05-21 22:03:42 +01:00
Earnestly 021a64558d make: use more GNU directory variables
A set of conventions[0] that I think are quite nice outside of
autotools.

0. https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
2020-05-21 21:59:02 +01:00
prez d4e10c871b sx: portability 2020-02-15 21:14:25 +00:00
Earnestly 521d3c92d0 sx: correct the usage of ps
There appears to be no indication according to the POSIX synopsis[1] of
the ps command that it shall take a PID argument as positional.  The
rest of the document doesn't suggest such a case either.

What the document does provide is the `-p' flag to specify a list of
PIDs with which ps will narrow the results.

1. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html
2019-12-06 12:05:15 +00:00
Earnestly 41a6a9b372 doc: include examples and clarify usage
Sometimes people encode logic into files such as Xinitrc which absorbs
command-line arguments that typically control which window manager or
desktop environment to start.

These examples demonstrate how they might do this with sxrc and other
suggestions for reusing ~/.Xinitrc
2019-02-06 18:54:34 +00:00
Earnestly 7073e7df87 make: remove non-posix features
For better or worse.
2019-02-06 18:54:07 +00:00
Earnestly 956be33728 sx: remove case check on tty
Substring removal using the '#' form will already try to match from the
beginning of the string.

If the output from ps does not start with "tty" then nothing will be
removed.
2018-12-14 14:51:26 +00:00
Earnestly d2919f5b62 doc: grammatical correction and clarification
This emphasises that the command need not have arguments.  Additionally
include a reference to Xwrapper.config(5) as mentioned in the NOTE.
2018-10-21 17:14:48 +01:00
Earnestly 069d745d44 doc: move notes to manual and clarify the synopsis
Since the README is not intended to be installed to the system it makes
sense to provide the NOTES section in the manual itself which is.

This also expands the SYNOPSIS section to indicate that the usage of sx
should work as a typical chain command.
2018-10-14 11:25:17 +01:00
Earnestly 8d75ae233b doc: improve the typesetting 2018-08-04 15:57:01 +01:00
Earnestly 67330907da doc: clarify and update README
Correct the location mentioning the xauthority to XDG_DATA_HOME instead
of XDG_CONFIG_HOME.

Clarify why the server sets DISPLAY to 1 instead of naturally
incrementing until an unused slot is found.
2018-08-04 15:34:29 +01:00
Earnestly bedb6e313b doc: rationale is a noun 2018-08-04 15:27:50 +01:00
Earnestly 887df364fe sx: use XDG_DATA_HOME for the authority
The authority file should not really be considered configuration data
especially in the context of backups which might want to exclude such
content.
2018-07-19 14:14:54 +01:00
Earnestly bf8652401d sx: slightly clarity the signal negotiation
This should properly emphasise that we are receiving a USR1 signal back
from the server itself.
2018-07-19 14:07:12 +01:00
Earnestly 3db3447aa4 doc: mention a workaround for Xorg.wrap 2018-07-19 14:06:16 +01:00
Nameless b8c45edb31 Adjust sx to work with Xorg 1.20 (and older)
Since Xorg 1.20 the location of the primary binary has changed making it
impossible to support both 1.20 and previous versions.

So instead I'm switching to the `Xorg' command directly which won't
bypass Xorg.wrap in older versions, but since Xorg 1.20, the `Xorg'
command doesn't use it.
2018-05-13 23:25:22 +01:00
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