[augeas-devel] Betterer inittab lens
Matt Palmer
matt at anchor.net.au
Tue Jun 16 00:28:21 UTC 2009
I don't know if the original inittab lens handled blank lines, but my
previous attempts at improvement sure didn't. Here's a replacement for my
previous patch, which tests for and handles empty space in inittabs.
diff --git a/lenses/inittab.aug b/lenses/inittab.aug
index 0aa7baf..a4357aa 100644
--- a/lenses/inittab.aug
+++ b/lenses/inittab.aug
@@ -5,20 +5,20 @@ 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 ) *
+ let lns = ( comment | record | Util.empty ) *
let xfm = transform lns (incl "/etc/inittab")
diff --git a/lenses/tests/test_inittab.aug b/lenses/tests/test_inittab.aug
index 6ac4ce3..4c80f52 100644
--- a/lenses/tests/test_inittab.aug
+++ b/lenses/tests/test_inittab.aug
@@ -5,34 +5,38 @@ module Test_inittab =
let inittab = "id:5:initdefault:
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
+
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
+
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