# Xsession(5) - man - phpman

[Xsession(5)](https://www.chedong.com/phpMan.php/man/Xsession/5/markdown)                              File Formats Manual                             [Xsession(5)](https://www.chedong.com/phpMan.php/man/Xsession/5/markdown)



## NAME
       Xsession - initialize X session

## SYNOPSIS
       Xsession [ _session-type_ ]

## DESCRIPTION
       _/etc/X11/Xsession_  is a Bourne shell ([**sh**(1)](https://www.chedong.com/phpMan.php/man/sh/1/markdown)) script which is run when an X Window System ses‐
       sion is begun by [**startx**(1)](https://www.chedong.com/phpMan.php/man/startx/1/markdown) or a display manager such as [**xdm**(1)](https://www.chedong.com/phpMan.php/man/xdm/1/markdown).  (Some display managers  only
       invoke  _Xsession_ when specifically directed to so by the user; see the documentation for your
       display manager to find out more.)  Administrators unfamiliar  with  the  Bourne  shell  will
       likely  find the [**Xsession.options**(5)](https://www.chedong.com/phpMan.php/man/Xsession.options/5/markdown) configuration file easier to deal with than _Xsession_ it‐
       self.

       _Xsession_ is not intended to be invoked directly by the user; to be effective it needs to  run
       in a special environment associated with X server initialization.  **startx**, **xdm**, [**xinit**(1)](https://www.chedong.com/phpMan.php/man/xinit/1/markdown), and
       other similar programs handle this.

       By default on a Debian system, _Xsession_ is used by both common methods of starting the X Win‐
       dow  System, **xdm** (or another X display manager) and **startx**.  To change this for **xdm,** edit the
       ‘DisplayManager*session’ resource in the _/etc/X11/xdm/xdm-config_ file  —  for  other  display
       managers,  consult  their  documentation.  To stop **startx** from using _Xsession_ by default, re‐
       place the contents of the _/etc/X11/xinit/xinitrc_ file.

       The _Xsession_ script is quite flexible, and extensive customization of the X startup procedure
       is possible without modifying the script itself.  See “CUSTOMIZING THE STARTUP PROCEDURE” be‐
       low.

   **SESSION** **TYPES**
       _Xsession_ may optionally be passed a single argument indicating the type of X  session  to  be
       started.   It  is up to the display manager to set the argument. To pass _Xsession_ an argument
       from **startx** or **xinit**, _/etc/X11/Xsession_ (or _/etc/X11/xinit/xinitrc_) must be called explicitly
       with  a path, as in **startx** **/etc/X11/Xsession** **failsafe**.  By default, three different arguments
       are supported:

### failsafe
              invokes a session consisting solely of an [**x-terminal-emulator**(1)](https://www.chedong.com/phpMan.php/man/x-terminal-emulator/1/markdown) (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  _Xses__‐
              _sion.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 featureful window manager.  If _program_ is not found, the _Xsession_  script  pro‐
              ceeds  with  its  default  behavior.   This  argument  is  ignored if there is no ‘al‐
              low-user-xsession’ line in _Xsession.options_.  (If  the  administrator  does  not  want
              users writing their own _.xsession_ files, it makes little sense to permit them to spec‐
              ify the names of arbitrary programs to run.)  Note that the restriction may be easy to
              bypass, e.g. by using a _.gnomerc_ file instead.

   **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,  or  append to an existing one.  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 it is impossible to write to an error file, the script (and thus the
       X session) aborts.  For convenience, once the error file is successfully opened, _Xsession_ re‐
       ports the fact that the session has started, the invoking username, and the date to the error
       file.  This makes it easier to discern which X session produced a particular line  of  output
       in the file.

       _Xsession_  next  confirms  that its script directory, _Xsession.d_, exists.  If it does not, the
       script aborts.  After the  script  directory  is  confirmed  to  be  present,  _Xsession_  uses
       [**run-parts**(1)](https://www.chedong.com/phpMan.php/man/run-parts/1/markdown)  to  identify  files  in that directory that should be sourced (executed) in the
       shell's environment.  Only files named in a certain way are sourced; see the **run-parts** manual
       page  for  a  description of valid characters in the filename.  (This restriction enables the
       administrator to move experimental or problematic files out of the way of the script but keep
       them  in an obvious place, for instance by renaming them with ‘.old’ or ‘.broken’ appended to
       the filename.)

   **SUPPLIED** **SCRIPTS**
       Five shell script portions are supplied by default to  handle  the  details  of  the  session
       startup procedure.

       _/etc/X11/Xsession.d/20x11-common_process-args_
              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  im‐
              mediately executed.

       _/etc/X11/Xsession.d/30x11-common_xresources_
              X  resources  are merged.  **run-parts** 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/.Xre__‐
              _sources_ file is merged in the same way.

       _/etc/X11/Xsession.d/35x11-common_xhost-local_
              Give access to the X server to the same user on the local host.  If the _xhost_  command
              is  available, it will use it to allow any process of the same user running on the lo‐
              cal host to access the X server.

       _/etc/X11/Xsession.d/40x11-common_xsessionrc_
              Source global environment variables.  This script will source anything in _$HOME/.xses__‐
              _sionrc_  if  the  file is present. This allows the user to set global environment vari‐
              ables for their X session, such as locale information.

       _/etc/X11/Xsession.d/50x11-common_determine-startup_
              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 a
              program or failsafe argument was given and is allowed (see above), it is used  as  the
              controlling process.  Otherwise, if the line ‘allow-user-xsession’ is present in _Xses__‐
              _sion.options_, a user-specified session program or script is used.  In the latter case,
              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**.  Finally, if none of the above succeeds,  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,  _Xses__‐
              _sion_ aborts with an error.

       _/etc/X11/Xsession.d/90x11-common_ssh-agent_
              Start [**ssh-agent**(1)](https://www.chedong.com/phpMan.php/man/ssh-agent/1/markdown), if needed.  If the line ‘use-ssh-agent’ is present in _Xsession.op__‐
              _tions_, and no SSH agent process appears to be running already, **ssh-agent** is marked  to
              be  used to execute the startup program determined previously.  **Note:** this functional‐
              ity may move to the ssh package in the future.

       _/etc/X11/Xsession.d/99x11-common_start_
              Start the X session.  The startup program is executed, inside a Bourne shell if it  is
              not  executable,  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  impor‐
       tant, files to be added to this directory should have a well-formed name.  The following for‐
       mat is recommended:

       * a two-digit number denoting sequence;

       * the name of the package providing the script (or ‘custom’ for locally-created scripts);

       * an underscore;

       * a description of the script's basic function, using only characters allowed by **run-parts**.

       Here is an example of how one might write a script, named  _40custom_load-xmodmap_,  to  invoke
       [**xmodmap**(1)](https://www.chedong.com/phpMan.php/man/xmodmap/1/markdown):

       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 is a wrapper for the [**echo**(1)](https://www.chedong.com/phpMan.php/man/echo/1/markdown) command and
       relies upon **echo** for its argument processing.  This function may be given an arbitrarily long
       message string, which is formatted to the user's terminal width  (breaking  lines  at  white‐
       space)  and sent to standard error.  If the _DISPLAY_ environment variable is set and the **xmes**‐‐
       [**sage**(1)](https://www.chedong.com/phpMan.php/man/sage/1/markdown) program is available, **xmessage** is also used to display the message.

       **message**___**nonl** is used for communicating with the user when a trailing newline is  undesirable;
       it omits a trailing newline from the message text.  It otherwise works as **message**.

       **errormsg** is used for indicating an error condition and aborting the script.  It works as **mes**‐‐
       **sage**, above, except that after displaying the message, it will exit _Xsession_ with status 1.

## ENVIRONMENT
       The following environment variables affect the execution of _Xsession_:

       **HOME**   specifies the user's home directory; various files are searched for here.

       **TMPDIR** names a default directory for temporary files; if the standard X  session  error  file
              cannot be opened, this variable is used to locate a place for one.

       **COLUMNS**
              indicates  the  width  of  terminal device in character cells.  This value is 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** and are **source**d, not executed in a sub‐
              shell.

       _/etc/X11/Xresources/_
              is a directory containing files corresponding to Debian package names, each  of  which
              contains system-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**.

       _/etc/X11/Xsession.options_
              contains  configuration  options  for  the _/etc/X11/Xsession_ script.  See **Xsession.op**‐‐
              [**tions**(5)](https://www.chedong.com/phpMan.php/man/tions/5/markdown) 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  deprecated  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**(1)](https://www.chedong.com/phpMan.php/man/xsm/1/markdown)).
              See the manual page for **xinit** for tips on writing an _.xsession_ file.

## OUTPUT FILES
       _$HOME/.xsession-errors_
              is where standard output and standard error for _Xsession_ script and all X client  pro‐
              cesses are directed by default.

       _$TMPDIR/filename_
              is  where  the  X  session  error  file  is placed if _$HOME/.xsession-errors_ cannot be
              opened.  For security reasons, the exact  filename  is  randomly  generated  by  **temp**‐‐
              [**file**(1)](https://www.chedong.com/phpMan.php/man/file/1/markdown).

## AUTHORS
       Stephen  Early,  Mark  Eichin,  and  Branden  Robinson  developed Debian's X session handling
       scripts.  Branden Robinson wrote this manual page.

## SEE ALSO
       [**Xsession.options**(5)](https://www.chedong.com/phpMan.php/man/Xsession.options/5/markdown), [**X**(7)](https://www.chedong.com/phpMan.php/man/X/7/markdown), [**run-parts**(1)](https://www.chedong.com/phpMan.php/man/run-parts/1/markdown), [**ssh-agent**(1)](https://www.chedong.com/phpMan.php/man/ssh-agent/1/markdown), [**startx**(1)](https://www.chedong.com/phpMan.php/man/startx/1/markdown), [**tempfile**(1)](https://www.chedong.com/phpMan.php/man/tempfile/1/markdown), [**xdm**(1)](https://www.chedong.com/phpMan.php/man/xdm/1/markdown),  **xmes**‐‐
       [**sage**(1)](https://www.chedong.com/phpMan.php/man/sage/1/markdown), [**xmodmap**(1)](https://www.chedong.com/phpMan.php/man/xmodmap/1/markdown), [**xrdb**(1)](https://www.chedong.com/phpMan.php/man/xrdb/1/markdown), [**sh**(1)](https://www.chedong.com/phpMan.php/man/sh/1/markdown)



Debian Project                               2004-11-04                                  [Xsession(5)](https://www.chedong.com/phpMan.php/man/Xsession/5/markdown)
