help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

line counting bug in editfiles, 2.0.8p1


From: Jamie Wilkinson
Subject: line counting bug in editfiles, 2.0.8p1
Date: Fri, 20 Feb 2004 12:36:29 +1100
User-agent: Mutt/1.5.5.1+cvs20040105i

So I have these nifty M4 macros that generate some common editfiles
scripts for me, which I've posted to this list recently, one of them
looks like this:

CF_EDITFILES_INTERFACE(eth0:01, 202.4.235.120, 255.255.255.192, [rt.engineroom])

which generates this beautiful editfiles script:

# rt.engineroom
{ /etc/sysconfig/network-scripts/ifcfg-eth0:01
        Backup 'off'
        AutoCreate
         
BeginGroupIfNoLineMatching '^DEVICE=.*'
        Append 'DEVICE='
EndGroup
ResetSearch 1
LocateLineMatching '^DEVICE=.*'
BeginGroupIfNoMatch '^DEVICE=eth0:01$'
        ReplaceLineWith 'DEVICE=eth0:01'
EndGroup
ResetSearch 1
                                                                                
BeginGroupIfNoLineMatching '^BOOTPROTO=.*'
        Append 'BOOTPROTO='
EndGroup
ResetSearch 1
LocateLineMatching '^BOOTPROTO=.*'
BeginGroupIfNoMatch '^BOOTPROTO=static$'
        ReplaceLineWith 'BOOTPROTO=static'
EndGroup
ResetSearch 1
     
BeginGroupIfNoLineMatching '^ONBOOT=.*'
        Append 'ONBOOT='
EndGroup
ResetSearch 1
LocateLineMatching '^ONBOOT=.*'
BeginGroupIfNoMatch '^ONBOOT=yes$'
        ReplaceLineWith 'ONBOOT=yes'
EndGroup
ResetSearch 1
     
BeginGroupIfNoLineMatching '^IPADDR=.*'
        Append 'IPADDR='
EndGroup
ResetSearch 1
LocateLineMatching '^IPADDR=.*'
BeginGroupIfNoMatch '^IPADDR=202.4.235.120$'
        ReplaceLineWith 'IPADDR=202.4.235.120'
EndGroup
ResetSearch 1
     
BeginGroupIfNoLineMatching '^NETMASK=.*'
        Append 'NETMASK='
EndGroup
ResetSearch 1
LocateLineMatching '^NETMASK=.*'
BeginGroupIfNoMatch '^NETMASK=255.255.255.192$'
        ReplaceLineWith 'NETMASK=255.255.255.192'
EndGroup
ResetSearch 1
        DeleteLinesMatching '^GATEWAY=.*'
        DefineClasses 'eth0_restart'
}

which is (as I've described previously) making sure each of the keys
exist and setting them to the correct value in turn.

The file in question looks like this (line numbers added):

  1  DEVICE=eth0:01
  2  ONBOOT=yes
  3  BOOTPROTO=static
  4  IPADDR=202.4.235.120
  5  NETMASK=255.255.255.192

and this editfiles script behaves correctly and convergently on it.  All
is good.

But I'm not keen on rolling out this to modify interface definitions on
live machines and risk having the network die on them due to some error,
so I'm taking pains to ensure that an all-talk-and-no-action run does
the right thing first:

Begin editing /etc/sysconfig/network-scripts/ifcfg-eth0:01
Edit: Search ended at line 1
Edit: (Found DEVICE=eth0:01)
(Begin Group - skipping ^DEVICE=.*)
Edit: Search ended at line 1
Edit: (Found DEVICE=eth0:01)
(Begin Group - skipping ^DEVICE=eth0:01$)
Edit: Search ended at line 3
Edit: (Found BOOTPROTO=static)
(Begin Group - skipping ^BOOTPROTO=.*)
Edit: Search ended at line 3
Edit: (Found BOOTPROTO=static)
(Begin Group - skipping ^BOOTPROTO=static$)
Edit: Search ended at line 4
Edit: (Found ONBOOT=yes)
(Begin Group - skipping ^ONBOOT=.*)
Edit: Search ended at line 4
Edit: (Found ONBOOT=yes)
(Begin Group - skipping ^ONBOOT=yes$)
Edit: Search ended at line 7
Edit: (Found IPADDR=202.4.235.120)
(Begin Group - skipping ^IPADDR=.*)
Edit: Search ended at line 7
Edit: (Found IPADDR=202.4.235.120)
(Begin Group - skipping ^IPADDR=202.4.235.120$)
Edit: Search ended at line 11
Edit: (Found NETMASK=255.255.255.192)
(Begin Group - skipping ^NETMASK=.*)
Edit: Search ended at line 11
Edit: (Found NETMASK=255.255.255.192)
(Begin Group - skipping ^NETMASK=255.255.255.192$)
End editing /etc/sysconfig/network-scripts/ifcfg-eth0:01

Everything looks right; but on closer inspection the line numbers don't
match... line 7?  11?  The file is 5 lines long!

At each increment of the line number, the script has performed a
ResetSearch to jump to the top and commence the next search.  However it
looks like the line number pointer isn't being reset, and so when the
next search occurs the counter is just accumulating line offsets from
the start of the file... now of course it's easy to work out what line
cfengine actually means; one merely needs to take the differences
between this line and the previously reported line number, using 0 for
the terminating case, and add 1 to get the actual line number; but I
humbly propose that cfengine is not using an ornate number system
and instead contains a bug.

The version in question is 2.0.8p1 on a Red Hat 9 system.  Apologies for
the verbosity if this is in fact fixed in 2.1.x :-)

-- 
jaq@spacepants.org                           http://spacepants.org/jaq.gpg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]