[augeas-devel] inittab with a # comments after process values

David Lutterkort lutter at redhat.com
Fri Oct 23 10:41:27 UTC 2009


On Thu, 2009-10-22 at 15:53 +0200, ant+augeas at caetano.za.net wrote:
> David Lutterkort wrote:
> > Shouldn't this be added as a comment on that inittab entry, i.e. so that
> > you get a tree like
> >
> >         /files/etc/inittab/fmc/
> >                                runlevels = "2345"
> >                                action = "respawn"
> >                                process = "/opt/ibm/db2/V9.5/bin/db2fmcd"
> >                                #comment = "DB2 Fault Monitor Coordinator"
> >
> >
> >   
> > Let me know what you think of doing it like above, and I'll either
> > commit your change or one that pulls out the comment separately.
> >   
> Hi David
> 
> I like your suggestion of pulling out the comment separately, but I 
> can't exactly say that I would have a use for it now...  So not a very 
> helpful reply from me :-/

How about this patch:

>From 1cd5868ba2181384e1bbd7ffc042964bdf482b2f Mon Sep 17 00:00:00 2001
From: David Lutterkort <lutter at redhat.com>
Date: Fri, 23 Oct 2009 12:39:12 +0200
Subject: [PATCH] Inittab: parse end-of-line comments into a #comment

---
 lenses/inittab.aug            |    5 ++++-
 lenses/tests/test_inittab.aug |    8 ++++++++
 2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/lenses/inittab.aug b/lenses/inittab.aug
index 86a0dc8..5830e1c 100644
--- a/lenses/inittab.aug
+++ b/lenses/inittab.aug
@@ -12,10 +12,13 @@ module Inittab =
 
    let record =
      let field (name:string) = [ label name . store value ] in
+     let eolcomment =
+       [ label "#comment" . del /#[ \t]*/ "# "
+           . store /([^ \t\n].*[^ \t\n]|[^ \t\n])/ ] in
        [ key id . sep .
            field "runlevels" . sep .
            field "action" . sep .
-           field "process" . eol ]
+           field "process" . eolcomment? . eol ]
 
    let lns = ( comment | record ) *
 
diff --git a/lenses/tests/test_inittab.aug b/lenses/tests/test_inittab.aug
index 61d8d21..bef4c40 100644
--- a/lenses/tests/test_inittab.aug
+++ b/lenses/tests/test_inittab.aug
@@ -39,6 +39,14 @@ l0:0:wait:/etc/rc.d/rc 0
   test Inittab.lns put simple after set "/id/runlevels" "3" =
     "id:3:initdefault:\n"
 
+  test Inittab.lns get
+    "co:2345:respawn:/usr/bin/command # End of line comment\n" =
+    { "co"
+        { "runlevels" = "2345" }
+        { "action" = "respawn" }
+        { "process" = "/usr/bin/command " }
+        { "#comment" = "End of line comment" } }
+
 (* Local Variables: *)
 (* mode: caml       *)
 (* End:             *)
-- 
1.6.2.5






More information about the augeas-devel mailing list