help-cfengine
[Top][All Lists]
Advanced

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

Re: DefineClasses help


From: Andrew Stribblehill
Subject: Re: DefineClasses help
Date: Tue, 25 Feb 2003 17:19:23 +0000
User-agent: Mutt/1.5.3i

Quoting Alexander Mattausch <Alexander.Mattausch@physik.uni-erlangen.de> 
(2003-02-25 04:29:44 GMT):
> Andrew Stribblehill schrieb:
> 
> >DefineClasses is defined whenever any part of your file is edited.
> >Mark actually put some test into the editfiles source to stop people
> >getting confused by trying this. The error message is:
> >
> >Class definitions inside conditionals or loops are not allowed
> >
> But there are circumstances under which it is sensible to define a class 
> only if a part of the file has been edited, as in this case. Suse e.g. 
> is now using a similar concept with config files in /etc/sysconfig that 
> may be read by several daemons. Editing such a file means, for example, 
> that all daemons are restarted, although only one would have been 
> necessary. Intuitively I'd put the DefineClasses statement in a 
> BeginGroup/EndGroup, then.

I see what you mean, but that would diverge from the documented
meaning of DefineClasses. The following patch adds an extra keyword,
DefineInGroup, which defines a list (comma, colon or dot separated)
to be defined if the group is entered, regardless of whether any
editing is done within the group.

I haven't patched the documentation.

diff -ruN cfengine-2.0.5-old/src/cf.defs.h cfengine-2.0.5/src/cf.defs.h
--- cfengine-2.0.5-old/src/cf.defs.h    2003-02-15 09:30:51.000000000 +0000
+++ cfengine-2.0.5/src/cf.defs.h        2003-02-25 16:47:14.000000000 +0000
@@ -911,7 +911,8 @@
    EditRepos,
    EditUmask,
    EditUseShell,
-   EditFilter
+   EditFilter,
+   DefineInGroup
    };
 
 enum RegExpTypes
diff -ruN cfengine-2.0.5-old/src/edittools.c cfengine-2.0.5/src/edittools.c
--- cfengine-2.0.5-old/src/edittools.c  2003-02-15 10:14:48.000000000 +0000
+++ cfengine-2.0.5/src/edittools.c      2003-02-25 17:12:25.000000000 +0000
@@ -357,6 +357,7 @@
 { struct Edlist *ep, *loopstart, *loopend, *ThrowAbort();
   struct Item *filestart = NULL, *newlineptr;
   char currenteditscript[bufsize], searchstr[bufsize], expdata[bufsize];
+  char *sp, currentitem[maxvarsize];
   struct stat tmpstat;
   char spliton = ':';
   mode_t maskval;
@@ -459,6 +460,16 @@
                  }
               break;
 
+      case DefineInGroup:
+                  for (sp = expdata; *sp != '\0'; sp++)
+                      {
+                      currentitem[0] = '\0';
+                      sscanf(sp,"%[^,:.]",currentitem);
+                      sp += strlen(currentitem);
+                      AddClassToHeap(currentitem);
+                      }
+                  break;
+               
       case CatchAbort:
                  EditVerbose("Caught Exception\n");
                  break;
diff -ruN cfengine-2.0.5-old/src/globals.c cfengine-2.0.5/src/globals.c
--- cfengine-2.0.5-old/src/globals.c    2003-02-11 20:33:47.000000000 +0000
+++ cfengine-2.0.5/src/globals.c        2003-02-25 16:48:34.000000000 +0000
@@ -886,6 +886,7 @@
      "Umask",
      "UseShell",
      "Filter",
+     "DefineInGroup",
      NULL
      };
 
diff -ruN cfengine-2.0.5-old/src/install.c cfengine-2.0.5/src/install.c
--- cfengine-2.0.5-old/src/install.c    2003-02-16 18:39:21.000000000 +0000
+++ cfengine-2.0.5/src/install.c        2003-02-25 16:51:31.000000000 +0000
@@ -2683,6 +2683,12 @@
                   yyerror("EndLoop without ForEachLineIn");
                   }
                break;
+         case DefineInGroup:
+                if (EDITGROUPLEVEL < 0)
+                   {
+                   yyerror("DefineInGroup outside a group");
+                   }
+                break;
         case SetLine:
                if (FOREACHLEVEL > 0)
                   {

-- 
PLYMOUTH BISCAY
SOUTHEAST 5 TO 7, BECOMING VARIABLE 3 OR 4 IN WEST BISCAY LATER.
RAIN. MAINLY MODERATE




reply via email to

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