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

bash logins: a little buggy (and potentially dangerous)?



Bash's login behavior seems a little buggy and potentially dangerous.
As far as I can tell, when invoked as a login shell (i.e. via rxvt
-ls), bash does three things which, in combination, are a little
weird:

  1) it sets PATH back to the system default
  2) it resets the umask to 002
  3) it leaves all the other environment variables alone so that
     there's no way to tell that it's done 1 and 2 without both checking
     the first character of ARGV[0] for "-", and searching all the
     command line options for --login. [***]

This wouldn't be so bad if it was documented, but if you were in a
situation where it was really important for your default umask to be
007, you might be surprised that doing this in your .xsession:

  source ${HOME}/.bashrc
  exec scwm

and this in your .bashrc (symlinked to) .bash_login:

  if [ "${BASH_INITIALIZED}" != "true" ]
  then
    export PATH=whatever
    umask 007
    export BASH_INITIALIZED=true
  fi

would actually have you end up with rxvt's with a umask of 002
whenever they're launched from scwm's (or any other window manager's)
Apps menu.  That's because the menu entry uses rxvt -ls, and bash
resets PATH and umask for a login shell, *but not the rest of the
envt*, so it circumvents the BASH_INITIALIZED test.

Does this at least seem a little unepected to anyone else?

[***] Actually, there is an easier solution for the problem, but it
requires *not* symlinking .bash_login or .profile to .bashrc (which
many people do).  Instead put something like this in your .bash_login:

  export THIS_REALLY_IS_A_LOGIN_SHELL=true
  . ${HOME}/.bashrc

And then do something like this in .bashrc:

  if [ "${THIS_REALLY_IS_A_LOGIN_SHELL}" != "true" ]
  then
    PATH=whatever     # reset the path since it got clobbered.
    umask 007         # reset the umask since it got clobbered.
  fi

  if [ "${BASH_INITIALIZED}" != "true" ]
  then
    # Do other things here that bask won't clobber in subshells, even
    # login subshells
    export BASH_INITIALIZED=true
  fi

But I still say it's a little strange that you need to do this...

Thanks

-- 
Rob Browning <rlb@cs.utexas.edu> PGP=E80E0D04F521A094 532B97F5D64E3930


Reply to: