UnCommentToLineMatching doesn’t work in cfengine-2.2.8
And — once again — cfengine has wasted part of my life. I’ve never had more trouble with software than I’ve had with cfengine. This time I had to delve into the source code to find the problem, and what I found hilights poor coding and even poorer testing.
Stop me if you’ve heard this one already…
For the life of my I can’t get the following editfiles snippet:
{ /etc/syslog-ng/syslog-ng.conf LocateLineMatching "### Begin Section loghost ###" UnCommentToLineMatching "### End .*" }
To do what I expect on the following bit of syslog-ng.conf:
### Begin Section loghost ### # source s_remote { # tcp(ip(0.0.0.0) port(514)); # udp(ip(0.0.0.0) port(514)); # }; ### End Section loghost ### ### Begin Section loghost_sys ### # destination d_messages_byhost { # file("/var/log/$HOST/messages"); # }; # # log { source(s_remote); destination(d_messages_byhost); }; ### End Section loghost_web ###
I want it to only uncomment the first section. What it does is uncomment the entire rest of the file.
Here’s some interesting debugging output:
Edit action: UnCommentToLineMatching CommentToRegExp(list,# ### End .*) Uncomment line # source s_remote { Uncomment line # tcp(ip(0.0.0.0) port(514)); Uncomment line # udp(ip(0.0.0.0) port(514)); Uncomment line # }; Terminating line: ### End Section loghost ### (Done) Uncomment line # destination d_messages_byhost { Uncomment line # file("/var/log/$HOST/messages"); Uncomment line # }; Uncomment line # Uncomment line # log { source(s_remote); destination(d_messages_byhost); };
It looks like it detects the correct line on which to Terminate, but then Uncomments the rest of the file anyway.
From UnCommentToRegExp() in item-ext.c (line 1282 in cfengine-2.2.8):
for (ip = CURRENTLINEPTR; ip != NULL; ip = CURRENTLINEPTR) { if (ip == ip_end) { EditVerbose("Terminating line: %s (Done)\n",ip->name); done = true; }
“done” is a local variable that is not used anywhere else in UnCommentToRegExp(). Based on the incorrect function name in the Debug2() statement, I take it UnCommentToRegExp() was copied from CommentToRegExp() and the if (done) { break; } was lost somewhere along the way. I attempted to see if this is also the case in cfengine-3.0.0a3, but UnCommentToRegExp() has been removed entirely, it seems.
This also raises a larger question — will cfengine-2.2 be bugfixed after 3.0.0 is released, or will I have to upgrade to 3.0.0 to fix this issue? I certainly don’t want to upgrade to 3.0.0. I’m there’ll be no limit to the number of bugs introduced in that major release.
Leave a Reply