ksh may not execute /etc/profile during graphical login in Red Hat Enterprise Linux 5

Solution Verified - Updated -

Issue

Problem

  • When user shell is /bin/ksh, /etc/profile isn't executed at X login.
  • In Red Hat Enterprise Linux 5, /etc/profile may not get executed if a user has /bin/ksh as their login shell and the user logs into the system using the graphical login screen.  Not running /etc/profile during login can cause problems with a user's default environment such as invalid program search paths, missing command aliases, and problems with other default values.
  • This problem should not occur when a user logs in locally through the text console or remotely with programs such as ssh.

Environment

Red Hat Enterprise Linux 5.2

Resolution

This problem is resolved in ksh-20080202-2.el5 which was released in Red Hat Enterprise Linux 5.3.  If you are experiencing this problem, please update ksh to the latest version available in Red Hat Enterprise Linux 5.

Root Cause

When called as a result of a gdm (Grahical Display Manager) login, ksh may not recognize that it is a login shell, and thus may not execute the commands in /etc/profile.

The detailed answer is that, as part of the gdm user login and session creation process, some variant of the following command is executed:

exec $SSH_AGENT /bin/sh -c "exec -l $SHELL -c "$DBUS_LAUNCH <script>""

where

  • $SSH_AGENT is /usr/bin/ssh-agent,

  • $SHELL is the user's shell as specified in /etc/passwd,

  • $DBUS_LAUNCH is /usr/bin/dbus-launch --exit-with-session, and

  • <script> is one of $HOME/.xsession, $HOME/.Xclients, or /etc/X11/xinit/Xclients, depending on how the system is configured.

The key point is that, in the case of a user whose shell is specified as /bin/ksh, then the command run is

exec /usr/bin/ssh-agent /bin/sh -c "exec -l /bin/ksh -c "/usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients""

According to the sh manpage:

If the -l option is supplied, the shell places a dash at the begin-
ning of the zeroth arg passed to command.  This is what login(1)
doe

The function of the dash is to let the ksh process know that it is a login shell.  From the ksh manpage):

If the shell is invoked by exec(2), and the first character of argument
zero  ($0) is -, then the shell is assumed to be a login shell and com-
mands are read from /etc/profile and then from either .profile  in  the
current directory or $HOME/.profile, if either file exists.

However, there was a problem in ksh that prevented it from recognizing that argument zero ($0) began with a dash when $0 included a full path like /bin/bash.

Diagnostic Steps

  1. Add the line "date > /tmp/now" to /etc/profile
  2. Set a user's shell to /bin/ksh
  3. Log in as that user from gdm
  4. Note that the /tmp/now file will not have been generated
  • Component
  • ksh

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.