bug-cfengine
[Top][All Lists]
Advanced

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

Alert class bug


From: Jason Kim
Subject: Alert class bug
Date: Wed, 21 Sep 2005 21:56:03 -0400
User-agent: KMail/1.8.1

This one drove me nuts...

This is what I was trying without success (culled from a post in the 
help-cfengine list):

++++++
#!/usr/sbin/cfagent -qKf

control:
    actionsequence = ( shellcommands )

shellcommands:
    !preserved::
        "/bin/echo setting a class"
            define=create_preserved
    preserved::
        "/bin/echo preserved set"
            define=remove_preserved

alerts:
    create_preserved::
        SetState("preserved",999,Preserve)
    remove_preserved::
        UnsetState(preserved)
++++++

The outcome should be this:
address@hidden ~]# ./preserve
cfengine::/bin/echo setti: setting a class
address@hidden ~]# ./preserve
cfengine::/bin/echo prese: preserved set
address@hidden ~]# ./preserve
cfengine::/bin/echo setti: setting a class

But instead I got this:
address@hidden ~]# ./preserve
cfengine::/bin/echo setti: setting a class
address@hidden ~]# ./preserve
cfengine::/bin/echo setti: setting a class

Using AddInstallable didn't help. If I used a plain string instead of 
SetState/UnsetState it would issue an alert as expected.

Much debugging ensued... Apparently, during the parsing stage, when cfengine 
encounters a function it passes it to HandleFunctionObject in parse.c. This 
then calls IsDefinedClass to see if the class the function was parsed in is 
defined. Unfortunately the class isn't defined at parse time because it's set 
by shellcommands, and the list that IsDefinedClass consults apparently 
doesn't contain the AddInstallable classes. No such class check is done if a 
string is used instead of a function.

I've attached a trivial patch that simply ignores the IsDefinedClass check if 
the ACTION being parsed is 'alerts'. I'm not too sure if this is the 'right' 
fix, or if it would be better to make IsDefinedClass check a full list of 
classes including the AddInstallable ones, but since it's a pretty heavily 
used function I left it alone. Anyone who knows better can yell at me though.

-JayKim

Attachment: cfengine_alert_patch
Description: Text Data


reply via email to

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