Why are hotplug and uci-defaults scripts sourced?

In the case of both hotplug and uci-defaults, the scripts are sourced, rather than invoked as stand-alone programs. Does it have to be this way?

I find the current state of affairs to suffer from two problems:

  1. Only shell scripts (as opposed to Lua, ucode, binaries, etc) can be used in hotplug and uci-defaults.
  2. The hotplug scripts inherit the arguments that were used to invoke hotplug-call. Thus, a hotplug script in the "mount" category will have $1 set to mount. This gets in the way for scripts that, in addition to be used as hotplug scripts, can be called with arguments.

For my own use in the uci-defaults case, I have modified the source code to invoke as stand-alone programs those files that have their executable bits set, and fall back to sourcing the remaining files.

That is, changing this:

( . "./$(basename $file)" ) && rm -f "$file"

To this:

if [ -x "$file" ]; then
    ./"$file"
else
    ( . "./$(basename $file)" )
fi && rm -f "$file"

None of the existing hotplug or uci-defaults scripts seem to have the executable bit set, so this works nicely. Is this solution something that I should propose in a pull-request, or am I missing some problem with it?

2 Likes