Details
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
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 |
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.