chiark / gitweb /
bin/zoneconf: Abstract out command substitution machinery.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 3 Dec 2011 19:26:48 +0000 (19:26 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 3 Dec 2011 19:29:09 +0000 (19:29 +0000)
bin/zoneconf

index 820f62f473322ab2f84e0e6ccf10c551a4e9b159..7ee6d6ab1c655377005ee683b7963eebfb709bb0 100755 (executable)
@@ -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