[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Debianly Correct place to add ~/bin to $PATH ? - .xsession vs .xinitrc



Brian wrote:
> Zenaan Harkness wrote:
> > Bob Proulx wrote:
> > > I prefer:
> > > ,----[ ~/.xsession ]
> > > | #!/bin/bash --login
> > > | exec x-session-manager
> > > `----
> > >
> > > And VERY IMPORTANT FOR THE ABOVE then be sure to:
> > >
> > >   chmod a+x ~/.xsession
> > 
> > This looks like an elegant solution. Thank you.
> > 
> > I currently have .xinitrc with a single line:
> > exec ck-launch-session startxfce4

I assume by your use of .xinitrc that you are logging into the Linux
virtual console (aka a text console) and then starting X by launching
it with either "xinit" or "startx"?  Is that correct?  Otherwise I
don't believe the .xinitrc file would be used.  (I do this too.)

The ck-launch-session program is an undocumented part of consolekit.
The x-session-manager is a Debian "alternative" that launches the
currently installed and configured X session manager.  Could be GNOME,
KDE, LXDE, XFCE or even lighter could be Openbox.  x-session-manager
implies a Desktop Environment.

  $ update-alternatives --display x-session-manager
  x-session-manager - manual mode
    link currently points to /usr/bin/xfce4-session
  /usr/bin/gnome-session - priority 50
    slave x-session-manager.1.gz: /usr/share/man/man1/gnome-session.1.gz
  /usr/bin/lxsession - priority 49
    slave x-session-manager.1.gz: /usr/share/man/man1/lxsession.1.gz
  /usr/bin/openbox-session - priority 40
    slave x-session-manager.1.gz: /usr/share/man/man1/openbox-session.1.gz
  /usr/bin/startlxde - priority 50
    slave x-session-manager.1.gz: /usr/share/man/man1/startlxde.1.gz
  /usr/bin/xfce4-session - priority 40
    slave x-session-manager.1.gz: /usr/share/man/man1/xfce4-session.1.gz
  Current 'best' version is '/usr/bin/gnome-session'.

There is also the x-window-manager Debian "alternative" which is what
you have installed for a window manager.  It could be any one of the
long list window managers that you might have installed.

  $ update-alternatives --display x-window-manager
  x-window-manager - auto mode
    link currently points to /usr/bin/fvwm2
  /usr/bin/awesome - priority 20
    slave x-window-manager.1.gz: /usr/share/man/man1/awesome.1.gz
  /usr/bin/fvwm2 - priority 90
    slave x-window-manager.1.gz: /usr/share/man/man1/fvwm2.1.gz
  /usr/bin/i3 - priority 20
    slave x-window-manager.1.gz: /usr/share/man/man1/i3.1.gz
  /usr/bin/metacity - priority 60
    slave x-window-manager.1.gz: /usr/share/man/man1/metacity.1.gz
  /usr/bin/openbox - priority 90
    slave x-window-manager.1.gz: /usr/share/man/man1/openbox.1.gz
  /usr/bin/stumpwm - priority 20
    slave x-window-manager.1.gz: /usr/share/man/man1/stumpwm.1.gz
  /usr/bin/twm - priority 40
    slave x-window-manager.1.gz: /usr/share/man/man1/twm.1.gz
  /usr/bin/xfwm4 - priority 60
    slave x-window-manager.1.gz: /usr/share/man/man1/xfwm4.1.gz
  Current 'best' version is '/usr/bin/fvwm2'.

I used x-session-manager in my example .xinitrc file because it is the
most general.  In reality I don't start a Desktop Environment.  For me
(and perhaps for you) using x-window-manager is more appropriate.
Actually I just start either 'fvwm' (or awesome, another window
manager) directly since I know exactly what I want there.  It is a
strongly personal preference for everyone.

> > Is .xession (as you show above) better or different to .xinitrc ?
> 
> I'd associate .xinitrc with xinit and startx (which is a frontend for
> xinit).
> 
> xdm uses xsession (and .xsession if it exists).

Correct.  The difference is the difference between starting X from the
user logged in by the text console _or_ having the graphical login
manager start X and then have you log into the already runnin
session.

The .xinitrc is used by 'xinit'.  You can log into one of the Linux
virtual consoles and start X with either 'xinit' or the 'startx'
wrapper for it.  The xinit program expects to find a configuration
file in $HOME/.xinitrc just like a typical program.  The startx script
is a system wrapper that points xinit to /etc system locations of
configuration files.  That way if the user has not set up window
managers, X resources, keymaps and so forth that a nice default system
set of all of those things will be used.

If you have a freshly created new user and no files then running
startx will start up something reasonable by what is configured in the
system /etc configuration files.  On the other hand if you are an
experienced user, know what you want, have customizations to set up
your own window manager and so forth then you will have overridden
everything startx would do.  In that case I prefer just to use xinit
directly since I am not using any of the features of startx.

The result between using xinit and startx does not really matter and
is no difference.  But just for simplication I prefer to remove extra
layers that don't do anything and work more directly.  Using .xinitrc
is about as simple as things can get.

If there are no customized user files then startx will point xinit to
the system /etc/X11/xinit/xinitrc file which itself does nothing but
turn around and use /etc/X11/Xsession.  The /etc/X11/Xsession file is
place that all system X functionality has been converged to using.

> On a Debian system xession (plus .xession) gives the same X environment
> whether it is started by xinit, startx or xdm (or, I assume, gdm etc).

Yes.  That is the goal.

The /etc/X11/Xsession script and all of the /etc/X11/Xsession.d/*
script parts run by it look for local customizations.  That script
has the file locations for most of the things we have been talking
about.  Here is a snippet from the configuration section of it.

  OPTIONFILE=/etc/X11/Xsession.options
  SYSRESOURCES=/etc/X11/Xresources
  USRRESOURCES=$HOME/.Xresources
  SYSSESSIONDIR=/etc/X11/Xsession.d
  USERXSESSION=$HOME/.xsession
  USERXSESSIONRC=$HOME/.xsessionrc
  ALTUSERXSESSION=$HOME/.Xsession
  ERRFILE=$HOME/.xsession-errors

All of the X display managers such as xdm, gdm, gdm3, kdm, lightdm and
others use /etc/X11/Xsession to launch the user session after the user
logs into them.  For example the USERXSESSIONRC file is handled by the
snippet:

File /etc/X11/Xsession.d/40x11-common_xsessionrc:
  #Source user defined xsessionrc (locales and other environment variables)
  if [ -r "$USERXSESSIONRC" ]; then
    . "$USERXSESSIONRC"
  fi

But note that this is source from a /bin/sh script not a bash script.
The start of the /etc/X11/Xsession file is:

  #!/bin/sh
  #
  # /etc/X11/Xsession

And therefore the .xsessionrc file is a /bin/sh script not a bash
script.  This is a subtle point if standard shell syntax is used in
the .bash_profile file and then sourced into the .xsessionrc file.
But if bash extensions are used then since /bin/sh is not bash by
default anymore there will be syntax errors.  Of course if you only
use portable shell syntax everywhere then there is no problem.  You
will never notice anything different in that case.  But if you use a
bash specific syntax then /bin/sh not being bash would throw an error.
The error will show up in the $HOME/.xsession-errors file.

Which is the reason I prefer the .xsession script.  In that script I
can specify my login shell to be bash and then I have no restriction
to use portable shell syntax in my bash startup scripts.  Same thing
applies if I were using ksh or zsh.  The .xsession script is handled
by the /etc/X11/Xsession.d/50x11-common_determine-startup snippet
which executes it if it is executable or sources it if it is not.  If
it is not executable and it is sourced then it still has the /bin/sh
syntax problem.  That is why it must be executable if you are trying
to use any shell other than /bin/sh because executing it is the only
way to invoke the #!/bin/bash interpreter.

Whew!  A complicated subject! :-)

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: