Skip to content

Commit

Permalink
rc.subr avoid noise if /usr not mounted
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sgerraty committed Feb 10, 2024
1 parent 61cc483 commit 15483f9
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions libexec/rc/rc.subr
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

##
Expand Down Expand Up @@ -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 "$@"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 15483f9

Please sign in to comment.