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:
[EMAIL PROTECTED] ~]# ./preserve
cfengine::/bin/echo setti: setting a class
[EMAIL PROTECTED] ~]# ./preserve
cfengine::/bin/echo prese: preserved set
[EMAIL PROTECTED] ~]# ./preserve
cfengine::/bin/echo setti: setting a class
But instead I got this:
[EMAIL PROTECTED] ~]# ./preserve
cfengine::/bin/echo setti: setting a class
[EMAIL PROTECTED] ~]# ./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
--- src/parse.c.orig 2005-09-21 21:25:25.182204638 -0400
+++ src/parse.c 2005-09-21 21:25:28.528333570 -0400
@@ -636,7 +636,7 @@
return;
}
-if (!IsDefinedClass(CLASSBUFF))
+if ((ACTION != alerts) && (!IsDefinedClass(CLASSBUFF)))
{
Debug("Function object class was beyond current environment (%s)\n",CLASSBUFF);
return;
_______________________________________________
Bug-cfengine mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-cfengine