Changeset View
Changeset View
Standalone View
Standalone View
libexec/rc/rc.subr
Show First 20 Lines • Show All 986 Lines • ▼ Show 20 Lines | if [ -n "$flags" ]; then # allow override from environment | ||||||||||||
rc_flags=$flags | rc_flags=$flags | ||||||||||||
else | else | ||||||||||||
eval rc_flags=\$${name}_flags | eval rc_flags=\$${name}_flags | ||||||||||||
fi | fi | ||||||||||||
eval _chdir=\$${name}_chdir _chroot=\$${name}_chroot \ | eval _chdir=\$${name}_chdir _chroot=\$${name}_chroot \ | ||||||||||||
_nice=\$${name}_nice _user=\$${name}_user \ | _nice=\$${name}_nice _user=\$${name}_user \ | ||||||||||||
_group=\$${name}_group _groups=\$${name}_groups \ | _group=\$${name}_group _groups=\$${name}_groups \ | ||||||||||||
_fib=\$${name}_fib _env=\$${name}_env \ | _fib=\$${name}_fib _env=\$${name}_env \ | ||||||||||||
_prepend=\$${name}_prepend _login_class=\${${name}_login_class:-daemon} \ | _prepend=\$${name}_prepend _login_class=\${${name}_login_class-daemon} \ | ||||||||||||
allanjude: you dropped a : here. a - is an invalid character in a variable name.
I think you might want… | |||||||||||||
Done Inline ActionsThis is on purpose. This allows us to set name_login_class to an empty string. E.g., sh -c 'unset x; echo "unset and with a colon: ${x:-ok}"' sh -c 'x=""; echo "empty and with a colon: ${x:-ok}"' sh -c 'unset x; echo "unset and without a colon: ${x-ok}"' sh -c 'x=""; echo "empty and without a colon: ${x-ok}"' returns unset and with a colon: ok empty and with a colon: ok unset and without a colon: ok empty and without a colon: 0mp: This is on purpose. This allows us to set name_login_class to an empty string. E.g.,
```
sh -c… | |||||||||||||
_limits=\$${name}_limits _oomprotect=\$${name}_oomprotect \ | _limits=\$${name}_limits _oomprotect=\$${name}_oomprotect \ | ||||||||||||
_env_file=\$${name}_env_file | _env_file=\$${name}_env_file | ||||||||||||
if [ -n "$_env_file" ] && [ -r "${_env_file}" ]; then # load env from file | if [ -n "$_env_file" ] && [ -r "${_env_file}" ]; then # load env from file | ||||||||||||
set -a | set -a | ||||||||||||
. $_env_file | . $_env_file | ||||||||||||
set +a | set +a | ||||||||||||
fi | fi | ||||||||||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | $command $rc_flags $command_args" | ||||||||||||
fi | fi | ||||||||||||
_doit="nice -n $_nice $_doit" | _doit="nice -n $_nice $_doit" | ||||||||||||
fi | fi | ||||||||||||
if [ -n "$_prepend" ]; then | if [ -n "$_prepend" ]; then | ||||||||||||
_doit="$_prepend $_doit" | _doit="$_prepend $_doit" | ||||||||||||
fi | fi | ||||||||||||
fi | fi | ||||||||||||
# Prepend default limits | # prepend default limits | ||||||||||||
_doit="$_cd limits -C $_login_class $_limits $_doit" | # if the login class and/or limits | ||||||||||||
# are provided | |||||||||||||
Done Inline Actions
You could optimize it by shoving both into a single string and testing the results. dteske: You could optimize it by shoving both into a single string and testing the results. | |||||||||||||
Done Inline ActionsHmm, I'm a bit worried that it muddles the code a bit. All speed gains we can get here are greatly appreciated by those running FreeBSD in emulators, however. 0mp: Hmm, I'm a bit worried that it muddles the code a bit. All speed gains we can get here are… | |||||||||||||
# | |||||||||||||
if [ -n "${_login_class}${_limits}" ]; then | |||||||||||||
Done Inline Actions
Alternatively, if you want to be avant-garde about it, you could optimize it further to just adding a single line above it which states "if both login_class and limits are null, skip running limts" (which I think is rather succinct) dteske: Alternatively, if you want to be avant-garde about it, you could optimize it further to just… | |||||||||||||
Done Inline ActionsI think that the if statement is cleaner to readers. 0mp: I think that the if statement is cleaner to readers. | |||||||||||||
_doit="limits ${_login_class:+-C $_login_class} $_limits $_doit" | |||||||||||||
fi | |||||||||||||
# lastly, prepend the directory change | |||||||||||||
# | |||||||||||||
_doit="$_cd $_doit" | |||||||||||||
# run the full command | # run the full command | ||||||||||||
# | # | ||||||||||||
if ! _run_rc_doit "$_doit"; then | if ! _run_rc_doit "$_doit"; then | ||||||||||||
warn "failed to start ${name}" | warn "failed to start ${name}" | ||||||||||||
return 1 | return 1 | ||||||||||||
fi | fi | ||||||||||||
▲ Show 20 Lines • Show All 1,072 Lines • Show Last 20 Lines |
you dropped a : here. a - is an invalid character in a variable name.
I think you might want just: