In this section we will explain the Init,
PostLogin, PreSession and
PostSession directories as they are very similar.
When the X server has been successfully started, GDM will try to run
the script called Init/<displayname>. I.e.
Init/:0 for the first local display.  If this file
is not found, GDM will attempt to to run
Init/<hostname>. I.e.
Init/somehost.
If this still is not found, GDM will try
Init/XDMCP for all XDMCP logins or
Init/Flexi for all on demand flexible
servers.  If none of the above were found, GDM will run
Init/Default. The script will be run as root and
GDM blocks until it terminates. Use the Init/*
script for applications that are supposed to run alongside with the GDM
login window. xconsole for instance.  Commands to set the background
etc. goes in this file too.
It is up to the sysadmin to decide whether clients started by the Init
script should be killed before starting the user session. This is
controlled with the KillInitClients option in
gdm.conf.
When the user has been successfully authenticated GDM tries the
scripts in the PostLogin directory in the same
manner as for the Init directory.  This is done
before any session setup is done, and so this would be the script where
you might setup the home directory if you need to (though you should
use the pam_mount module if you can for this).
You have the $USER and
$DISPLAY environment variables set for this
script, and again it is run as root.  The script should return 0 on
success as otherwise the user won't be logged in.  This is not true for
failsafe session however.
After the user session has been setup from the GDM side of things, GDM
will run the scripts in the PreSession directory,
again in the same manner as the Init directory.
Use this script for local session management or accounting stuff.  The
$USER environment variable contains the login of
the authenticated user and $DISPLAY is set to the
current display.  The script should return 0 on success.  Any other
value will cause GDM to terminate the current login process.  This is
not true for failsafe sessions however.  Also
$X_SERVERS environmental variable is set and this
points to a fake generated x servers file for use with the sessreg
accounting application.
After this the base Xsession script is run with
the selected session executable as the first argument.  This is run as
the user, and really this is the user session.  The available session
executables are taken from the Exec= line in the
.desktop files in the path specified by
SessionDesktopDir.  Usually this path is
<etc>/X11/sessions/:<etc>/dm/Sessions:/usr/share/xsessions/.
The first found file is used.  The user either picks from these
sessions or GDM will look inside the file ~/.dmrc
for the stored preference.
This script should really load the users profile and generally do all
the voodoo that is needed to launch a session.  Since many systems
reset the language selections done by GDM, GDM will also set the
$GDM_LANG variable to the selected language.  You
can use this to reset the language environmental variables after you
run the users profile.  If the user elected to use the system language,
then $GDM_LANG is not set.
When the user terminates his session, the
PostSession script will be run. Again operation
is similar to Init, PostLogin
and PreSession.  Again the script will be run with
root privileges, the slave daemon will block and the
$USER environment variable will contain the name
of the user who just logged out and $DISPLAY will
be set to the display the user used, however note that the X server for
this display may already be dead and so you shouldn't try to access it.
Also $X_SERVERS environmental variable is set and
this points to a fake generated x servers file for use with the sessreg
accounting application.
Note that the PostSession script will be run
even when the display fails to respond due to an I/O error or
similar. Thus, there is no guarantee that X applications will work
during script execution.
Except for the Xsession script all of these
scripts will also have the environment variable
$RUNNING_UNDER_GDM set to
yes, so that you could perhaps use similar
scripts for different display managers.  The
Xsession will always have the
$GDMSESSION set to the basename of the
session that the user chose to run without the
.desktop extension.  In addition
$DESKTOP_SESSION is also set to the same value
and in fact this will also be set by KDM in future versions.
Neither of the Init,
PostLogin, PreSession or
PostSession scripts are necessary and can be left
out.  The Xsession script is however required as
well as at least one session .desktop file.
