Created attachment 145853 [details] patch for /etc/rc.subr "find_local_scripts_old()" If there are no /usr/local/etc/rc.d/*.sh scripts "$zlist" & "$slist" are non-empty upon return: zlist=' /usr/local/etc/rc.d/[0-9]*.sh' slist=' /usr/local/etc/rc.d/[^0-9]*.sh' A patch is attached.
$ ls /usr/local/etc/rc.d/ avahi-daemon* avahi-dnsconfd* cupsd* dbus* git_daemon* poudriered* slim* svnserve* $ source /etc/rc.subr $ find_local_scripts_old Checking variables (which are recognized and autocompleted by the shell) $ echo "+++"$zlist"+++" ++++++ $ echo "+++"$slist"+++" ++++++ Look empty. Closing.
the test you used to test does not include $local_startup in bourne sh: > cd > mkdir x > local_startup=/root/x > . /etc/rc.subr > set +x > find_local_scripts_old + find_local_scripts_old + zlist='' + slist='' + [ -d /root/x ] + grep '^# PROVIDE:' '/root/x/[0-9]*.sh' + zlist=' /root/x/[0-9]*.sh' + grep '^# PROVIDE:' '/root/x/[!0-9]*.sh' + slist=' /root/x/[!0-9]*.sh' This was done on FreeBSD 12.x
You're right, I can confirm. Assigning jilles@ based on git history to see if he can have a look at this.
This "bug" in find_local_scripts_old has existed since it was added in SVN r153027 / git 0f3ce2b32c1dd5e82c838030e87f1f868cf58af9. It may not really be a bug since its caller libexec/rc/rc.subr (installed as /etc/rc.subr) compensates for it. As for a fix, the proposed [ "`echo $f`" != "$f" ] works in this particular case, but I'd say a check [ -f "$file" ] || continue in the loop would be more idiomatic (since it is more common and also works for patterns that match themselves or contain quoted characters).
(In reply to Jilles Tjoelker from comment #4) Does that mean that the patch is good if we use [ -f "$file" ] || continue ? :-)
Looking at it again, I think the original version with [ "`echo $f`" != "$f" ] is better. The code is a bit strangely factored, and /etc/rc.d/localpkg in fact depends on non-executable files and dangling symlinks being included for the " (skipping ${script}, not executable)" message. Only the pattern itself (if it does not match any files) is safe to exclude. The more idiomatic pattern with [ -f "$file" ] || continue (or a similar condition) would apply to loops that perform an actual action rather than just collecting a list to be processed later.
(In reply to Jilles Tjoelker from comment #6) Thanks Jills for looking into this. Will you proceed with the fix? I'm not a src committer, but if you want me to do it, just let me know.
(In reply to Fernando Apesteguía from comment #7) I will take care of it.
(In reply to Jilles Tjoelker from comment #8) Thanks!