From 15483f96207de354714fc61f20cdbf971706e6cb Mon Sep 17 00:00:00 2001 From: "Simon J. Gerraty" Date: Sat, 10 Feb 2024 10:14:23 -0800 Subject: [PATCH] rc.subr avoid noise if /usr not mounted basename, sed and tty are all in /usr/bin and not available until /usr is mounted. basename and tty we can replace with a function, but sed is more important. Fix o_verify to just use shell builtins, and rc_trace should avoid trying to set RC_LEVEL until sed is available. --- libexec/rc/rc.subr | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr index 19955fa83fbdf0..d76f0ba4f9a76d 100644 --- a/libexec/rc/rc.subr +++ b/libexec/rc/rc.subr @@ -82,7 +82,10 @@ _VDOT_SH=: # current state of O_VERIFY o_verify() { - set -o | sed -n '/^verify/s,.*[[:space:]],,p' + case $(echo $(set -o)) in + *verify" "off*) echo off;; + *verify" "on*) echo on;; + esac } ## @@ -174,9 +177,15 @@ rc_trace() if [ -z "$RC_LEVEL" ]; then [ -f $cf ] || return - [ -s $cf ] && \ - RC_LEVEL=$(sed -n '/^RC_LEVEL=/ { s/.*=//p;q; }' $cf) - RC_LEVEL=${RC_LEVEL:-0} + if [ -s $cf ]; then + # don't try to set RC_LEVEL without sed + if [ -x /usr/bin/sed ]; then + RC_LEVEL=$(sed -n '/^RC_LEVEL=/ { s/.*=//p;q; }' $cf) + RC_LEVEL=${RC_LEVEL:-0} + fi + else + RC_LEVEL=0 + fi fi [ ${RC_LEVEL:-0} -ge ${level:-0} ] || return rc_log "$@" @@ -2493,8 +2502,22 @@ fi # Use vdot to ensure the file has not been tampered with. vdot /etc/local.rc.subr -# safe_eval.sh provides safe_dot - for untrusted files -$_SAFE_EVAL_SH vdot /libexec/safe_eval.sh +# Avoid noise - when we do not have /usr mounted, +# and we cannot use safe_dot without sed. +if ! have basename; then + basename() + { + local b=${1%$2} + echo ${b##*/} + } + tty() + { + return 0 + } +else + # safe_eval.sh provides safe_dot - for untrusted files + $_SAFE_EVAL_SH vdot /libexec/safe_eval.sh +fi $_DEBUG_SH vdot /libexec/debug.sh # Ensure we can still operate if debug.sh and