How Many Ways To Start An Xserver - Desktop Customization & Workflow

Users browsing this thread: 1 Guest(s)
venam
Administrators
A recent thread on nixers got me thinking about the Xserver. We often interract with it either through startx or a display manager. How many ways can we actually send parameters to the X server, actually how many ways do we have to start an X session.

The first one is through the display manager, this is specific to each one and I'll take the case of lightdm.
lightdm.conf allows to pass parameters to the Xserver via the xserver-command = directive.

For example:
Code:
xserver-command= X -maxclients 2048


An obvious way to pass parameters to the Xserver is through its configuration files. For example, Xorg has a bunch in /etc/X11.

From man 5 xorg.conf:
Code:
SERVERFLAGS SECTION
...
       Option "MaxClients"  "integer"
              Set the maximum number of clients allowed to connect  to  the  X  server.
              Acceptable values are 64, 128, 256 or 512.
# so...
Section "ServerFlags"
       Option "MaxClients"  2048
EndSection

Now what if you are using startx(1).

Code:
NAME
       startx - initialize an X session
SYNOPSIS
       startx [ [ client ] options ... ] [ -- [ server ] [ display ] options ... ]

Anything after the -- will be considered arguments to the Xserver, if not starting with / or ./

So you can do the following:
Code:
startx -- -maxclients 2048

startx executes by default the server found in $HOME/.xserverrc or the one in the xinit directory, usually these days /etc/X11/xinit/xserverrc.

Similarly, if you are using xinit(1).

Code:
NAME
       xinit - X Window System initializer
SYNOPSIS
       xinit [ [ client ] options ... ] [ -- [ server ] [ display ] options ... ]

Anything after the -- will be considered arguments to the Xserver, executing by default xserverrc, just like startx.

So why use startx at all, you might ask.

startx is a wrapper over xinit to make it easier to start a session, though...

Code:
# Site administrators are STRONGLY urged to write nicer versions.

So what does it do?

It gets the next available display by looping in /tmp/.X{digit}-lock and /tmp/.X11-unix/X{digit}, and the tty number by executing tty(1).

It also sets features for xauth if enabled, like setting the .Xauthority environment variable, creating an authentication cookie (mcookie) and registering it using xauth(1). And cleans the allocated vt (deallocvt) and xauth session if needed. But the Xauth isn't mandatory.

In the end you get a line like this to open a session on display :1 and TTY 2:

Code:
xinit $HOME/.xinitrc -- /usr/bin/Xorg :1 vt2 -maxcients 2048 -keeptty [-auth /tmp/serverauth.SRVBaiALw0]


So you can definitely pass your arguments to the Xserver there.


But what if we go further and run Xorg ourselves, what do we need xinit for anyway. Let's go all the way.

From the Arch Wiki:
Quote:The Xorg(1) command is usually not run directly, instead the X server is started with either a display manager or xinit.

It was quite hard to find a way to run the Xorg(1) Xserver directly from the TTY without xinit and without messing up everything. But you can do it in the same way you would launch a Xephyr Xserver or Xvfb Xserver or others — Same o' same o'.

The following starts an Xorg Xserver on display :1 and TTY 2, and runs the session over it (xinitrc script).

Code:
/usr/bin/Xorg :1 vt2 -keeptty -maxclients 2048 &
DISPLAY=:1
export DISPLAY
sleep 5
./$HOME/.xinitrc
The sleep is sort of mandatory if you want to start Xorg in the background. (EDIT: or you can wait for the process like sx does or similar to what vain's version does capturing USR1 does the trick)

So many layers of indirection, startx calls xinit, xinit calls the Xserver.

That's it folks, I hope you enjoy this little escapade.
And comment with your own thoughts and ways to start X.


Messages In This Thread
How Many Ways To Start An Xserver - by venam - 05-09-2020, 11:50 AM
RE: How Many Ways To Start An Xserver - by venam - 07-09-2020, 02:48 AM
RE: How Many Ways To Start An Xserver - by z3bra - 07-09-2020, 07:31 AM
RE: How Many Ways To Start An Xserver - by venam - 07-09-2020, 03:07 PM
RE: How Many Ways To Start An Xserver - by venam - 08-09-2020, 02:42 AM
RE: How Many Ways To Start An Xserver - by venam - 09-09-2020, 02:12 AM
RE: How Many Ways To Start An Xserver - by movq - 13-09-2020, 02:31 PM