Closed grahamc closed 4 years ago
xargs <command>
wouldn't be too bad as I already have separate handling for builtins that do similar. I'm on board with the concept and I hope a naive version is simple enough. I'll need to play with injecting a leading statement to set PATH="" (it looks like unsetting it entirely causes which
to exit 1) at runtime to confirm there's a straightforward way to put it in the right place. There are probably quite a few edge cases where this will break down if scripts set/modify path or do certain kinds of environment sanity-checking...
Here's a real-world example. Here's what it does, roughly, with an empty path:
readonly PATH=""
function fixpath(){
local default_path=$(command -p getconf PATH 2>/dev/null)
[[ $default_path ]] || return 1
local original_path=$PATH
export PATH=${default_path}${PATH:+:}${PATH}
[[ :$PATH: == *:/bin:* ]] || PATH=/bin${PATH:+:}$PATH
[[ :$PATH: == *:/usr/bin:* ]] || PATH=/usr/bin${PATH:+:}$PATH
if ! type "${_ble_init_posix_command_list[@]}"; then
PATH=$original_path
fi
}
fixpath
echo path=$PATH # prints path=/usr/bin:/bin:/usr/sbin:/sbin
readonly PATH=""
. It wouldn't cause hard failures by itself, but it would ensure every attempt to fiddle with PATH is at least exposed.$0
to execute differently) that probably shouldn't be resolved or that could waste time without benefit. I guess an alternative is "move fast and break things" but provide a way to explicitly exclude some.Broke these out into separate issues to have a little more room to focus on each. Edited this post down to reflect new locations.
There are some things I would like for it to do:
~1. better support for bash
alias
definitions, where currently it does not handle them at all.~ Finished in #5 ~2. better support for programs which call other programs, likexargs «cmd»
. This one is not a principled solution, but I think an investment in to handling common "higher order" programs like this would pay off well.~ See #6 ~3. development of a "strict mode" where the PATH is unset, to improve the guarantee~ See #9 ~4. have a "traced execution" model where executing specially instrumented "resholved" scripts record any programs executed which are not in their Nix closure. This indicates a scope leak and resolution failure.~ See #9 ~5. a buildInputs setup hook, which automatically resholves all of the outputs of a Nix build.~ See #8what do you think about these things?