/etc/profile.d/*.sh executed twice

Please reproduce your error on a second machine before posting, and check the error by running without saved changes or extra modules (See FAQ No. 13, "How to report a bug"). For unstable Porteus versions (alpha, beta, rc) please use the relevant thread in our "Development" section.
Post Reply
rych
Black ninja
Black ninja
Posts: 80
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 2.1 32-bit
Location: NZ

/etc/profile.d/*.sh executed twice

Post#1 by rych » 23 Oct 2017, 07:30

In Porteus 3.2.2 64bit, LXDE, login as root,
/etc/profile.d/*.sh scripts sourced at the end of /etc/profile,
appear to be executed twice.

I know it because I amend the $PATH in a /etc/profile.d/myprofile.sh, and then in a fresh terminal echo $PATH displays my amendment twice.

burdi01
Black ninja
Black ninja
Posts: 65
Joined: 18 Aug 2013, 12:09
Distribution: Slackware, Xubuntu
Location: The Netherlands

/etc/profile.d/*.sh executed twice

Post#2 by burdi01 » 25 Oct 2017, 09:33

Do you use persistence? If so it might be that you add your change to a PATH that already was changed in your previous session. To veryfy test with an Always Fresh boot.
:D

jssouza
DEV Team
DEV Team
Posts: 348
Joined: 09 Jul 2015, 14:17
Distribution: Porteus x86 arm
Location: Liechtenstein

/etc/profile.d/*.sh executed twice

Post#3 by jssouza » 25 Oct 2017, 10:20

This happens because both the non-login shell startup script as well as the login shell startup script end up calling all scripts in /etc/profile.d

Code: Select all

guest@porteus:~$ cat .bash_profile 
# Use settings from ~/.bashrc
if [ -f ~/.bashrc ]; then
    source ~/.bashrc
figuest@porteus:~$ cat .bashrc 
# Setup color scheme for list call <brokenman>
alias ll='/bin/ls --color=auto -lF'
alias la='/bin/ls --color=auto -axF'
alias ls='/bin/ls --color=auto -xF'

# Append any additional sh scripts found in /etc/profile.d/:
for y in /etc/profile.d/*.sh ; do [ -x $y ] && . $y; done
unset y

# Setup shell prompt for guest <wread and fanthom>
PS1='\[\033[01;36m\]\u@\h:\[\033[01;32m\]\w\$\[\033[00m\] '
PS2='> '
This is on all desktops.

burdi01
Black ninja
Black ninja
Posts: 65
Joined: 18 Aug 2013, 12:09
Distribution: Slackware, Xubuntu
Location: The Netherlands

/etc/profile.d/*.sh executed twice

Post#4 by burdi01 » 25 Oct 2017, 12:22

Hmm, it is years and years ago that I resolved login/non-login "thing" for my linux installations, and consequently forgot completely about it. [/blush] That solution comes down to sourcing the /etc/profile.d/* scripts in /etc/profile only and only doing the missing settings (e.g.PS1, PS2 and the dircolors) in ~/bashrc.
However for a user-extensible distribution like Porteus that is not a complete solution. Instead the profile.d scripts should cater for possible "cumulative" effects. E.g.:

Code: Select all

if ! echo "$PATH" | grep -qE "(^|.*:)mydir(:|$)" ; then
   export $PATH="$PATH:mydir"
fi
An empty PATH is highly unlikely. For an environment variable that can be empty the code should be like:

Code: Select all

if ! echo "$LD_LIBRARY_PATH" | grep -qE "(^|.*:)mydir(:|$)" ; then
   export $LD_LIBRARY_PATH="$LD_LIBRARY_PATH${LD_LIBRARY_PATH:+:}mydir"
fi
:D

rych
Black ninja
Black ninja
Posts: 80
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 2.1 32-bit
Location: NZ

/etc/profile.d/*.sh executed twice

Post#5 by rych » 28 Oct 2017, 04:31

Yes indeed, /etc/profile.d/*.sh are executed both from within /etc/profile AND .bashrc.

I've removed these lines from .bashrc.

Code: Select all

# Append any additional sh scripts found in /etc/profile.d/:
for y in /etc/profile.d/*.sh ; do [ -x $y ] && . $y; done
unset y
That solved it then. Or am I now breaking something else? Both "login" and "interactive" shells source /etc/profile anyway...

burdi01
Black ninja
Black ninja
Posts: 65
Joined: 18 Aug 2013, 12:09
Distribution: Slackware, Xubuntu
Location: The Netherlands

/etc/profile.d/*.sh executed twice

Post#6 by burdi01 » 28 Oct 2017, 09:50

Or am I now breaking something else?
As elaborated upon in section 6.2 "Bash Startup Files" of the Bash Reference Manual (which can be downloaded/read from e.g. https://www.gnu.org/software/bash/manual/bash.html) you may or may not be breaking something.
:D

Post Reply