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

Re: Where is $MAIL set? (login process)

In a message of 1 Jun 2003 Bill Moseley <moseley@hank.org> wrote:

> .... This time I decided to start using xdm to manage logins.
> This caused icewm to no longer display the little mailbox icon, so it 
> turned out that the problem was that MAIL was not being set when logging 
> in with xdm.
> From what I gather, login(1) sets MAIL, but xdm bypasses login.

Bypass is not the right word here, xdm *replaces* login.

> So, I'm wondering why MAIL is not being set with xdm (seem like it 
> should) ....

So it seems to me, but more knowledgeable people may be able to explain
the good reason why it does not. It is not hard to have MAIL set in X
sessions started by xdm, you can insert a statement like
  export MAIL=/var/mail/$LOGNAME
in one of:
  /etc/X11/xdm/Xsession  called by xdm to start the user's X session, calls
  /etc/X11/Xsession      the general script to start an X session
  /home/*/.xsession      each user's customization of an X session
unless the more knowledgeable people I referred to before warn us that that
is a bad idea.

> .... and I'd also like to understand how it gets set normally when  using
> login -- e.g. is it read set in a startup script?  I assume  there's a
> setting to say mail is in /var/mail/$USER.

'man login' tells me that login constructs MAIL from the information in
/etc/passwd. Exactly how is not stated; my guess is that login appemds the
user name of the user who has just logged in to the home directory of user
'mail', so that with the following lines in /etc/passwd
  ben:x:1001:100:Ben Kal,,,:/home/ben:/bin/bash
for user ben MAIL is assigned the value

> Secondly, is there a simple explanation of the boot and login process for
> Debian?  Something that explains the order of programs and scripts run.

The boot process:

I am afraid that a really *simple* explanantion would not add much to what
you already know, while a valuable explanation would be quite a long story
and requires knowledge of some details of your system, for instance what
boot loader you use and whether your kernel uses the 'hotplug' facility or

My advice is to study the documentation of your boot loader and search the
web for descriptions of the boot process. I suppose there must be some.

The login process:

The man pages of
- login
- xdm
- bash or tcsh or any other shell you use
are pretty clear about what happens (mostly what startup scripts they
execute) under what circumstances. Issues to be aware of are:
- xdm replaces login but does not set up the environment in exactly the same
  way as login does, in particular it does not set MAIL as you have found
- the shell of an X terminal is not a login shell (the user is already
  logged in through xdm) so the startup scripts for login shells,
  /etc/profile and ~/.bash_profile in the case of bash, are not executed!
  This easily causes the environment of shells on virtual consoles to be
  radically different from the environment of shells in X terminals.
- environment variables have to be set only once and are inherited by all
  processes that are children of the login shell or the X session,
  but things like aliases and shell options have to be set every time
  a shell is started.

To ensure that:
- the environment is the same in all shells
- on startup shells do not read more startup scripts than necessary
I did the following:
- put all settings of environment variables in /etc/profile and ~/.bash_profile
- put all aliases and shell options in /etc/bash.bashrc and ~/.bahsrc
- made /etc/profile source /etc/bash.bashrc
- made ~/.bash_profile source ~/.bashrc
- made ~/.xsession source both /etc/profile and ~/.bash_profile,
  after setting an environment variable that to /etc/profile and ~/.bash_profile
  signals that they have been sourced by ~/.xsession;
  in that case they do not need to source /etc/bash.bashrc resp. ~/.bashrc,
  and instead unset that environment variable.



B.F.M. Kal
Anjelierstraat 1,   2014 TC Haarlem,  Netherlands
tel +31 23 5324909, benkal@euronet.nl

Reply to: