/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
Samurai
Samurai
Posts: 176
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 4.0 64 LXDE
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
Samurai
Samurai
Posts: 142
Joined: 18 Aug 2013, 12:09
Distribution: Slackware PartedMagic 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
Legendary
Legendary
Posts: 1165
Joined: 09 Jul 2015, 14:17
Distribution: Porteus x86 arm

/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
Samurai
Samurai
Posts: 142
Joined: 18 Aug 2013, 12:09
Distribution: Slackware PartedMagic 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
Samurai
Samurai
Posts: 176
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 4.0 64 LXDE
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
Samurai
Samurai
Posts: 142
Joined: 18 Aug 2013, 12:09
Distribution: Slackware PartedMagic 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

rych
Samurai
Samurai
Posts: 176
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 4.0 64 LXDE
Location: NZ

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

Post#7 by rych » 13 Feb 2021, 12:19

The scripts in /etc/profile.d are still invoked twice in Porteus-v5.0rc2. Why, and what's the modern way to avoid it?

burdi01
Samurai
Samurai
Posts: 142
Joined: 18 Aug 2013, 12:09
Distribution: Slackware PartedMagic Xubuntu
Location: The Netherlands

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

Post#8 by burdi01 » 14 Feb 2021, 09:48

It looks like my remarks from 2017 are still applicable ...
:D

User avatar
Blaze
DEV Team
DEV Team
Posts: 3118
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus current ☯ all DEs ☯
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

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

Post#9 by Blaze » 14 Feb 2021, 10:57

rych and burdi01, and now this is fixed in the main tree :oops:

Thanks.
Linux 5.10.11-porteus #1 SMP Thu Jan 28 11:33:44 UTC 2021 x86_64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Tobago PRO [Radeon R7 360 / R9 360 OEM] (rev 81) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

rych
Samurai
Samurai
Posts: 176
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 4.0 64 LXDE
Location: NZ

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

Post#10 by rych » 15 Feb 2021, 07:32

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?

User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 2839
Joined: 20 Mar 2012, 03:42
Distribution: 5.0rc1-64bit all-DE+more
Location: australia
Contact:

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

Post#11 by ncmprhnsbl » 15 Feb 2021, 09:28

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..
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

User avatar
Blaze
DEV Team
DEV Team
Posts: 3118
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus current ☯ all DEs ☯
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

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

Post#12 by Blaze » 18 Feb 2021, 18:25

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
Linux 5.10.11-porteus #1 SMP Thu Jan 28 11:33:44 UTC 2021 x86_64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Tobago PRO [Radeon R7 360 / R9 360 OEM] (rev 81) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

Post Reply