help-cfengine
[Top][All Lists]
Advanced

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

interesting variable redefinition problem


From: Luke A. Kanies
Subject: interesting variable redefinition problem
Date: Tue, 31 Dec 2002 17:58:30 -0600 (CST)

Hi Mark,

Is the following intended behaviour:

If I have the following config file:

groups:
   one = ( pixie )
   two = ( pixie )
   three = ( pixie )
   
control:
   AllowRedefinitionOf = ( variable name )
   testcmd = ( "/bin/echo" )
   
   actionsequence = (
      shellcommands.testing
   )
   
   #variable = ( "" )

   one::
      name = ( one )
      variable = ( "${variable}:${name}" )
      #variable = ( "${name}" )
   
   two::
      name = ( two )
      variable = ( "${variable}:${name}" )
      #variable = ( "${name}" )
      
   three::
      name = ( three )
      variable = ( "${variable}:${name}" )
      #variable = ( "${name}" )
   
      
shellcommands:
      
   testing::
      "${testcmd} [$$] ${variable}"

Then I get the following result:

cfengine:pixie:/bin/echo [$$] : [2231] :one:one:two:one:one:two:three
cfengine:pixie:/bin/echo [$$] : [2233] one
cfengine:pixie:/bin/echo [$$] : [2235] two
cfengine:pixie:/bin/echo [$$] : [2237] three

However, if I uncomment the 'variable = ( "" )' line, thus initializing
the variable, I get this:

cfengine:pixie:/bin/echo [$$] : [2245] one
cfengine:pixie:/bin/echo [$$] : [2247] two
cfengine:pixie:/bin/echo [$$] : [2249] three

I spent a bunch of time viewing the debugging, and essentially what is
happening is that the first time cfengine sees the string:

'variable = ( "${variable}:${name}" )'

because '${variable}' is uninitialized, it actually stores the
uninterpolated variable in the value; essentially a symbolic reference, I
guess.

Then, whenever that variable is interpolated through the rest of the file,
it basically gets interpolated twice, because the variable is stored in
itself.

I think this is unintended, because I've never seen this kind of behaviour
before, but I wanted to check.  In some ways more importantly, can I
depend on this behaviour staying the same, or should I definitely avoid
taking advantage of it?

Luke

-- 
Nature and nature's laws lay hid in night,
God said, "Let Newton be," and all was light.

It did not last; the devil howling "Ho!
Let Einstein be!" restored the status quo.




reply via email to

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