Page 1 of 1

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

Posted: 23 Oct 2017, 07:30
by rych
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.

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

Posted: 25 Oct 2017, 09:33
by burdi01
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

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

Posted: 25 Oct 2017, 10:20
by jssouza
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.

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

Posted: 25 Oct 2017, 12:22
by burdi01
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

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

Posted: 28 Oct 2017, 04:31
by rych
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...

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

Posted: 28 Oct 2017, 09:50
by burdi01
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

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

Posted: 13 Feb 2021, 12:19
by rych
The scripts in /etc/profile.d are still invoked twice in Porteus-v5.0rc2. Why, and what's the modern way to avoid it?

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

Posted: 14 Feb 2021, 09:48
by burdi01
It looks like my remarks from 2017 are still applicable ...
:D

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

Posted: 14 Feb 2021, 10:57
by Blaze
rych and burdi01, and now this is fixed in the main tree :oops:

Thanks.

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

Posted: 15 Feb 2021, 07:32
by rych
Blaze, thank you. Where can I download the "main tree" and if not I have 2 questions please:

How did you fix this particular issue, which file to edit?

I'd like to finally upgrade from porteus 4. Would you advise to start using 5.0rc2 now as it could take another year to wait for Slackware to go to 15 and porteus to go to 5.0 release?

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

Posted: 15 Feb 2021, 09:28
by ncmprhnsbl
rych wrote:
15 Feb 2021, 07:32
How did you fix this particular issue, which file to edit?
same as what you did:
"removed these lines from (home/guest/) .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
rych wrote:
15 Feb 2021, 07:32
I'd like to finally upgrade from porteus 4. Would you advise to start using 5.0rc2 now as it could take another year to wait for Slackware to go to 15 and porteus to go to 5.0 release?
:D.. well, hopefully it won't be a year.. i think they'll go beta sometime soonish(months?) ..
about rc2: there's been a lot of movement in slackware current since rc2 release(aug 2020), not least python and quite few key packages as well as our script rewrite to pygobject3 is further along ... so .. it's pretty likely an rc3 will be put out before slackware goes final or even beta.. at the moment, i'm watching the slackware current changelog: expecting a mass package rebuild for the latest glibc currently in testing..

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

Posted: 18 Feb 2021, 18:25
by Blaze
rych wrote:
15 Feb 2021, 07:32
How did you fix this particular issue, which file to edit?
ncmprhnsbl wrote:
15 Feb 2021, 09:28
same as what you did:
"removed these lines from (home/guest/) .bashrc."
Yep

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

Posted: 23 Oct 2021, 19:50
by skladby
Scripts in /etc/profile.d are sourced up to thrice (under Bash), but only in one of these three runs fully:
  1. At login /etc/profile is read with the sourcing
  2. Also at login ~/.bashprofile is read which sources ~/.bashrc with the sourcing
  3. Then in any user invoked shell ~/.bashrc is read with the sourcing
But only intiially, in /etc/profile all executable *.sh files in /etc/profile.d are sourced.

Following in ~/.bashrc and therefore also ~/.bashprofile sourcing stops after "user.sh", i.e. "vdpau.sh", "vdpau-va-gl.sh", and "xdg.sh" are not sourced by ~/.bashrc and ~/.bashprofile. The reason is a wrong "break 2" instruction in "user.sh", breaking also out from the sourcing "for" loop, so all scripts following after "user.sh" in alphabetical order are not sourced. The break is only triggered if a logged-in user exists, i.e. not in /etc/profile - good for those who want to use freedesktop.org compliant "$XDG_RUNTIME_DIR" (defined in "xdg.sh"). This fragile construction should in general be replaced by a stable architecture. Currently the historical "parallelism" with csh seems to be valued higher - obviously without currently offering (t)csh anywhere in Porteus land (is it really needed?)

Note that "fully" restricts to those scripts / files in /etc/profile.d with "x" attribute set - the affected sourcing routines require it (is this really intended?).