Bug 247934

Summary: shells/bash: profile is not read from LOCALBASE
Product: Ports & Packages Reporter: Michael Osipov <michael.osipov>
Component: Individual Port(s)Assignee: Emanuel Haupt <ehaupt>
Status: Closed FIXED    
Severity: Affects Some People CC: ltning-freebsd, michael.osipov
Priority: --- Flags: bugzilla: maintainer-feedback? (ehaupt)
Version: Latest   
Hardware: Any   
OS: Any   
Description Flags
Using LOCALBASE/etc/profile instead of /etc/profile none

Description Michael Osipov 2020-07-12 17:05:35 UTC
This is similar to Bug 247933.
pathnames.h defines:
> /* The default login shell startup file. */
> #define SYS_PROFILE "/etc/profile"
This is base, but I would expect to use SYS_PROFILE from LOCALBASE/etc/profile. Especially because /etc/profile is Bourne shell in FreeBSD only. Patch the header file and maybe provide an option to symlink from /etc/profile to LOCALBASE/etc/profile for the ease of migration.
This would cleanly decouple this port from base.
Comment 1 Michael Osipov 2020-07-15 07:32:11 UTC
As metioned, /etc/profile cannot be a Bash script, had this with "source ..." because it is not sh compatible. At best, profile stays in /usr/local/etc only.
Comment 2 Emanuel Haupt freebsd_committer 2020-07-15 14:37:27 UTC
There is a non default ports option for using system wide (SYSBASHRC) configuration in LOCALBASE/etc/bash.bashrc and LOCALBASE/etc/bash.bash_logout.
Comment 3 Michael Osipov 2020-07-15 15:22:13 UTC
This is not what I mean. I am referring to:
> #define SYS_PROFILE "/etc/profile"
From a ports perspective, this should be LOCALBASE/etc/profile.
Comment 4 Emanuel Haupt freebsd_committer 2020-07-15 16:42:01 UTC
Created attachment 216473 [details]
Using LOCALBASE/etc/profile instead of /etc/profile

Got you. Can you try this patch? It worked for me:

$ for i in /etc /usr/local/etc; do printf 'echo "Hello from %s/profile"\n' $i > $i/profile; done
$ bash -l
Hello from /usr/local/etc/profile
Comment 5 Emanuel Haupt freebsd_committer 2020-07-15 16:48:59 UTC
This change requires a mention in ports/UPDATING
Comment 6 Michael Osipov 2020-07-15 18:13:20 UTC
(In reply to Emanuel Haupt from comment #5)

Works for me:
219 openat(AT_FDCWD,"/usr/local/etc/profile",O_RDONLY,00) ERR#2 'No such file or directory'
220 openat(AT_FDCWD,"/root/.bash_profile",O_RDONLY,00) ERR#2 'No such file or directory'
221 openat(AT_FDCWD,"/root/.bash_login",O_RDONLY,00) ERR#2 'No such file or directory'
222 openat(AT_FDCWD,"/root/.profile",O_RDONLY,00)    ERR#2 'No such file or directory'

Not that readline suffers from the same issue:
Comment 7 commit-hook freebsd_committer 2020-07-16 17:15:13 UTC
A commit references this bug:

Author: ehaupt
Date: Thu Jul 16 17:14:53 UTC 2020
New revision: 542373
URL: https://svnweb.freebsd.org/changeset/ports/542373

  Cleanly decouple bash from base by reading `profile` from $LOCALBASE/etc/
  instead of from /etc.

  Document this change in UPDATING and provide a migration strategy.

  PR:		247934 (based on)
  Submitted by:	Michael Osipov <michael.osipov@siemens.com>

Comment 8 Emanuel Haupt freebsd_committer 2020-07-16 17:17:13 UTC
Change implemented. Thank you again for your input.
Comment 9 Eirik Oeverby 2020-09-24 07:47:39 UTC

this information needs to go into pkg-message or somesuch - those of us who use packages will never see UPDATING and this caused headscratching across our user base.

I'm not arguing against the change - it makes sense - but I've always thought of a drop-in replacement for sh for interactive use, and given the heritage always expected (and got used to) it to read /etc/profile in the same way. Had I been here earlier, I'd have joined the bikeshedding with "Also, a two-stage change might have made sense, with the default initially being old behavior". Alas, too late now.

My 2 cents.

Comment 10 Michael Osipov 2020-09-24 08:12:37 UTC
(In reply to Eirik Oeverby from comment #9)

a pkg message makes sense, but the /etc/profile heritage is a GNU one, not a BSD one as far as I remember.