Index: rc =================================================================== RCS file: /cvsroot/src/etc/rc,v retrieving revision 1.175 diff -u -p -r1.175 rc --- rc 8 Sep 2020 16:10:53 -0000 1.175 +++ rc 17 Aug 2026 01:06:06 -0000 @@ -140,19 +140,56 @@ rc_real_work() ) & # - # Get a list of all rc.d scripts, and use rcorder to choose - # what order to execute them. + # Get a list of all rc.d scripts and the order in which to + # execute them. We first use rcorder to select the overall + # total order, and then filter out the scripts that will not + # do any work using the "doeswork" directive. If the script + # does no work, it is elided from the list. This pared down + # list is then cached so subsequent boots can perform fewer + # checks, this improving boot time. The cache is invalidated + # implicitly if any of the $rc_directories or if /etc/rc.conf + # is newer than /etc/rcorder.cache. + # + _rc_update_rcorder_cache=NO + if [ -f /etc/rcorder.cache ]; then + for rcd in ${rc_directories:-/etc/rc.d}; do + if [ ${rcd} -nt /etc/rcorder.cache ]; then + _rc_update_rcorder_cache=YES + fi + done + if [ /etc/rc.conf -nt /etc/rcorder.cache ]; then + _rc_update_rcorder_cache=YES + fi + else + _rc_update_rcorder_cache=YES + fi + + files="" + if [ $_rc_update_rcorder_cache = YES ]; then + echo -n "Updating /etc/rcorder.cache..." + print_rc_metadata "cmd-name:rcorder" + scripts=$(for rcd in ${rc_directories:-/etc/rc.d}; do + test -d ${rcd} && echo ${rcd}/*; + done) + allfiles=$(rcorder -s nostart ${rc_rcorder_flags} ${scripts}) + print_rc_metadata "cmd-status:rcorder:$?" + + for f in $allfiles; do + twiddle + _rc_elem=$f + if run_rc_script $_rc_elem doeswork; then + files="$files $f" + fi + done + echo "done." + else + files=$(cat /etc/rcorder.cache) + fi + # # For testing, allow RC_FILES_OVERRIDE from the environment to # override this. # - print_rc_metadata "cmd-name:rcorder" - scripts=$(for rcd in ${rc_directories:-/etc/rc.d}; do - test -d ${rcd} && echo ${rcd}/*; - done) - files=$(rcorder -s nostart ${rc_rcorder_flags} ${scripts}) - print_rc_metadata "cmd-status:rcorder:$?" - if [ -n "${RC_FILES_OVERRIDE}" ]; then files="${RC_FILES_OVERRIDE}" fi @@ -166,6 +203,14 @@ rc_real_work() print_rc_metadata "cmd-status:$_rc_elem:$?" done + if [ $_rc_update_rcorder_cache = YES ]; then + echo "Saving updated /etc/rcorder.cache." + echo "" > /etc/rcorder.cache + for _rc_elem in $files; do + echo "$_rc_elem" >> /etc/rcorder.cache + done + fi + print_rc_metadata "end:$(date)" exit 0 ) Index: rc.subr =================================================================== RCS file: /cvsroot/src/etc/rc.subr,v retrieving revision 1.111 diff -u -p -r1.111 rc.subr --- rc.subr 22 May 2022 11:27:33 -0000 1.111 +++ rc.subr 17 Aug 2026 01:06:06 -0000 @@ -567,6 +567,11 @@ wait_for_pids() # # rcvar Display what rc.conf variable is used (if any). # +# doeswork Returns 0 if the script does work that's needed +# for boot, non-zero otherwise. Scripts are considered +# to do work if either their rcvar is set to YES or +# if they do not have a defined rcvar. +# # Variables available to methods, and after run_rc_command() has # completed: # @@ -617,7 +622,7 @@ run_rc_command() ;; esac - _keywords="start stop restart rcvar" + _keywords="start stop restart rcvar doeswork" if [ -n "$extra_commands" ]; then _keywords="${_keywords} ${extra_commands}" fi @@ -664,7 +669,8 @@ run_rc_command() # and return if that failed or warn # user and exit when interactive # - if [ -n "${rcvar}" ] && [ "$rc_arg" != "rcvar" ]; then + if [ -n "${rcvar}" ] && [ "$rc_arg" != "rcvar" ] && \ + [ "$rc_arg" != "doeswork" ]; then if ! checkyesno ${rcvar}; then # check whether interactive or not if [ -n "$_run_rc_script" ]; then @@ -902,6 +908,18 @@ $command $rc_flags $command_args" fi ;; + doeswork) + if [ -n "$rcvar" ]; then + if checkyesno ${rcvar}; then + return 0 + else + return 1 + fi + else + return 0 + fi + ;; + *) rc_usage "$_keywords" ;;