Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 610898 - sys-apps/baselayout - /etc/profile.d/*.sh should be sourced before /etc/bash/bashrc
Summary: sys-apps/baselayout - /etc/profile.d/*.sh should be sourced before /etc/bash/...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: William Hubbs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-25 15:28 UTC by Evert
Modified: 2020-03-31 09:23 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
/etc/profile.patch (profile.patch,666 bytes, patch)
2017-02-25 15:28 UTC, Evert
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Evert 2017-02-25 15:28:09 UTC
Created attachment 465118 [details, diff]
/etc/profile.patch

Currently, /etc/profiles sources or sets:
- /etc/profile.env
- other defaults
- /etc/bash/bashrc
- /etc/profile.d/*.sh

I know it's a compromise to source /etc/bash/bashrc in /etc/profile and the comment in /etc/profile documents that too. However, since it's a compromise, sourcing /etc/bash/bashrc should be done completely at the end which is after sourcing /etc/profile.d/*.sh, so:
- /etc/profile.env
- other defaults
- /etc/profile.d/*.sh
- /etc/bash/bashrc

In most cases it won't make a difference, but in some cases it will. This should be corrected.

Patch included.
Comment 1 Evert 2017-02-25 15:31:54 UTC
Correction:
Currently, /etc/profiles sources or sets:

Should be:
Currently, /etc/profile sources or sets:
Comment 2 Patrick McLean gentoo-dev 2017-02-26 06:40:59 UTC
I don't think I agree with this, /etc/bash/bashrc sets the defaults, then /etc/profile.d/*.sh overrides those defaults with specific settings. Having it sourced in the current order allows one to drop a file in /etc/profile.d to override defaults without having to modify the standard bashrc file.
Comment 3 Evert 2017-02-26 11:58:16 UTC
Please read the man page:
roughly said:
profile is for environment settings etc
bashrc is for aliases / shell specific stuff

The only reason /etc/bash/bashrc is called from /etc/profile is because if its not in ~/.profile, it won't be sourced at login. It is a compromise to call it anyway so if it needs to be called from /etc/profile, it should be done completely at the end.

Modifying the standard bashrc should be done in ~/.bashrc or /etc/bash/bashrc.d/* anyway

profile and bashrc should not be mixed!

Note non-login shells do not even source profile, only bashrc so ...
Override settings is not applicable & not relevant here ...
Comment 4 Evert 2017-02-28 18:53:09 UTC
Let me give you some hard evidence why /etc/profile.d/*.sh should be sourced before /etc/bash/bashrc.
Example:

# cat > /etc/env.d/02locale <<'EOF'
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE=C
LC_MONETARY=en_US.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=""
EOF

# env-update
>>> Regenerating /etc/ld.so.cache...

# cat > /etc/profile.d/locale_users.sh <<'EOF'
[ $(id -u) -ge 1000 ] && export LC_MESSAGES="nl_NL.UTF-8"
EOF

# cat > /etc/bash/bashrc.d/test_locale.sh <<'EOF'
cat /tmp/no_file  # does not exist
EOF

# exit  # switch back to regular user

$ bash --login
cat: /tmp/no_file: No such file or directory

$ bash --login
cat: /tmp/no_file: No such file or directory

$ bash
cat: /tmp/no_file: Bestand of map bestaat niet

$ bash
cat: /tmp/no_file: Bestand of map bestaat niet

$ bash --login
cat: /tmp/no_file: No such file or directory

So clearly, /etc/bash/bashrc acts diffently depending on login-shell or not because /etc/profile hasn't finished doing all of its settings when /etc/bash/bashrc is called too early.

However, if (in /etc/profile) you source /etc/profile.d/*.sh before /etc/bash/bashrc, the environment gets consistent for both login-shells and non-login shells:

$ bash --login
cat: /tmp/no_file: Bestand of map bestaat niet

$ bash --login
cat: /tmp/no_file: Bestand of map bestaat niet

$ bash
cat: /tmp/no_file: Bestand of map bestaat niet

$ bash
cat: /tmp/no_file: Bestand of map bestaat niet

So, consistent behaviour is the reason for calling /etc/bash/bashrc after al the profile stuff.
Thank you.
Comment 5 Evert 2017-03-08 17:47:53 UTC
ping, any questions?
Comment 6 Larry the Git Cow gentoo-dev 2017-10-03 22:02:41 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/baselayout.git/commit/?id=3d46659bf88caf23cfb631671dbece20bfdf8572

commit 3d46659bf88caf23cfb631671dbece20bfdf8572
Author:     William Hubbs <williamh@gentoo.org>
AuthorDate: 2017-10-03 21:58:35 +0000
Commit:     William Hubbs <williamh@gentoo.org>
CommitDate: 2017-10-03 22:01:40 +0000

    process files in /etc/profile.d before /etc/bash/bashrc for consistency
    
    Bug: https://bugs.gentoo.org/show_bug.cgi?id=610898

 etc/profile | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)}
Comment 7 William Hubbs gentoo-dev 2017-10-03 22:09:03 UTC
This will be in baselayout-2.5.