Starting your X Server and X Session

Starting your X Server and starting your session are two distinct operations, but they are usually performed by the same utility. The two most common utilities that are used are xinit and xdm.

A session is usually defined by a single client that prevents the session from ending. When that client terminates, the session will also be terminated. Both utilities implement this is similar ways.

xinit

Xinit is used when the user desires a one time X session. This utility will start the X server specified by the user and then start the user's session.

By default, xinit will use the following for the users session:

        xterm -geometry +1+1 -n login -display :0

The default X server is executed as:

        X :0

This assumes that the X server (usually XF86_*) is also linked to X, and that it is in the users PATH.

Both of these can be overridden on the command line using this syntax:

        xinit <session/client command> [- - <server command>]

A more convenient way to change the default behavior is through the use of two rc files, .xserverrc and .xinitrc

.xserverrc

This file is used to specify the name of the Xserver, and also the parameters to pass to it. This is usually a shell script that can be very simple

        #!/bin/sh
        exec /usr/X11R6/bin/XF86_Mach64 :0 -depth 16

or very complex

        #!/bin/sh
        HOSTNAME=`/usr/ucb/hostname`
        case $HOSTNAME in
                loweezy)
                        exec /usr/bin/X11/XF86_Mach64 :0
                ;;
                kzin|recycle)
                        exec /usr/bin/X11/XF86_SVGA :0
               ;;
        esac

depending on the users needs. The X server should be exec'ed so that xinit will have a direct parent-child relationship with it. This is required so the X Server can be killed when the user's session has terminated.

.xinitrc

This file is where the user can configure the X environment. This script defines the users session. Below is a sample .xinitrc file.

        #!/bin/sh -x

        /usr/bin/X11/xrdb $HOME/.Xdefaults      # quickly returns
        /usr/bin/X11/xterm -geometry 80x45+0+0 &
        /usr/bin/X11/xsetroot -solid grey50     # quickly returns

        exec /usr/bin/X11/mwm

In this example, control of the session is turned over to the window manager by using exec. When the user exits the window manager the session will be terminated. The same thing can be done using xterm as the controlling client

        #!/bin/sh -x

        /usr/bin/X11/xrdb $HOME/.Xdefaults      # quickly returns
        /usr/bin/X11/xsetroot -solid grey50     # quickly returns

        /usr/bin/X11/mwm &

        exec /usr/bin/X11/xterm -geometry 80x45+0+0

One other thing to note is that any command that does not return quickly should be placed in the background. This allows the rest of the user's session to execute.

xdm

This utility is much more complex than xinit. Xdm should be used when it is desirable to have sessions restarted automatically. Xdm has two mechanisms for starting a session on an X server.

On local X servers, it works similar to xinit in that it starts the X server and then lets the user execute a session. Once the session terminates, the X server is restarted and the cycle can repeat. One difference from xinit, is xdm is run by the system startup scripts and acts like a getty, requiring the user to login to start the session.

On remote X server (X terminals), xdm does not have the ability to automaticcaly start the X server. Instead, it uses the XDM Control Protocol (XDMCP) to communicate with the X server. This prototcol is used to keep xdm and the X server in sync as a session is started and terminates.

All of the configuration files for xdm are located in /usr/X11R6/lib/X11/xdm.

A default session will be started when a user logs in, unless the file .xsession is present in the users HOME directory.

.xsession

This file behaves exactly the same as the .xinitrc file. In fact, they can be linked together so the user only has to maintain a single file.

.xsession-error

Errors that occur during a session started by xdm will be sent to the file $HOME/.xsession-error.