├── LICENSE ├── Makefile ├── README ├── sx └── sx.1 /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 Earnestly 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | .SUFFIXES: 3 | 4 | PREFIX = /usr/local 5 | bindir = $(PREFIX)/bin 6 | datarootdir = $(PREFIX)/share 7 | mandir = $(datarootdir)/man 8 | man1dir = $(mandir)/man1 9 | 10 | install: sx sx.1 11 | mkdir -p -- $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir) 12 | cp -f -- sx $(DESTDIR)$(bindir)/sx 13 | chmod -- +x $(DESTDIR)$(bindir)/sx 14 | cp -f -- sx.1 $(DESTDIR)$(man1dir)/sx.1 15 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | sx 2 | 3 | INTRODUCTION 4 | 5 | sx is a simple alternative to both xinit(1) and startx(1) for starting 6 | an Xorg server. 7 | 8 | It started life as a proof of concept while attempting to learn how both 9 | xinit and startx worked while taking up the offer presented in startx: 10 | 11 | > Site administrators are STRONGLY urged to write nicer versions. 12 | 13 | It is not a direct replacement however as it provides a different, more 14 | limited, interface. 15 | 16 | Some of these major differences are listed here: 17 | 18 | * The server's command-line is hard coded and not exposed to the user. 19 | * The server doesn't listen on anything except unix domain sockets. 20 | * The server starts on the same tty the user logged in on. 21 | * The first DISPLAY is 1 instead of 0 contrary to what X(7) suggests 22 | as it is coupled to the tty number. 23 | * xauth entries are overwritten if the displayname is identical. 24 | * Corresponding xauth entries are unconditionally removed when the 25 | server exits. 26 | * The server uses the -noreset flag. 27 | * While XAUTHORITY is still honoured, $XDG_DATA_HOME/sx/xauthority is 28 | used by default instead of $HOME/.Xauthority 29 | * Very little proxy error checking is used preferring instead to let 30 | each tool speak for itself. 31 | * None of the typical /etc/X11/xinit infrastructure is directly used. 32 | * Neither XINITRC is honoured nor .xinitrc used. 33 | * The XDG_CONFIG_HOME/sx/sxrc file is used instead of .xinitrc and is 34 | required to be executable. 35 | 36 | For a rationale on why this exists the author invites the reader to 37 | look over the source code for both xinit and startx. 38 | 39 | REQUIRES 40 | 41 | * Xorg 42 | * xauth 43 | * /dev/urandom 44 | 45 | INSTALL 46 | 47 | make PREFIX=/usr install 48 | -------------------------------------------------------------------------------- /sx: -------------------------------------------------------------------------------- 1 | #!/bin/sh -- 2 | # sx - start an xorg server 3 | # requires xauth Xorg /dev/urandom 4 | 5 | cleanup() { 6 | if [ "$server" ] && kill -0 "$server" 2> /dev/null; then 7 | kill "$server" 8 | wait "$server" 9 | xorg=$? 10 | fi 11 | 12 | if ! stty "$stty"; then 13 | stty sane 14 | fi 15 | 16 | xauth remove :"$tty" 17 | } 18 | 19 | stty=$(stty -g) 20 | tty=$(tty) 21 | tty=${tty#/dev/tty} 22 | 23 | cfgdir=${XDG_CONFIG_HOME:-$HOME/.config}/sx 24 | datadir=${XDG_DATA_HOME:-$HOME/.local/share}/sx 25 | mkdir -p -- "$cfgdir" "$datadir" 26 | 27 | export XAUTHORITY="${XAUTHORITY:-$datadir/xauthority}" 28 | touch -- "$XAUTHORITY" 29 | 30 | trap 'cleanup; exit "${xorg:-0}"' EXIT 31 | 32 | for signal in HUP INT QUIT TERM; do 33 | # shellcheck disable=SC2064 34 | trap "cleanup; trap - $signal EXIT; kill -s $signal $$" "$signal" 35 | done 36 | 37 | # Xorg will return a USR1 signal to the parent process indicating it is ready 38 | # to accept connections if it inherited a USR1 signal with a SIG_IGN 39 | # disposition. Consequently a client may be started directly from a USR1 40 | # signal handler and obviate the need to poll for server readiness. 41 | trap 'DISPLAY=:$tty "${@:-$cfgdir/sxrc}" & wait "$!"' USR1 42 | 43 | xauth add :"$tty" MIT-MAGIC-COOKIE-1 "$(od -An -N16 -tx /dev/urandom | tr -d ' ')" 44 | (trap '' USR1 && exec Xorg :"$tty" vt"$tty" -keeptty -noreset -auth "$XAUTHORITY") & 45 | server=$! 46 | wait "$server" 47 | -------------------------------------------------------------------------------- /sx.1: -------------------------------------------------------------------------------- 1 | .TH SX 1 "6 July 2021" 3.0 2 | .SH NAME 3 | sx \- start an xorg server 4 | .SH SYNOPSIS 5 | .B sx 6 | .RI [ "command " [ "arguments " ...]] 7 | .SH DESCRIPTION 8 | .B sx 9 | can be used to replace both 10 | .BR xinit (1) 11 | and 12 | .BR startx (1) 13 | for starting an 14 | .BR Xorg (1) 15 | server with an initial client. By default 16 | .B sx 17 | will attempt to execute 18 | .I \%XDG_CONFIG_HOME/sx/sxrc 19 | unless a 20 | .I command 21 | is provided. The 22 | .I command 23 | may have additional 24 | .IR arguments . 25 | .SH EXIT STATUS 26 | .B sx 27 | will attempt to inherit the exit status from the 28 | .BR Xorg (1) 29 | server. If 30 | .B sx 31 | was signalled then the exit status will reflect this, otherwise it will be 32 | zero. 33 | .SH ENVIRONMENT 34 | .TP 35 | .B XAUTHORITY 36 | This environment references a file which stores authorisation entries 37 | used to secure 38 | .BR Xorg (1) . 39 | If this environment is not set then 40 | .B sx 41 | will create and use 42 | .B \%XDG_DATA_HOME/sx/xauthority 43 | instead while also exporting this value to 44 | .BR XAUTHORITY . 45 | .TP 46 | .B XDG_CONFIG_HOME 47 | The directory used when searching for 48 | .IR sxrc . 49 | .B \%HOME/.config 50 | will be used if not set. 51 | .TP 52 | .B XDG_DATA_HOME 53 | The directory used for storing the 54 | .I xauthority 55 | file. 56 | .B \%HOME/.local/share 57 | will be used if not set. 58 | .SH FILES 59 | .TP 60 | .B XDG_CONFIG_HOME/sx/sxrc 61 | The default command started by 62 | .BR sx . 63 | This file must be executable. 64 | .TP 65 | .B XDG_DATA_HOME/sx/xauthority 66 | The default authority used by 67 | .B sx 68 | if an alternative file is not provided with 69 | .BR XAUTHORITY . 70 | .SH NOTES 71 | With the addition of 72 | .BR Xorg.wrap (1) 73 | it may be necessary to set 74 | .I allowed_users 75 | to 76 | .I anybody 77 | in 78 | .B \%/etc/X11/Xwrapper.config 79 | if 80 | .B sx 81 | is used in a pipeline or its standard output and standard error is redirected 82 | to a file as it will not be considered a console user. 83 | .SH EXAMPLES 84 | Use an existing 85 | .I .Xinitrc 86 | by specifying an appropriate interpreter such as 87 | .BR sh (1) 88 | or making it executable with a correct interpreter line: 89 | .IP 90 | .EX 91 | .B sx sh ~/.Xinitrc 92 | .EE 93 | .PP 94 | Pass arguments to the standard 95 | .I sxrc 96 | by presenting it to 97 | .B sx 98 | as a 99 | .IR command : 100 | .IP 101 | .EX 102 | .B sx ~/.config/sx/sxrc arg1 arg2 103 | .EE 104 | .SH SOURCE 105 | .UR https://github.com/Earnestly/sx 106 | .UE 107 | .SH SEE ALSO 108 | .BR startx (1), 109 | .BR xinit (1), 110 | .BR Xorg (1), 111 | .BR X (7), 112 | .BR Xsecurity (7), 113 | .BR Xwrapper.config (5) 114 | --------------------------------------------------------------------------------