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.
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
#!/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.
#!/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.
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.