help-cfengine
[Top][All Lists]
Advanced

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

Re: macros from modules set too late?


From: Adrian Phillips
Subject: Re: macros from modules set too late?
Date: 01 Feb 2002 08:17:27 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1

>>>>> "Martin" == Martin Andrews <address@hidden> writes:

    Martin> I am trying to use a module to define macro values in
    Martin> cfengine-2.0.a16 and I cannot get them to take affect.

    Martin> Here is an example config: -------- control:
    Martin> actionsequence = ( module:environ copy ) # HOST_SHORT = (
    Martin> tbd ) # HOST_SHORT = ( foo ) moduledirectory = (
    Martin> "$(CFINPUTS)/scripts" ) domain = ( dev.netgenics.com )

    Martin> copy: /bin/sh dest=/tmp/$(HOST_SHORT) --------

    Martin> Here is the module: -------- #!/bin/sh echo
    Martin> "=HOST_SHORT=`hostname | sed 's/\..*//'`" --------

    Martin> Running cfagent I get:

    Martin>     cfengine: Need to link files /tmp/${HOST_SHORT} ->
    Martin> ./bash

    Martin> If I uncomment the hardcoded values for HOST_SHORT I get:

    Martin>     cfengine:dhcp8::17: Warning: Redefinition of macro
    Martin> HOST_SHORT=dhcp8 cfengine: Need to link files /tmp/foo ->
    Martin> ./bash

I sent the fllowing patch in for 1.6.3 to fix this behaviour (if 'm
not mistaken, haven't had coffee yet), but I haven't started looking
at 2.0 yet. Have a look at it and compare with 2.0 to see if its
needed.

Sincerely,

Adrian Phillips

diff -urN cfengine-1.6.3.orig/src/do.c cfengine-1.6.3/src/do.c
--- cfengine-1.3.6/src/do.c     Fri Jun  8 18:32:17 2001
+++ cfengine-1.3.6.new/src/do.c Wed Aug  1 10:43:41 2001
@@ -2046,19 +2046,22 @@
 { struct Image *ip;
   struct Item *svp;
   struct stat statbuf;
-  struct servent *server;
+  struct servent *serverent;
   int savesilent;
+  char path[bufsize];
+  char destination[bufsize];
+  char server[bufsize];
 
 Banner("Checking file images:");

-if ((server = getservbyname(CFENGINE_SERVICE,"tcp")) == NULL)
+if ((serverent = getservbyname(CFENGINE_SERVICE,"tcp")) == NULL)
    {
    CfLog(cfverbose,"Remember to register cfengine in /etc/services: cfengine 
5308/tcp\n","getservbyname");
    PORTNUMBER = htons((unsigned short)5308);
    }
 else
    {
-   PORTNUMBER = (unsigned short)(server->s_port); /* already in network order 
*/
+   PORTNUMBER = (unsigned short)(serverent->s_port); /* already in network 
order */
    }
  
 for (svp = VSERVERLIST; svp != NULL; svp=svp->next) /* order servers */
@@ -2090,7 +2094,21 @@
    
       IMAGEBACKUP = true;
       
-      Verbose("Checking copy from %s:%s to 
%s\n",ip->server,ip->path,ip->destination);
+         /* Convert any variables to their values */
+         if (IsVarString(ip->server))
+               ExpandVarstring(ip->server,server,"");
+         else
+               strncpy (server, ip->server, sizeof(server));
+         if (IsVarString(ip->path))
+               ExpandVarstring(ip->path,path,"");
+         else
+               strncpy (path, ip->path, sizeof(path));
+         if (IsVarString(ip->destination))
+               ExpandVarstring(ip->destination,destination,"");
+         else
+               strncpy (destination, ip->destination, sizeof(destination));    
        
+
+      Verbose("Checking copy from %s:%s to %s\n",server,path,destination);
       
       savesilent = SILENT;
       
@@ -2101,7 +2118,7 @@
       
       ResetOutputRoute(ip->log,ip->inform);
       
-      sprintf(VBUFF,"%.50s.%.50s",ip->path,ip->destination); /* Unique ID for 
copy locking */
+      snprintf(VBUFF,bufsize,"%.50s.%.50s",path,destination); /* Unique ID for 
copy locking */
 
       if 
(!GetLock(ASUniqueName("copy"),CanonifyName(VBUFF),VIFELAPSED,VEXPIREAFTER,VUQNAME,CFSTARTTIME))
         {
@@ -2112,9 +2129,9 @@
       
       IMAGEBACKUP = ip->backup;
       
-      if (cfstat(ip->path,&statbuf,ip) == -1)
+      if (cfstat(path,&statbuf,ip) == -1)
         {
-        sprintf(OUTPUT,"Can't stat %s in copy\n",ip->path);
+        snprintf(OUTPUT,bufsize*2,"Can't stat %s in copy\n",path);
         CfLog(cfinform,OUTPUT,"");
         ReleaseCurrentLock();
         SILENT = savesilent;
@@ -2122,7 +2139,7 @@
         continue;
         }
       
-      if (strncmp(ip->destination,"home",4) == 0)
+      if (strncmp(destination,"home",4) == 0)
         {
         HOMECOPY = true;          /* Don't send home backups to repository */
         CheckHomeImages(ip);
@@ -2136,11 +2153,11 @@
               {
               Verbose("%s: (Destination purging enabled)\n",VPREFIX);
               }
-           RecursiveImage(ip,ip->path,ip->destination,ip->recurse);
+           RecursiveImage(ip,path,destination,ip->recurse);
            }
         else
            {
-           if (! MakeDirectoriesFor(ip->destination))
+           if (! MakeDirectoriesFor(destination))
               {
               ReleaseCurrentLock();
               SILENT = savesilent;
@@ -2148,7 +2165,7 @@
               continue;
               }
            
-           CheckImage(ip->path,ip->destination,ip);
+           CheckImage(path,destination,ip);
            }
         }


-- 
Your mouse has moved.
Windows NT must be restarted for the change to take effect.
Reboot now?  [OK]



reply via email to

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