NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: xsrc/54851: .profile is not read by sh when using xdm or other login managers
The following reply was made to PR xsrc/54851; it has been noted by GNATS.
From: "John D. Baker" <jdbaker%consolidated.net@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: xsrc/54851: .profile is not read by sh when using xdm or other
login managers
Date: Sat, 11 Jan 2020 07:43:52 -0600 (CST)
As noted by others, only login shells read ".profile".
When 'xdm' starts the session, it is just another fork/chown/exec sequence
and "/bin/sh" interpreting the master Xsession script
("/etc/X11/xdm/Xsession") is not a login shell. The same is true for any
display manager program that starts its session script with "/bin/sh".
Since the various penguin-OS flavors typically have "bash" and it has the
"-l" option to force it to be a login shell, such installations typically
use:
#!/bin/bash -l
at the top of their master Xsession script. Since the process is run as
the local user, it reads their ".profile" (".bash_profile) the same as a
terminal login.
Some twenty-odd years ago I figured this out after tracing the "chain of
custody" of the xdm session process and crafted a "~/.xsession" script
to handle the situation by explicitly sourcing my ".profile" at the start
of the script.
----------
#!/bin/sh
#
# .xsession -- user-specific GUI session initialization
# This script is the next-to-last thing that runs in the process started
# by the display manager.
# As it functions as a login shell, the script should read the system
# and user-specific startup files to set up the user's environment.
# This is often dependent on the shell interpreter used.
# If we were executed by 'xinit' or included by 'startx', arrange for
# output/error logging just like Xsession would.
hostname=$(hostname)
hostname=${hostname%%.*}
case $0 in
*.xinitrc|*/startx)
exec > ~/.xsession-errors.${hostname} 2>&1
echo "Executed as: "${0##*/}
;;
*.xsession)
# If we were executed as ".xsession", check which interpreter is in use.
# If it is 'bash', assume we are a login shell already.
# Otherwise, if it is not 'bash', source .profile to set environment.
[ -z "$BASH_VERSION" ] && [ -s ~/.profile ] && . ~/.profile
;;
esac
[...]
--
|/"\ John D. Baker, KN5UKS NetBSD Darwin/MacOS X
|\ / jdbaker[snail]consolidated[flyspeck]net OpenBSD FreeBSD
| X No HTML/proprietary data in email. BSD just sits there and works!
|/ \ GPGkeyID: D703 4A7E 479F 63F8 D3F4 BD99 9572 8F23 E4AD 1645
Home |
Main Index |
Thread Index |
Old Index