Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src * Implement



details:   https://anonhg.NetBSD.org/src/rev/bd500c46059f
branches:  trunk
changeset: 570471:bd500c46059f
user:      lukem <lukem%NetBSD.org@localhost>
date:      Tue Oct 12 14:45:29 2004 +0000

description:
* Implement
        load_rc_config_var cmd var
  to load the rc.conf(5) configuration for cmd and set var in the
  current shell, using 'load_rc_config var' in a sub-shell to avoid
  unwanted side-effects.

* Improve required_vars warning message.

diffstat:

 etc/rc.subr              |  27 +++++++++++++++++++++++----
 share/man/man8/rc.subr.8 |  21 ++++++++++++++++++---
 2 files changed, 41 insertions(+), 7 deletions(-)

diffs (119 lines):

diff -r 26b8a97c9b85 -r bd500c46059f etc/rc.subr
--- a/etc/rc.subr       Tue Oct 12 14:42:08 2004 +0000
+++ b/etc/rc.subr       Tue Oct 12 14:45:29 2004 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: rc.subr,v 1.64 2004/08/13 18:08:03 mycroft Exp $
+# $NetBSD: rc.subr,v 1.65 2004/10/12 14:45:29 lukem Exp $
 #
-# 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
@@ -70,6 +70,7 @@
        esac
 }
 
+#
 # reverse_list list
 #      print the list in reverse order
 #
@@ -517,7 +518,7 @@
                                        #
                        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
@@ -731,7 +732,7 @@
 }
 
 #
-# load_rc_config
+# load_rc_config command
 #      Source in the configuration file for a given command.
 #
 load_rc_config()
@@ -752,6 +753,24 @@
        fi
 }
 
+#
+# 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
diff -r 26b8a97c9b85 -r bd500c46059f share/man/man8/rc.subr.8
--- a/share/man/man8/rc.subr.8  Tue Oct 12 14:42:08 2004 +0000
+++ b/share/man/man8/rc.subr.8  Tue Oct 12 14:45:29 2004 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: rc.subr.8,v 1.15 2004/04/29 22:44:43 gendalia Exp $
+.\"    $NetBSD: rc.subr.8,v 1.16 2004/10/12 14:45:29 lukem Exp $
 .\"
 .\" Copyright (c) 2002-2004 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -34,7 +34,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 2, 2004
+.Dd October 12, 2004
 .Dt RC.SUBR 8
 .Os
 .Sh NAME
@@ -57,6 +57,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 Op Ar ...
@@ -226,7 +228,9 @@
 and then
 .Ar message .
 .It Ic load_rc_config Ar command
-Source in the configuration files for
+Source in the
+.Xr rc.conf 5
+configuration files for
 .Ar command .
 First,
 .Pa /etc/rc.conf
@@ -240,6 +244,17 @@
 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



Home | Main Index | Thread Index | Old Index