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)
Tue, Nov 12, 1:03 PM
Unknown Object (File)
Mon, Nov 11, 8:36 PM
Unknown Object (File)
Mon, Nov 11, 1:23 PM
Unknown Object (File)
Mon, Nov 11, 10:21 AM
Unknown Object (File)
Mon, Nov 11, 9:47 AM
Unknown Object (File)
Mon, Nov 11, 8:39 AM
Unknown Object (File)
Sun, Nov 10, 9:53 AM
Unknown Object (File)
Sat, Nov 9, 10:42 PM
Subscribers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

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.