Bug 247934 - shells/bash: profile is not read from LOCALBASE
Summary: shells/bash: profile is not read from LOCALBASE
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Emanuel Haupt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-12 17:05 UTC by Michael Osipov
Modified: 2020-07-16 17:17 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (ehaupt)


Attachments
Using LOCALBASE/etc/profile instead of /etc/profile (621 bytes, patch)
2020-07-15 16:42 UTC, Emanuel Haupt
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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
Note:
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:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247933
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

Log:
  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>

Changes:
  head/UPDATING
  head/shells/bash/Makefile
Comment 8 Emanuel Haupt freebsd_committer 2020-07-16 17:17:13 UTC
Change implemented. Thank you again for your input.