/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.
rych
Warlord
Warlord
Posts: 622
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

/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
Shogun
Shogun
Posts: 201
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
Shogun
Shogun
Posts: 201
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
Warlord
Warlord
Posts: 622
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

/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
Shogun
Shogun
Posts: 201
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
Warlord
Warlord
Posts: 622
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

/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
Shogun
Shogun
Posts: 201
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: 3869
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 6.6.11-porteus #1 SMP PREEMPT_DYNAMIC Sun Jan 14 12:07:37 MSK 2024 x86_64 Intel(R) Xeon(R) CPU E3-1270 v6 @ 3.80GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Navi 23 [Radeon RX 6600] [1002:73ff] (rev c7) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

rych
Warlord
Warlord
Posts: 622
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

/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: 3924
Joined: 20 Mar 2012, 03:42
Distribution: v5.0-64bit
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: 3869
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 6.6.11-porteus #1 SMP PREEMPT_DYNAMIC Sun Jan 14 12:07:37 MSK 2024 x86_64 Intel(R) Xeon(R) CPU E3-1270 v6 @ 3.80GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Navi 23 [Radeon RX 6600] [1002:73ff] (rev c7) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

User avatar
skladby
White ninja
White ninja
Posts: 4
Joined: 29 Dec 2020, 16:56
Distribution: 5

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

Post#13 by skladby » 23 Oct 2021, 19:50

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?).

Post Reply