From a97a69293c633be97d05d0b3803f656a2db97d8c Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 3 Dec 2011 19:26:48 +0000 Subject: [PATCH] bin/zoneconf: Abstract out command substitution machinery. --- bin/zoneconf | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/bin/zoneconf b/bin/zoneconf index 820f62f..7ee6d6a 100755 --- a/bin/zoneconf +++ b/bin/zoneconf @@ -1037,6 +1037,17 @@ define-configuration-space toplevel ZONECFG { ###-------------------------------------------------------------------------- ### Processing the results. +proc build-command {command args} { + ## Return the COMMAND list, after applying the string map ARGS to each item + ## in turn. + + set cmd {} + foreach item $command { + lappend cmd [string map $args $item] + } + return $cmd +} + proc zone-file-name {view config} { ## Return the relative file name for the zone described by CONFIG, relative ## to the given VIEW. An absolute filename may be derived later, depending @@ -1297,14 +1308,11 @@ provided by the named USER" } close $chan - set cmd {} - foreach item $zone(checkzone-command) { - lappend cmd [string map [list \ - "%z" $name \ - "%v" $view \ - "%f" $tmp] \ - $item] - } + ## Check the zone for sanity. + set cmd [build-command $zone(checkzone-command) \ + "%z" $name \ + "%v" $view \ + "%f" $tmp] set rc [catch { set out [eval exec $cmd] } msg] @@ -1322,14 +1330,9 @@ provided by the named USER" file rename -force -- $tmp $zone(file-name) set cleanup {} foreach view $matchview { - set cmd {} - foreach item $zone(reload-command) { - lappend cmd [string map [list \ - "%v" $view \ - "%z" $zone(name)] \ - $item] - } - eval exec $cmd + eval exec $cmd [build-command $zone(reload-command) \ + "%v" $view \ + "%z" $zone(name)] } } { eval $cleanup -- 2.11.0