{
    "content": [
        {
            "type": "text",
            "text": "# Xsession(5) (man)\n\n**Summary:** Xsession - initialize X session\n\n**Synopsis:** Xsession [ session-type ]\n\n## See Also\n\n- Xsession.options(5)\n- X(7)\n- run-parts(1)\n- ssh-agent(1)\n- startx(1)\n- tempfile(1)\n- xdm(1)\n- sage(1)\n- xmodmap(1)\n- xrdb(1)\n- sh(1)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (2 lines)\n- **DESCRIPTION** (28 lines) — 2 subsections\n  - failsafe (5 lines)\n  - default (130 lines)\n- **ENVIRONMENT** (11 lines)\n- **INPUT FILES** (25 lines)\n- **OUTPUT FILES** (9 lines)\n- **AUTHORS** (3 lines)\n- **SEE ALSO** (6 lines)\n\n## Full Content\n\n### NAME\n\nXsession - initialize X session\n\n### SYNOPSIS\n\nXsession [ session-type ]\n\n### DESCRIPTION\n\n/etc/X11/Xsession  is a Bourne shell (sh(1)) script which is run when an X Window System ses‐\nsion is begun by startx(1) or a display manager such as xdm(1).  (Some display managers  only\ninvoke  Xsession when specifically directed to so by the user; see the documentation for your\ndisplay manager to find out more.)  Administrators unfamiliar  with  the  Bourne  shell  will\nlikely  find the Xsession.options(5) configuration file easier to deal with than Xsession it‐\nself.\n\nXsession is not intended to be invoked directly by the user; to be effective it needs to  run\nin a special environment associated with X server initialization.  startx, xdm, xinit(1), and\nother similar programs handle this.\n\nBy default on a Debian system, Xsession is used by both common methods of starting the X Win‐\ndow  System, xdm (or another X display manager) and startx.  To change this for xdm, edit the\n‘DisplayManager*session’ resource in the /etc/X11/xdm/xdm-config file  —  for  other  display\nmanagers,  consult  their  documentation.  To stop startx from using Xsession by default, re‐\nplace the contents of the /etc/X11/xinit/xinitrc file.\n\nThe Xsession script is quite flexible, and extensive customization of the X startup procedure\nis possible without modifying the script itself.  See “CUSTOMIZING THE STARTUP PROCEDURE” be‐\nlow.\n\nSESSION TYPES\nXsession may optionally be passed a single argument indicating the type of X  session  to  be\nstarted.   It  is up to the display manager to set the argument. To pass Xsession an argument\nfrom startx or xinit, /etc/X11/Xsession (or /etc/X11/xinit/xinitrc) must be called explicitly\nwith  a path, as in startx /etc/X11/Xsession failsafe.  By default, three different arguments\nare supported:\n\n#### failsafe\n\ninvokes a session consisting solely of an x-terminal-emulator(1) (no window manager is\nlaunched).   If  the  x-terminal-emulator  program cannot be found, the session exits.\nThe ‘failsafe’ argument is ignored if there  is  no  ‘allow-failsafe’  line  in  Xses‐\nsion.options.\n\n#### default\n\nproduces the same behavior as if no session type argument had been given at all.\n\nprogram\nstarts  program if it can be found in the $PATH.  This is usually a session manager or\na very featureful window manager.  If program is not found, the Xsession  script  pro‐\nceeds  with  its  default  behavior.   This  argument  is  ignored if there is no ‘al‐\nlow-user-xsession’ line in Xsession.options.  (If  the  administrator  does  not  want\nusers writing their own .xsession files, it makes little sense to permit them to spec‐\nify the names of arbitrary programs to run.)  Note that the restriction may be easy to\nbypass, e.g. by using a .gnomerc file instead.\n\nDEFAULT STARTUP PROCEDURE\nInitially, Xsession performs some housekeeping.  It declares a set of built-in functions (see\n“BUILT-IN SHELL FUNCTIONS” below) and variables, then attempts to create a log file for the X\nsession,  or  append to an existing one.  Historically this is called an ‘error’ file, but it\ncatches all sorts of diagnostic output from various X clients run in the user's session,  not\njust error messages.  If it is impossible to write to an error file, the script (and thus the\nX session) aborts.  For convenience, once the error file is successfully opened, Xsession re‐\nports the fact that the session has started, the invoking username, and the date to the error\nfile.  This makes it easier to discern which X session produced a particular line  of  output\nin the file.\n\nXsession  next  confirms  that its script directory, Xsession.d, exists.  If it does not, the\nscript aborts.  After the  script  directory  is  confirmed  to  be  present,  Xsession  uses\nrun-parts(1)  to  identify  files  in that directory that should be sourced (executed) in the\nshell's environment.  Only files named in a certain way are sourced; see the run-parts manual\npage  for  a  description of valid characters in the filename.  (This restriction enables the\nadministrator to move experimental or problematic files out of the way of the script but keep\nthem  in an obvious place, for instance by renaming them with ‘.old’ or ‘.broken’ appended to\nthe filename.)\n\nSUPPLIED SCRIPTS\nFive shell script portions are supplied by default to  handle  the  details  of  the  session\nstartup procedure.\n\n/etc/X11/Xsession.d/20x11-commonprocess-args\nArguments  are  processed as described in “SESSION TYPES” above.  The startup program,\nif one is identified at this point, is merely stored for later reference, and not  im‐\nmediately executed.\n\n/etc/X11/Xsession.d/30x11-commonxresources\nX  resources  are merged.  run-parts is again used, this time to identify files in the\n/etc/X11/Xresources directory that should be processed with ‘xrdb -merge’.   Next,  if\nthe line ‘allow-user-resources’ is present in Xsession.options, the user's $HOME/.Xre‐\nsources file is merged in the same way.\n\n/etc/X11/Xsession.d/35x11-commonxhost-local\nGive access to the X server to the same user on the local host.  If the xhost  command\nis  available, it will use it to allow any process of the same user running on the lo‐\ncal host to access the X server.\n\n/etc/X11/Xsession.d/40x11-commonxsessionrc\nSource global environment variables.  This script will source anything in $HOME/.xses‐\nsionrc  if  the  file is present. This allows the user to set global environment vari‐\nables for their X session, such as locale information.\n\n/etc/X11/Xsession.d/50x11-commondetermine-startup\nDetermine startup program.  The X client to launch as the controlling process (the one\nthat,  upon  exiting,  causes  the X server to exit as well) is determined next.  If a\nprogram or failsafe argument was given and is allowed (see above), it is used  as  the\ncontrolling process.  Otherwise, if the line ‘allow-user-xsession’ is present in Xses‐\nsion.options, a user-specified session program or script is used.  In the latter case,\ntwo  historically  popular  names  for  user  X  session  scripts  are  searched  for:\n$HOME/.xsession and $HOME/.Xsession (note the difference  in  case).   The  first  one\nfound  is used.  If the script is not executable, it is marked to be executed with the\nBourne shell interpreter, sh.  Finally, if none of the above succeeds,  the  following\nprograms  are searched for: /usr/bin/x-session-manager, /usr/bin/x-window-manager, and\n/usr/bin/x-terminal-emulator.  The first one found is used.  If none are found,  Xses‐\nsion aborts with an error.\n\n/etc/X11/Xsession.d/90x11-commonssh-agent\nStart ssh-agent(1), if needed.  If the line ‘use-ssh-agent’ is present in Xsession.op‐\ntions, and no SSH agent process appears to be running already, ssh-agent is marked  to\nbe  used to execute the startup program determined previously.  Note: this functional‐\nity may move to the ssh package in the future.\n\n/etc/X11/Xsession.d/99x11-commonstart\nStart the X session.  The startup program is executed, inside a Bourne shell if it  is\nnot  executable,  and  inside  an ssh-agent if necessary.  The shell's exec command is\nused to spare a slot in the process table.\n\nCUSTOMIZING THE STARTUP PROCEDURE\nOf course, any of the existing files can be edited in place.\n\nBecause the order in which the various scripts in /etc/X11/Xsession.d are executed is  impor‐\ntant, files to be added to this directory should have a well-formed name.  The following for‐\nmat is recommended:\n\n* a two-digit number denoting sequence;\n\n* the name of the package providing the script (or ‘custom’ for locally-created scripts);\n\n* an underscore;\n\n* a description of the script's basic function, using only characters allowed by run-parts.\n\nHere is an example of how one might write a script, named  40customload-xmodmap,  to  invoke\nxmodmap(1):\n\nSYSMODMAP=\"/etc/X11/Xmodmap\"\nUSRMODMAP=\"$HOME/.Xmodmap\"\n\nif [ -x /usr/bin/X11/xmodmap ]; then\nif [ -f \"$SYSMODMAP\" ]; then\nxmodmap \"$SYSMODMAP\"\nfi\nfi\n\nif [ -x /usr/bin/X11/xmodmap ]; then\nif [ -f \"$USRMODMAP\" ]; then\nxmodmap \"$USRMODMAP\"\nfi\nfi\n\nThose  writing  scripts for Xsession to execute should avail themselves of its built-in shell\nfunctions, described below.\n\nBUILT-IN SHELL FUNCTIONS\nmessage is used for communicating with the user.  It is a wrapper for the echo(1) command and\nrelies upon echo for its argument processing.  This function may be given an arbitrarily long\nmessage string, which is formatted to the user's terminal width  (breaking  lines  at  white‐\nspace)  and sent to standard error.  If the DISPLAY environment variable is set and the xmes‐‐\nsage(1) program is available, xmessage is also used to display the message.\n\nmessagenonl is used for communicating with the user when a trailing newline is  undesirable;\nit omits a trailing newline from the message text.  It otherwise works as message.\n\nerrormsg is used for indicating an error condition and aborting the script.  It works as mes‐‐\nsage, above, except that after displaying the message, it will exit Xsession with status 1.\n\n### ENVIRONMENT\n\nThe following environment variables affect the execution of Xsession:\n\nHOME   specifies the user's home directory; various files are searched for here.\n\nTMPDIR names a default directory for temporary files; if the standard X  session  error  file\ncannot be opened, this variable is used to locate a place for one.\n\nCOLUMNS\nindicates  the  width  of  terminal device in character cells.  This value is used for\nformatting diagnostic messages.\n\n### INPUT FILES\n\n/etc/X11/Xsession.d/\nis a directory containing Bourne shell scripts to be executed by Xsession.   Files  in\nthis  directory  are  matched  using run-parts and are sourced, not executed in a sub‐\nshell.\n\n/etc/X11/Xresources/\nis a directory containing files corresponding to Debian package names, each  of  which\ncontains system-wide X resource settings for X clients from the corresponding package.\nThe settings are loaded with xrdb -merge.  Files in this directory are  matched  using\nrun-parts.\n\n/etc/X11/Xsession.options\ncontains  configuration  options  for  the /etc/X11/Xsession script.  See Xsession.op‐‐\ntions(5) for more information.\n\n$HOME/.Xresources\ncontains X resources specific to the invoking user's environment.   The  settings  are\nloaded with xrdb -merge.  Note that $HOME/.Xdefaults is a relic from X Version 10 (and\nX11R1) days, before app-defaults files were implemented.  It has been  deprecated  for\nover ten years at the time of this writing.  .Xresources should be used instead.\n\n$HOME/.xsession\nis  a  sequence  of commands invoking X clients (or a session manager such as xsm(1)).\nSee the manual page for xinit for tips on writing an .xsession file.\n\n### OUTPUT FILES\n\n$HOME/.xsession-errors\nis where standard output and standard error for Xsession script and all X client  pro‐\ncesses are directed by default.\n\n$TMPDIR/filename\nis  where  the  X  session  error  file  is placed if $HOME/.xsession-errors cannot be\nopened.  For security reasons, the exact  filename  is  randomly  generated  by  temp‐‐\nfile(1).\n\n### AUTHORS\n\nStephen  Early,  Mark  Eichin,  and  Branden  Robinson  developed Debian's X session handling\nscripts.  Branden Robinson wrote this manual page.\n\n### SEE ALSO\n\nXsession.options(5), X(7), run-parts(1), ssh-agent(1), startx(1), tempfile(1), xdm(1),  xmes‐‐\nsage(1), xmodmap(1), xrdb(1), sh(1)\n\n\n\nDebian Project                               2004-11-04                                  Xsession(5)\n\n"
        }
    ],
    "structuredContent": {
        "command": "Xsession",
        "section": "5",
        "mode": "man",
        "summary": "Xsession - initialize X session",
        "synopsis": "Xsession [ session-type ]",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "Xsession.options",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/Xsession.options/5/json"
            },
            {
                "name": "X",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/X/7/json"
            },
            {
                "name": "run-parts",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/run-parts/1/json"
            },
            {
                "name": "ssh-agent",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/ssh-agent/1/json"
            },
            {
                "name": "startx",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/startx/1/json"
            },
            {
                "name": "tempfile",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/tempfile/1/json"
            },
            {
                "name": "xdm",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/xdm/1/json"
            },
            {
                "name": "sage",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/sage/1/json"
            },
            {
                "name": "xmodmap",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/xmodmap/1/json"
            },
            {
                "name": "xrdb",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/xrdb/1/json"
            },
            {
                "name": "sh",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/sh/1/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 28,
                "subsections": [
                    {
                        "name": "failsafe",
                        "lines": 5
                    },
                    {
                        "name": "default",
                        "lines": 130
                    }
                ]
            },
            {
                "name": "ENVIRONMENT",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "INPUT FILES",
                "lines": 25,
                "subsections": []
            },
            {
                "name": "OUTPUT FILES",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 6,
                "subsections": []
            }
        ]
    }
}