Page MenuHomeFreeBSD

sh: read more profile files.
ClosedPublic

Authored by des on Sep 9 2022, 1:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sep 22 2024, 6:37 PM
Unknown Object (File)
Sep 19 2024, 3:03 PM
Unknown Object (File)
Sep 18 2024, 7:20 PM
Unknown Object (File)
Sep 18 2024, 3:28 AM
Unknown Object (File)
Sep 17 2024, 8:16 PM
Unknown Object (File)
Sep 15 2024, 5:11 PM
Unknown Object (File)
Sep 15 2024, 7:04 AM
Unknown Object (File)
Sep 9 2024, 7:58 PM
Subscribers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 47406
Build 44293: arc lint + arc unit

Event Timeline

des requested review of this revision.Sep 9 2022, 1:31 PM
jilles requested changes to this revision.Sep 9 2022, 3:02 PM
jilles added inline comments.
bin/sh/profile
16

Please unset this function after use, since it's not useful for the user's environment.

Alternatively, just write the code in line and unset dir and file afterwards.

37

The only purpose I can see for the :- assignment is if the variable went into the environment (preventing indefinite recursion if /etc/profile is copied to /usr/local/etc/profile), but that is not how a variable assignment before a function call works in our sh. (It does work that way in bash and mksh.)

In general, the exact effect of variable assignment before a function call is inconsistent across shells and it would be good to avoid breaking users of strange shells by putting unusual code in /etc/profile.

So if you want to guard against indefinite recursion, the code could be

_loaded=${_loaded:-/etc/profile}
export _loaded # also avoid export name=value syntax
_load_profile /etc /usr/local/etc # or inlined code
unset _loaded
unset -f _load_profile
This revision now requires changes to proceed.Sep 9 2022, 3:02 PM

Oh, the unset obviously defeats the purpose. Defending against someone copying /etc/profile to /usr/local/etc/profile without leaving stray variables in the user's environment is a little harder.

Oh, the unset obviously defeats the purpose. Defending against someone copying /etc/profile to /usr/local/etc/profile without leaving stray variables in the user's environment is a little harder.

I tried to strike a balance between not polluting the environment too much in the common case while still not blowing up too badly if something is wrong but there's no way to get it 100% right. It would be great if we could use local in a non-function block.

des marked 2 inline comments as done.Sep 16 2022, 6:36 AM
This revision is now accepted and ready to land.Sep 27 2022, 8:51 PM
This revision was automatically updated to reflect the committed changes.