[augeas-devel] Enhanced inittab lens

Matt Palmer matt at anchor.net.au
Fri Jun 12 04:49:32 UTC 2009


The existing structure of the inittab lens:

1/
1/id = "sa"
1/runlevels = "12345"
1/process = "whatever"

Seems a bit... perverse.  The id is guaranteed to be unique, and is a
fantastic way to key your records.

The following patch makes the inittab lens do this.  Unfortunately, the end
result is not backwards compatible with the current implementation, because
you can't have the same value in two places in the tree representation.  I
do believe, however, that this new tree structure is far more workable than
the old version.

Oh, I also fixed up the comment stuff so that it's more standardised, and
actually puts the contents of comments in the tree.  Much betterer.

diff --git a/lenses/inittab.aug b/lenses/inittab.aug
index 0aa7baf..82705a7 100644
--- a/lenses/inittab.aug
+++ b/lenses/inittab.aug
@@ -5,17 +5,17 @@ module Inittab =
    let sep = Util.del_str ":"
    let eol = Util.del_str "\n"
 
+   let id = /[^\/#:\n]{1,4}/
    let value = /[^#:\n]*/
 
-   let comment = [ del /[ \t]*(#.*)?\n/ "# \n" ]
+   let comment = Util.comment
 
    let field (name:string) = [ label name . store value ]
-   let record = [ seq "record" .
-                    field("id") . sep .
-                    field("runlevels") . sep .
-                    field("action") . sep .
-                    field("process") .
-                    eol
+   let record = [ key id . sep .
+                  field("runlevels") . sep .
+                  field("action") . sep .
+                  field("process") .
+                  eol
                 ]
 
    let lns = ( comment | record ) *
diff --git a/lenses/tests/test_inittab.aug b/lenses/tests/test_inittab.aug
index 6ac4ce3..22fdb23 100644
--- a/lenses/tests/test_inittab.aug
+++ b/lenses/tests/test_inittab.aug
@@ -11,28 +11,28 @@ l0:0:wait:/etc/rc.d/rc 0
 "
 
  test Inittab.lns get inittab =
-    { "1" { "id" = "id" }
+    { "id"
           { "runlevels" = "5" }
           { "action" = "initdefault" }
           { "process" = "" } }
-    {}
-    { "2" { "id" = "si" }
+    { "#comment" = "System initialization." }
+    { "si"
           { "runlevels" = "" }
           { "action" = "sysinit" }
           { "process" = "/etc/rc.d/rc.sysinit" } }
-    {}
-    { "3" { "id" = "ca" }
+    { "#comment" = "Trap CTRL-ALT-DELETE" }
+    { "ca"
           { "runlevels" = "" }
           { "action" = "ctrlaltdel" }
           { "process" = "/sbin/shutdown -t3 -r now" } }
-    { "4" { "id" = "l0" }
+    { "l0"
           { "runlevels" = "0" }
           { "action" = "wait" }
           { "process" = "/etc/rc.d/rc 0" } }
 
-  test Inittab.lns put simple after rm "/1/process" = *
+  test Inittab.lns put simple after rm "/id/process" = *
 
-  test Inittab.lns put simple after set "/1/runlevels" "3" =
+  test Inittab.lns put simple after set "/id/runlevels" "3" =
     "id:3:initdefault:\n"
 
 (* Local Variables: *)



-- 
Matt Palmer - Systems Administrator

A view into the Anchor Engineroom: http://anchor.com.au/blog/
Web Hosting Knowledgebase: http://anchor.com.au/wiki/

Anchor Systems Pty Ltd - Hosting Heavyweights
W: http://www.anchor.com.u - E: support at anchor.com.au
Phone: 1300 883 979 - Fax: 02 8296 5199




More information about the augeas-devel mailing list