earnestly / sx Goto Github PK
View Code? Open in Web Editor NEWStart an xorg server
License: MIT License
Start an xorg server
License: MIT License
sx <https://github.com/Earnestly/sx> INTRODUCTION sx is a simple alternative to both xinit(1) and startx(1) for starting an Xorg server. It started life as a proof of concept while attempting to learn how both xinit and startx worked while taking up the offer presented in startx: > Site administrators are STRONGLY urged to write nicer versions. It is not a direct replacement however as it provides a different, more limited, interface. Some of these major differences are listed here: * The server's command-line is hard coded and not exposed to the user. * The server doesn't listen on anything except unix domain sockets. * The server starts on the same tty the user logged in on. * The first DISPLAY is 1 instead of 0 contrary to what X(7) suggests as it is coupled to the tty number. * xauth entries are overwritten if the displayname is identical. * Corresponding xauth entries are unconditionally removed when the server exits. * The server uses the -noreset flag. * While XAUTHORITY is still honoured, $XDG_DATA_HOME/sx/xauthority is used by default instead of $HOME/.Xauthority * Very little proxy error checking is used preferring instead to let each tool speak for itself. * None of the typical /etc/X11/xinit infrastructure is directly used. * Neither XINITRC is honoured nor .xinitrc used. * The XDG_CONFIG_HOME/sx/sxrc file is used instead of .xinitrc and is required to be executable. For a rationale on why this exists the author invites the reader to look over the source code for both xinit and startx. REQUIRES * Xorg * xauth * /dev/urandom INSTALL make PREFIX=/usr install
The xauth program is used to edit and display the authorization information used in connecting to the X server.
if removing this from the sx program still makes X function, why is it required as a dependency? is the XAUTHORITY and authentication for security purposes for Xorg applications?
Hi. Currently the server command-line is hardcoded. Would it be possible to pass custom options to the server? I am specially interested in -ardelay
, -arinterval
and -xkbmap
. Thank you.
I get this is terminal emacs when trying to copy something. I think the error comes from xclip. I'm starting sx from .profile
:
#!/bin/sh
# .profile
if test -z "${XDG_RUNTIME_DIR}"; then
XDG_RUNTIME_DIR=/tmp/"$(id -u)"-runtime-dir
export XDG_RUNTIME_DIR
if ! test -d "${XDG_RUNTIME_DIR}"; then
mkdir "${XDG_RUNTIME_DIR}"
chmod 0700 "${XDG_RUNTIME_DIR}"
fi
fi
if [ -f ~/.bashrc ]; then . .bashrc; fi
if [ ! "$DISPLAY" ]; then
sx sh ~/.xinitrc 2> .xsession-errors
#startx 2> .xsession-errors
fi
#!/bin/sh
if [ -d /etc/X11/xinit ] ; then
for f in /etc/X11/xinit/* ; do
[ -x "$f" ] && . "$f"
done
unset f
fi
awesome
xrdb -merge ~/.Xresources
So I'm messing around in a minimal Debian VM that I started as just a server, but I wanted to play with installing a minimal graphical interface to it....this sounds like the perfect candidate to launch xorg......
The issue is, I don't know what make PREFIX=/usr DESTDIR=staged install
means. I'm assuming I'll need build-essentials
, but beyond that:
cd
into that directory and enter that exactly?sx
and X will go?sxrc
file is supposed to look likeThanks in advance for whatever patience you can spare for a noob.
P.S. If I'm able to grasp this, I'd be glad to attempt to write some documentation for your wiki tab for other less experienced folks
Applet such as nm-applet aren't visible in i3status bar and even refuse showing when run form the command line.
In other window managers I tested (qtile, awesomee) the same issue appear.
Any clarification about why i3status is having problems with sx?
As the title says, attempting to suppress both stdout and stderr causes X to never launch. If I only suppress one of the two, sx
is able to launch Xorg fine.
Due to my design choice of coupling the tty number to Xorg's vt
argument and DISPLAY
value it may mean neither OpenBSD or FreeBSD will ever work.
The reason for this seems to be due to how FreeBSD and OpenBSD won't let the Xorg server take over an active tty. Instead it generates a cryptic error message telling us that (EE) Unrecognized option: vt0
.
Additionally OpenBSD will not let users run ps -o tty= $$
so this approach isn't viable to start with either.
There are a few potential solutions to this, some which seem to be mutually exclusive between platforms.
vt
argument and let the Xorg server select one that is available. Unfortunately this doesn't work on Linux (when using rootless Xorg servers thanks to systemd-logind).vt
argument based on the tty number we get. However this is not a reliable heuristic as the second tty may also be used under FreeBSD which lands us back at square one.None of these are going to be viable. Instead FreeBSD and OpenBSD would probably take advantage of /etc/ttys
which appears to offer a better approach to managing Xorg servers anyway. For OpenBSD specifically they also have xenodm(1) as well.
This line in the README
file is incorrect:
"While XAUTHORITY is still honoured, $XDG_DATA_HOME/sx/xauthfile is ..."
The correct file name is xauthority
. The man page use the correct name.
In my ~/.config/Xresources file I have
Xft.dpi: 192
and in my sx file I have
xrdb -merge ~/.config/Xresources
However the dpi is not set on start. running the command manually after start will correctly set the dpi
Some packages install startup scripts to /etc/X11/xinit/xinitrc.d/
and it seems that currently they are not being run by sx
.
For example, on Arch systemd services get the DISPLAY environment variable set in one of these hooks:
https://wiki.archlinux.org/index.php/Systemd/User#DISPLAY_and_XAUTHORITY
Run zathura from the terminal. Errors out with this:
No protocol specified
Unable to init server: Could not connect: Connection refused
(zathura:11): Gtk-WARNING **: 11:00:51.082: cannot open display: :1
Since the update to version 1.1 I get the follow error:
/usr/libexec/Xorg.wrap: Only console users are allowed to run the X server
Only the i3 processes are killed but not Xorg and sx (and others)
Hi. It's me again. I hope I'm not bugging you.
Just in case I missed a chance to learn more, I read sx
again and realize that I don't quite understand why we need to wait
for the client process.
I tested it a bit myself. It seems that the wait
is for some reason necessary if exec
is used. Then I find the fact that exec
(in both the client and the server case) is used is actually strange to me as well, because they are both forked.
What would be the potential pitfall(s) when it is done with:
...
trap 'DISPLAY=:$tty "${@:-$cfgdir/sxrc}" &' USR1
(trap '' USR1 && Xorg :"$tty" -keeptty vt"$tty" -noreset -auth "$XAUTHORITY") & pid=$!
...
?
Here is my ~/.config/sx/sxrc:
#!/bin/sh
[ -f ~/.xprofile ] && . ~/.xprofile
xinput set-prop "Elan Touchpad" "libinput Tapping Enabled" 1
xinput set-prop "Elan Touchpad" "libinput Natural Scrolling Enabled" 1
setxkbmap -layout custom-us-keychron -option caps:escape
xset r rate 200 30
exec i3
I also tried with the export statements directly in the sxrc but they are still not set in the i3 process.
Could you help me see what I'm doing wrong?
Very nice simple program, thanks for making it :)
The posix ps command does not take PID as a argument. This fails in busybox for example. One alternative is try command which POSIX. To get the try, we need to basename it
Hi. I just stumbled by mere accident over sx. I had a question about xinitrc and somebody suggested sx. It works really great and seems to be faster. Anyway, I was wondering how come that sx is so much simpler than startx? You dont have to explain if you dont have time but maybe you can give me at least some hints :)
Under shells such as dash
or mrsh
the cleanup
function will never be called if sx
is interrupted by a signal. The bash
(as sh
) shell implements a strategy which does ensure it is called but it is the exception.
The only somewhat reliable interpretation of EXIT
is that it will be run when the shell script itself exits normally, as if the function was called directly at the bottom of the script. This effectively makes the EXIT
trap extraneous.
Due to this more thought is needed to handle signals that could interrupt sx
such as INT
and TERM
especially if the cleanup
function wants to call exit
.
A potential implementation might be something like this:
cleanup() {
r=$?
# See notes below this example code.
if [ "$r" -gt 128 ]; then
signal=$((r - 128))
fi
if kill -0 "$pid" > /dev/null; then
# Pass the signal to Xorg(?). If the return was 0 above then this if
# condition should not be met and the branch never taken. If due to
# any race conditions it is, then the call to kill will resolve to -0
# and do nothing.
kill -"$signal" "$pid"
wait "$pid"
fi
if ! stty "$stty"; then
stty sane
fi
xauth remove :"$tty"
}
# ...
for signal in HUP INT TERM; do
# Resend the signal as they are intended to terminate the script as well.
trap 'cleanup; trap - "$signal"; kill -s "$signal" "$$"' "$signal"
done
# ...
# Run the cleanup routine unconditionally at the end of the script, replacing
# the role of an EXIT trap.
cleanup
The use of 128 is not portable, and the POSIX standard renders it pointless:
The exit status of a command that terminated because it received a signal shall be reported as greater than 128.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02
Historically, shells have returned an exit status of 128+ n, where n represents the signal number. Since signal numbers are not standardized, there is no portable way to determine which signal caused the termination. Also, it is possible for a command to exit with a status in the same range of numbers that the shell would use to report that the command was terminated by a signal. Implementations are encouraged to choose exit values greater than 256 to indicate programs that terminate by a signal so that the exit status cannot be confused with an exit status generated by a normal termination.
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html#tag_23_02_08
In the end I may simply do the clean up at the end of the script and simply do nothing with signals which will potentially leave Xservers running when they ought not be; either that or port this to bash instead.
I have this systemd service file that I use as a screenlock:
[Unit]
Description=Lockscreen app launch before suspend
Before=sleep.target
[Service]
User=%i
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/i3lock
[Install]
WantedBy=suspend.target
This works well when used with startx. Even when I change the DISPLAY=:0
to DISPLAY=:1
, it does nothing but I get no error message whatsoever from i3lock.
This may be a bug with the i3lock itself, but since it appeared only using this programme, I thought it might be more appropriate to put it here.
sx doesn't kill while loops inside sxrc or external scripts.
example:
# Statusbar loop
while true; do
xsetroot -name "$( date +"%F %R" )"
sleep 1m # Update time every minute
done &
when I exit my WM (dwm) xsetroot says it can't open display 1 every minute. this issue doesn't happen on xinit.
--
distro: void linux
ver: 2.1.6
If I leave my window manager the Xorg still runs and does not shutdown. I have to switch to tty2 and kill it. How can I solve this?
Starting i3 with config for gnome-keyring according to ArchWiki
dbus-update-activation-environment --systemd DISPLAY
eval $(/usr/bin/gnome-keyring-daemon --start --components=pkcs11,secrets,ssh)
export SSH_AUTH_SOCK
startx works fine, but not sx.
Using sx still shows:
sign_and_send_pubkey: signing failed: agent refused operation
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.