Xsession
Xsession(n)                                           Xsession(n)



NAME
       Xsession - initialize X session

SYNOPSIS
       Xsession [ session-type ]

DESCRIPTION
       /etc/X11/Xsession  is  a Bourne shell (sh(h)) script which
       is run every time an X Window System session is  begun  by
       startx(x) or a display manager such as xdm(m).  (Some dis-
       play  managers  only  invoke  Xsession  when  specifically
       directed to so by the user; see the documentation for your
       display manager to find out more.)  Administrators unfami-
       lar  with  the  Bourne  shell  will  likely find the Xses-
       sion.options(s) configuration file  easier  to  deal  with
       than Xsession itself.

       Xsession  is  not  intended  to be invoked directly by the
       user; to be effective it needs to run in a  special  envi-
       ronment   associated   with   X   server   initialization.
       startx(x), xdm(m), xinit(t), and  other  similar  programs
       handle this.

       By  default  on  a Debian system, Xsession is used by both
       common methods of starting the X Window  System,  xdm  and
       startx.   To  change  this  for xdm, edit the "DisplayMan-
       ager*session"  resource  in  the   /etc/X11/xdm/xdm-config
       file;   for   startx,   replace   the   contents   of  the
       /etc/X11/xinit/xinitrc file.

       The Xsession script is quite flexible, and extensive  cus-
       tomization  of the X startup procedure is possible without
       modifying the script itself.  See "CUSTOMIZING THE STARTUP
       PROCEDURE" below.

   SESSION TYPES
       Xsession  may optionally be passed a single argument indi-
       cating the type of X session to be started.  It is  up  to
       the  display  manager  to  set  the argument.  By default,
       three different arguments are supported:

       failsafe
              invokes a session consisting solely of  /usr/bin/x-
              terminal-emulator  (no window manager is launched).
              If the x-terminal-emulator program cannot be found,
              the  session  exits.   The  "failsafe"  argument is
              ignored if there is  no  "allow-failsafe"  line  in
              Xsession.options.

       default
              produces  the  same  behavior as if no session type
              argument had been given at all.

       program
              starts program if it can be  found  in  the  $PATH.
              This  is  usually  a session manager or a very fea-
              tureful window manager.  If program is  not  found,
              the  Xsession  script  proceeds  with  its  default
              behavior.  This argument is ignored if there is  no
              "allow-user-xsession"   line  in  Xsession.options.
              (The reason being, if the  administrator  does  not
              want  users  writing  their own .Xsession files, it
              makes little sense to permit them  to  specify  the
              names of arbitrary programs to run.)

   DEFAULT STARTUP PROCEDURE
       Initially,   Xsession   performs  some  housekeeping.   It
       declares a set of built-in functions (see "BUILT-IN  SHELL
       FUNCTIONS" below) and variables, then attempts to create a
       log file for the X session.  Historically this  is  called
       an  "error"  file,  but it catches all sorts of diagnostic
       output from various X clients run in the  user's  session,
       not  just error messages.  If creation of an error file is
       impossible, the script (and thus the X session) aborts.

       Xsession next confirms that its  script  directory,  Xses-
       sion.d, exists.  If it does not, the script aborts.  After
       the script directory is confirmed to be present,  Xsession
       uses  an  internal implementation of run-parts(s) to iden-
       tify files in that directory that should be sourced  (exe-
       cuted)  in the shell's environment.  Only files named in a
       certain way are sourced; see the run-parts(s) manual  page
       for  a  description  of  valid characters in the filename.
       (This restriction enables the administrator to move exper-
       imental  or problematic files out of the way of the script
       but keep them in an obvious place, for instance by  renam-
       ing  them  with  ".old" or ".broken" appended to the file-
       name.)

       Five scripts are provided by default:

       1)  Argument  processing.   Arguments  are  processed   as
       described  in "SESSION TYPES" above.  The startup program,
       if one is identified at this point, is merely  stored  for
       later reference, and not immediately executed.

       2)  Merging  of  X resources.  run-parts(s) is again used,
       this time to identify  files  in  the  /etc/X11/Xresources
       directory  that  should  be  processed with "xrdb -merge".
       Next, if the line  "allow-user-resources"  is  present  in
       Xsession.options,  the  user's  $HOME/.Xresources  file is
       merged in the same way.

       3) Determine startup program.  The X client to  launch  as
       the  controlling  process  (the  one  that,  upon exiting,
       causes the X server to exit as well) is  determined  next.
       If  the  line  "allow-user-xsession"  is  present in Xses-
       sion.options, a user-specified session program  or  script
       is  used.  If a program or failsafe argument was given and
       is allowed (see above), it is  used  instead.   Otherwise,
       two  historically popular names for user X session scripts
       are  searched  for:  $HOME/.xsession  and  $HOME/.Xsession
       (note  the  difference  in  case).  The first one found is
       used.  If the script is not executable, it is marked to be
       executed  with  the  Bourne  shell interpreter, sh(h).  If
       "allow-user-xsession" is not specified, or no user X  ses-
       sion program can be located, and no failsafe session is to
       be  run,  the  following  programs   are   searched   for:
       /usr/bin/x-session-manager, /usr/bin/x-window-manager, and
       /usr/bin/x-terminal-emulator.   The  first  one  found  is
       used.  If none are found, Xsession aborts with an error.

       4)  Start  ssh-agent,  if  needed.   If the line "use-ssh-
       agent" is present in Xsession.options, and  no  ssh  agent
       process  appears  to  be  running already, ssh-agent(t) is
       marked to be used to execute the  startup  program  deter-
       mined  previously.   Note:  this functionality may move to
       the ssh package in the future.

       5) Start the X session.  Finally, the startup  program  is
       executed,  inside  a Bourne shell if necessary, and inside
       an ssh-agent if necessary.  The shell's  exec  command  is
       used to spare a slot in the process table.

   CUSTOMIZING THE STARTUP PROCEDURE
       Of  course,  any  of  the existing files can be edited in-
       place.

       Because  the  order  in  which  the  various  scripts   in
       /etc/X11/Xsession.d are executed is important, files to be
       added to this directory should have  a  well-formed  name.
       The following format is recommended:

       * a two-digit number denoting sequence
       * the name of the package providing the script
       * an underscore
       * a description of the script's basic function, using only
       characters allowed by run-parts(s).

       Here is an example of how one might write a script,  named
       40custom_load-xmodmap, to invoke xmodmap(p):

       SYSMODMAP=/etc/X11/Xmodmap
       USRMODMAP=$HOME/.Xmodmap

       if [ -x /usr/bin/X11/xmodmap ]; then
         if [ -f $SYSMODMAP ]; then
           xmodmap $SYSMODMAP
         fi
       fi

       if [ -x /usr/bin/X11/xmodmap ]; then
         if [ -f $USRMODMAP ]; then
           xmodmap $USRMODMAP
         fi
       fi

       Those writing scripts for Xsession to execute should avail
       themselves of  its  built-in  shell  functions,  described
       below.

   BUILT-IN SHELL FUNCTIONS
       message  is  used for communicating with the user.  It may
       be given an arbitrarily long message string.  It  is  for-
       matted  to  the  user's  terminal width (breaking lines at
       whitespace) and sent to standard error.

       message_nonl is used for communicating with the user  when
       a  trailing  newline  is  undesirable.  It may be given an
       arbitrarily long message string.  It is formatted  to  the
       user's  terminal  width (breaking lines at whitespace) and
       sent to standard error.

       errormsg is used for indicating  an  error  condition  and
       aborting  the  script.   It  can be used as message above.
       After displaying the message to standard  error,  it  will
       exit Xsession with status 1.

ENVIRONMENT
       The  following  environment variables affect the execution
       of Xsession:

       HOME   The  user's  home  directory;  various  files   are
              searched for here.

       TMPDIR Default directory for temporary files; if the stan-
              dard X session error file cannot  be  opened,  this
              variable is used to locate a place for one.

       COLUMNS
              Width of terminal device, in character cells.  Used
              for formatting diagnostic messages.

INPUT FILES
       /etc/X11/Xsession.d/
              is a directory containing Bourne shell  scripts  to
              be  executed  by Xsession.  Files in this directory
              are matched using run-parts(s) and are sourced, not
              executed in a subshell.

       /etc/X11/Xresources/
              is  a  directory  containing files corresponding to
              Debian package names, each of which  contains  sys-
              tem-wide X resource settings for X clients from the
              corresponding package.   The  settings  are  loaded
              with  xrdb  -merge.   Files  in  this directory are
              matched using run-parts(s).

       /etc/X11/Xsession.options
              contains    configuration    options    for     the
              /etc/X11/Xsession  script.  See Xsession.options(s)
              for more information.

       $HOME/.Xresources
              contains  X  resources  specific  to  the  invoking
              user's  environment.   The settings are loaded with
              xrdb -merge.  Note that $HOME/.Xdefaults is a relic
              from  X  Version  10  (and X11R1) days, before app-
              defaults files were implemented.  It has been  dep-
              recated  for  over  ten  years  at the time of this
              writing.  .Xresources should be used instead.

       $HOME/.Xsession
              is a sequence of commands invoking X clients (or  a
              session  manager  such  as xsm(m)).  See the manual
              page for xinit  and/or  /usr/share/doc/xfree86-com-
              mon/examples/xsession for tips on writing an .Xses-
              sion file.

OUTPUT FILES
       $HOME/.xsession-errors
              Where standard output and standard error for  Xses-
              sion script and all X client processes are directed
              by default.

       $TMPDIR
              Where  the  X  session  error  file  is  placed  if
              $HOME/.xsession-errors cannot be opened.  The file-
              name is provided by tempfile(e).

SEE ALSO
       Xsession.options(s),  X(X),  run-parts(s),   ssh-agent(t),
       startx(x), tempfile(e), xdm(m), xmodmap(p), xrdb(b), sh(h)

AUTHOR
       /etc/X11/Xsession   and   its    associated    files    in
       /etc/X11/Xsession.d  were  written  by Stephen Early, Mark
       Eichin, and Branden Robinson.



Debian GNU/Linux            2001-11-08                Xsession(n)