diff options
-rw-r--r-- | etc/rc.subr | 44 | ||||
-rw-r--r-- | share/man/man8/rc.subr.8 | 15 |
2 files changed, 48 insertions, 11 deletions
diff --git a/etc/rc.subr b/etc/rc.subr index 40d8c90..7549cdc 100644 --- a/etc/rc.subr +++ b/etc/rc.subr @@ -1,7 +1,7 @@ -# $NetBSD: rc.subr,v 1.60 2003/07/26 05:13:47 lukem Exp $ +# $NetBSD: rc.subr,v 1.65 2004/10/12 14:45:29 lukem Exp $ # $FreeBSD$ # -# Copyright (c) 1997-2002 The NetBSD Foundation, Inc. +# Copyright (c) 1997-2004 The NetBSD Foundation, Inc. # All rights reserved. # # This code is derived from software contributed to The NetBSD Foundation @@ -39,6 +39,8 @@ # functions used by various rc scripts # +: ${rcvar_manpage:='rc.conf(5)'} + # # Operating System dependent/independent variables # @@ -138,12 +140,13 @@ checkyesno() return 1 ;; *) - warn "\$${1} is not set properly - see rc.conf(5)." + warn "\$${1} is not set properly - see ${rcvar_manpage}." return 1 ;; esac } +# # reverse_list list # print the list in reverse order # @@ -598,7 +601,7 @@ run_rc_command() start) if [ -z "$rc_fast" -a -n "$rc_pid" ]; then - echo "${name} already running? (pid=$rc_pid)." + echo 1>&2 "${name} already running? (pid=$rc_pid)." return 1 fi @@ -612,7 +615,7 @@ run_rc_command() # for _f in $required_vars; do if ! checkyesno $_f; then - warn "\$${_f} is not set." + warn "\$${_f} is not enabled." if [ -z "$rc_force" ]; then return 1 fi @@ -684,10 +687,10 @@ $command $rc_flags $command_args" if [ -z "$rc_pid" ]; then [ -n "$rc_fast" ] && return 0 if [ -n "$pidfile" ]; then - echo \ + echo 1>&2 \ "${name} not running? (check $pidfile)." else - echo "${name} not running?" + echo 1>&2 "${name} not running?" fi return 1 fi @@ -729,10 +732,10 @@ $command $rc_flags $command_args" reload) if [ -z "$rc_pid" ]; then if [ -n "$pidfile" ]; then - echo \ + echo 1>&2 \ "${name} not running? (check $pidfile)." else - echo "${name} not running?" + echo 1>&2 "${name} not running?" fi return 1 fi @@ -854,7 +857,7 @@ run_rc_script() } # -# load_rc_config +# load_rc_config command # Source in the configuration file for a given command. # load_rc_config() @@ -898,6 +901,25 @@ load_rc_config() ;; esac } + +# +# load_rc_config_var cmd var +# Read the rc.conf(5) var for cmd and set in the +# current shell, using load_rc_config in a subshell to prevent +# unwanted side effects from other variable assignments. +# +load_rc_config_var() +{ + if [ $# -ne 2 ]; then + err 3 'USAGE: load_rc_config_var cmd var' + fi + eval $(eval '( + load_rc_config '$1' >/dev/null; + if [ -n "${'$2'}" -o "${'$2'-UNSET}" != "UNSET" ]; then + echo '$2'=\'\''${'$2'}\'\''; + fi + )' ) +} # # rc_usage commands @@ -1065,6 +1087,8 @@ backup_file() fi } +_rc_subr_loaded=: + # make_symlink src link # Make a symbolic link 'link' to src from basedir. If the # directory in which link is to be created does not exist diff --git a/share/man/man8/rc.subr.8 b/share/man/man8/rc.subr.8 index e9c6b49..7fbab14 100644 --- a/share/man/man8/rc.subr.8 +++ b/share/man/man8/rc.subr.8 @@ -36,7 +36,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 22, 2006 +.Dd April 4, 2006 .Dt RC.SUBR 8 .Os .Sh NAME @@ -66,6 +66,8 @@ .It .Ic load_rc_config Ar command .It +.Ic load_rc_config_var Ar command Ar var +.It .Ic mount_critical_filesystems Ar type .It .Ic rc_usage Ar command ... @@ -325,6 +327,17 @@ arguments defined by the calling script, to provide an easy mechanism for an administrator to override the behaviour of a given .Xr rc.d 8 script without requiring the editing of that script. +.It Ic load_rc_config_var Ar command Ar var +Read the +.Xr rc.conf 5 +variable +.Ar var +for +.Ar command +and set in the current shell, using +.Ic load_rc_config +in a sub-shell to prevent unwanted side effects from other variable +assignments. .It Ic mount_critical_filesystems Ar type Go through a list of critical file systems, as found in the |