Download raw body.
rc.subr: hoist OPTIND reset out of service scripts
> * netstart
>
> dot-sources rc.subr, but with FUNCS_ONLY=1, i.e. rc.subr
> exits after function definitions and before getopts usage
> and thus does not effect it.
/etc/rc does the same as netstart and thus not effected.
> 1) dot-sources rc.subr
> 2) rc.subr runs getopts; iff flags are used, OPTIND is >1
> 3) runs rc_*() which may use getopts; if OPTIND is >1,
> daemon_flags is parsed improperly.
> We can simply reset getopts in in 2) instead of 3) such that
> any service script will work properly.
One of the problems with 3) is knowing OPTIND needs to be reset
and any new uses of getopts will have to remember to reset it.
I for one didn't reset OPTIND in my original patch that introduced
getopts in unbound. I had read about it but thought I was safe in a
function, only later I learned not all functions are treated equally.
> Test:
> # mv /var/unbound/etc/{unbound,foo}.conf
> # rcctl enable unbound
> # rcctl set unbound flags -c /var/unbound/etc/foo.conf -p
I re-ran my testing as I did in bugs@ and doing 2) passes my tests.
OK mulh
If I had any concern it would be in the future someone seeing OPTIND=1
in rc.subr, thinking it was spurious and removing it. (Luckily you
don't have me doing audits)
rc.subr: hoist OPTIND reset out of service scripts