Changeset View
Standalone View
sbin/init/rc.subr
Show First 20 Lines • Show All 916 Lines • ▼ Show 20 Lines | quiet*) # "quiet" prefix; omit some messages | ||||
rc_arg=${rc_arg#${_rc_prefix}} | rc_arg=${rc_arg#${_rc_prefix}} | ||||
rc_quiet=yes | rc_quiet=yes | ||||
;; | ;; | ||||
esac | esac | ||||
eval _override_command=\$${name}_program | eval _override_command=\$${name}_program | ||||
command=${_override_command:-$command} | command=${_override_command:-$command} | ||||
_keywords="start stop restart rcvar enabled describe extracommands $extra_commands" | _keywords="start stop restart rcvar enable disable delete enabled describe extracommands $extra_commands" | ||||
dteske: I would think "rcdelete" should just be "delete".
The action is being passed to the "service"… | |||||
rc_pid= | rc_pid= | ||||
_pidcmd= | _pidcmd= | ||||
_procname=${procname:-${command}} | _procname=${procname:-${command}} | ||||
# setup pid check command | # setup pid check command | ||||
if [ -n "$_procname" ]; then | if [ -n "$_procname" ]; then | ||||
if [ -n "$pidfile" ]; then | if [ -n "$pidfile" ]; then | ||||
_pidcmd='rc_pid=$(check_pidfile '"$pidfile $_procname $command_interpreter"')' | _pidcmd='rc_pid=$(check_pidfile '"$pidfile $_procname $command_interpreter"')' | ||||
Show All 38 Lines | run_rc_command() | ||||
fi | fi | ||||
[ -z "$autoboot" ] && eval $_pidcmd # determine the pid if necessary | [ -z "$autoboot" ] && eval $_pidcmd # determine the pid if necessary | ||||
for _elem in $_keywords; do | for _elem in $_keywords; do | ||||
if [ "$_elem" != "$rc_arg" ]; then | if [ "$_elem" != "$rc_arg" ]; then | ||||
continue | continue | ||||
fi | fi | ||||
# if ${rcvar} is set, $1 is not "rcvar" and not "describe" | # if ${rcvar} is set, $1 is not "rcvar", "describe", | ||||
# and ${rc_pid} is not set, then run | # "enable" or "delete", and ${rc_pid} is not set, run: | ||||
# checkyesno ${rcvar} | # checkyesno ${rcvar} | ||||
# and return if that failed | # and return if that failed | ||||
# | # | ||||
if [ -n "${rcvar}" -a "$rc_arg" != "rcvar" -a "$rc_arg" != "stop" \ | if [ -n "${rcvar}" -a "$rc_arg" != "rcvar" -a "$rc_arg" != "stop" \ | ||||
-a "$rc_arg" != "delete" -a "$rc_arg" != "enable" \ | |||||
-a "$rc_arg" != "describe" ] || | -a "$rc_arg" != "describe" ] || | ||||
[ -n "${rcvar}" -a "$rc_arg" = "stop" -a -z "${rc_pid}" ]; then | [ -n "${rcvar}" -a "$rc_arg" = "stop" -a -z "${rc_pid}" ]; then | ||||
if ! checkyesno ${rcvar}; then | if ! checkyesno ${rcvar}; then | ||||
if [ -n "${rc_quiet}" ]; then | if [ -n "${rc_quiet}" ]; then | ||||
return 0 | return 0 | ||||
fi | fi | ||||
echo -n "Cannot '${rc_arg}' $name. Set ${rcvar} to " | echo -n "Cannot '${rc_arg}' $name. Set ${rcvar} to " | ||||
echo -n "YES in /etc/rc.conf or use 'one${rc_arg}' " | echo -n "YES in /etc/rc.conf or use 'one${rc_arg}' " | ||||
echo "instead of '${rc_arg}'." | echo "instead of '${rc_arg}'." | ||||
return 0 | return 0 | ||||
fi | fi | ||||
fi | fi | ||||
if [ $rc_arg = "start" -a -z "$rc_fast" -a -n "$rc_pid" ]; then | if [ $rc_arg = "start" -a -z "$rc_fast" -a -n "$rc_pid" ]; then | ||||
if [ -z "$rc_quiet" ]; then | if [ -z "$rc_quiet" ]; then | ||||
echo 1>&2 "${name} already running? " \ | echo 1>&2 "${name} already running? " \ | ||||
"(pid=$rc_pid)." | "(pid=$rc_pid)." | ||||
fi | fi | ||||
return 1 | return 1 | ||||
fi | fi | ||||
# if there's a custom ${XXX_cmd}, | # if there's a custom ${XXX_cmd}, | ||||
# run that instead of the default | # run that instead of the default | ||||
# | # | ||||
eval _cmd=\$${rc_arg}_cmd \ | eval _cmd=\$${rc_arg}_cmd \ | ||||
_precmd=\$${rc_arg}_precmd \ | _precmd=\$${rc_arg}_precmd \ | ||||
_postcmd=\$${rc_arg}_postcmd | _postcmd=\$${rc_arg}_postcmd | ||||
Not Done Inline ActionsThis code is incorrect. It neglects /etc/rc.conf.local, /usr/local/etc/rc.conf, and /usr/local/etc/rc.conf.d. It also ignores the -s name argument to sysrc to enable *proper* access to rc.conf.d. This code segment is a blocker. dteske: This code is incorrect. It neglects /etc/rc.conf.local, /usr/local/etc/rc.conf, and… | |||||
if [ -n "$_cmd" ]; then | if [ -n "$_cmd" ]; then | ||||
_run_rc_precmd || return 1 | _run_rc_precmd || return 1 | ||||
_run_rc_doit "$_cmd $rc_extra_args" || return 1 | _run_rc_doit "$_cmd $rc_extra_args" || return 1 | ||||
_run_rc_postcmd | _run_rc_postcmd | ||||
return $_return | return $_return | ||||
fi | fi | ||||
case "$rc_arg" in # default operations... | case "$rc_arg" in # default operations... | ||||
describe) | describe) | ||||
if [ -n "$desc" ]; then | if [ -n "$desc" ]; then | ||||
echo "$desc" | echo "$desc" | ||||
fi | fi | ||||
;; | ;; | ||||
extracommands) | extracommands) | ||||
echo "$extra_commands" | echo "$extra_commands" | ||||
;; | |||||
enable) | |||||
_out=$(/usr/sbin/sysrc -vs "$name" "$rcvar=YES") && | |||||
echo "$name enabled in ${_out%%:*}" | |||||
Not Done Inline ActionsCombine these two lines. For example, the current stanza: /usr/sbin/sysrc "$rcvar=YES" > /dev/null [ $? -eq 0 ] && Becomes: /usr/sbin/sysrc "$rcvar=YES" > /dev/null && dteske: Combine these two lines. For example, the current stanza:
```
/usr/sbin/sysrc "$rcvar=YES" >… | |||||
;; | |||||
Not Done Inline ActionsDon't hard-code /etc/rc.conf. If you use the -v flag to sysrc it tells you which file it made the change in. You would have to capture the output and parse the value. For example, say sshd_enable=YES is in /etc/rc.conf.local: dteske@vm11 ~ $ cat /etc/rc.conf.local foo="1" dteske@vm11 ~ $ sr sysrc -v foo=2 /etc/rc.conf.local: foo: 1 -> 2 dteske@vm11 ~ $ cat /etc/rc.conf.local foo="2" An example of capturing the output would be: output=$( /usr/sbin/sysrc "$rcvar=NO" ) && echo "$name disabled in ${output%%:*}" Though, while we're here, it's worth noting that since the first argument starts with a variable, you should add "--" as an option terminator to make it clear, even if the supplied $rcvar value starts with "-", that the argument is an assignment operation and not an option flag. For example: output=$( /usr/sbin/sysrc -- "$rcvar=NO" ) && echo "$name disabled in ${output%%:*}" dteske: Don't hard-code /etc/rc.conf. If you use the `-v` flag to sysrc it tells you which file it made… | |||||
disable) | |||||
_out=$(/usr/sbin/sysrc -vs "$name" "$rcvar=NO") && | |||||
echo "$name disabled in ${_out%%:*}" | |||||
;; | |||||
Not Done Inline ActionsSee notes on lines 1043-1045 dteske: See notes on lines 1043-1045 | |||||
delete) | |||||
_files= | |||||
for _file in $(sysrc -lEs "$name"); do | |||||
_out=$(sysrc -Fif $_file "$rcvar") && _files="$_files $_file" | |||||
done | |||||
/usr/sbin/sysrc -x "$rcvar" && echo "$rcvar deleted in ${_files# }" | |||||
# delete file in rc.conf.d if desired and empty. | |||||
Not Done Inline ActionsI will fix sysrc after head-thaw (Sep 23, 2018). You can remove this comment. PR welcome if we need a reminder to revisit it after commits are open on head again. dteske: I will fix sysrc after head-thaw (Sep 23, 2018). You can remove this comment. PR welcome if we… | |||||
Not Done Inline ActionsAlready fixed under 11.2. dteske@vm11 init $ uname -spr FreeBSD 11.2-STABLE amd64 dteske@vm11 init $ sudo sysrc -x foogribble [sudo] Password: sysrc: unknown variable 'foogribble' dteske@vm11 init $ echo $? 1 In the code (usr.sbin/bsdconfig/share/sysrc.subr): ... # This function is a two-parter. Below is the awk(1) portion of the function, # afterward is the sh(1) function which utilizes the below awk script. # f_sysrc_delete_awk=' # Variables that should be defined on the invocation line: # -v varname="varname" # BEGIN { regex = "^[[:space:]]*"varname"=" found = 0 } { if ( $0 ~ regex ) found = 1 else print } END { exit ! found } ' ... Emphasis on the exit !found dteske: Already fixed under 11.2.
```
dteske@vm11 init $ uname -spr
FreeBSD 11.2-STABLE amd64… | |||||
checkyesno service_delete_empty || _files= | |||||
for _file in $_files; do | |||||
Not Done Inline ActionsSee notes on lines 1043-1045 dteske: See notes on lines 1043-1045 | |||||
[ "$_file" = "${_file#*/rc.conf.d/}" ] && continue | |||||
[ $(/usr/bin/stat -f%z $_file) -gt 0 ] && continue | |||||
/bin/rm "$_file" && echo "Empty file $_file removed" | |||||
done | |||||
;; | ;; | ||||
Not Done Inline ActionsSee notes on lines 1043-1045 dteske: See notes on lines 1043-1045 | |||||
status) | status) | ||||
_run_rc_precmd || return 1 | _run_rc_precmd || return 1 | ||||
if [ -n "$rc_pid" ]; then | if [ -n "$rc_pid" ]; then | ||||
echo "${name} is running as pid $rc_pid." | echo "${name} is running as pid $rc_pid." | ||||
else | else | ||||
echo "${name} is not running." | echo "${name} is not running." | ||||
Not Done Inline ActionsSee notes on lines 1043-1045 dteske: See notes on lines 1043-1045 | |||||
return 1 | return 1 | ||||
fi | fi | ||||
_run_rc_postcmd | _run_rc_postcmd | ||||
Not Done Inline ActionsI just noticed that enable, disable, and rcdelete are duplicated in the same case statement. The first matching pattern in a case statement is the one executed and thus the later [duplicate] patterns will not fire. For example: case foo in foo) echo 1;; foo) echo 2 esac Results in "1", dteske: I just noticed that enable, disable, and rcdelete are duplicated in the same case statement. | |||||
;; | ;; | ||||
start) | start) | ||||
if [ ! -x "${_chroot}${_chroot:+/}${command}" ]; then | if [ ! -x "${_chroot}${_chroot:+/}${command}" ]; then | ||||
warn "run_rc_command: cannot run $command" | warn "run_rc_command: cannot run $command" | ||||
return 1 | return 1 | ||||
fi | fi | ||||
▲ Show 20 Lines • Show All 1,090 Lines • Show Last 20 Lines |
I would think "rcdelete" should just be "delete".
The action is being passed to the "service" utility and it should be obvious that you're not deleting software off disk (which would be the job of "pkg", not "service").
Drawing a comparison to Linux, admins are taught to use "chkconfig" to manage the runlevels. Well FreeBSD has neither runlevels nor chkconfig (they simply don't apply), and instead we have here a patch that makes FreeBSD "service" like a Linux "service" and "chkconfig" combined. I like this idea. It's a good idea. However, for consistency, I would think "delete" would be fine and you can remove the "rc" prefix as it looks out of place.