help-cfengine
[Top][All Lists]
Advanced

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

Re: PrepModule or actionsequence: Hobson's choice


From: Mark Burgess
Subject: Re: PrepModule or actionsequence: Hobson's choice
Date: Tue, 30 Aug 2005 14:39:51 +0200

Cedric, this is the first I have heard of this.

Of course the patch will be included, once it has been through quality
control.

M

On Tue, 2005-08-30 at 14:21 +0200, Cedric Ware wrote:
>       Hello,
> 
> Last month, I reported a problem in cfengine, that CFALLCLASSES
> was not set when calling an external module via PrepModule, cf:
> http://lists.gnu.org/archive/html/help-cfengine/2005-07/msg00025.html
> 
> The problem was that for a module called via PrepModule, the function
> CheckForModule (called from functions.c) isn't preceded by a call to
> BuildClassEnvironment, as it is for a module in the actionsequence,
> where CheckForModule is called from cfagent.c.
> 
> A colleague of mine wrote the patch below, against cfengine 2.1.14,
> which moves BuildClassEnvironment from cfagent.c to functions.c and
> adds the call before CheckForModule in functions.c.  I have been
> using it for a few weeks, seemingly without problems.  I think it
> applies cleanly to cfengine 2.1.15.
> 
> Shouldn't it be integrated in future versions?
> 
>                                       Thank you,
>                                       Cedric Ware.
> 
> diff -bBur cfengine-2.1.14/src/cfagent.c cfengine/src/cfagent.c
> --- cfengine-2.1.14/src/cfagent.c     2005-07-09 15:42:57.000000000 +0200
> +++ cfengine/src/cfagent.c    2005-07-09 16:00:19.000000000 +0200
> @@ -51,7 +51,10 @@
>  enum aseq EvaluateAction ARGLIST((char *action, struct Item **classlist, int 
> pass));
>  void CheckOpts ARGLIST((int argc, char **argv));
>  int GetResource ARGLIST((char *var));
> -void BuildClassEnvironment ARGLIST((void));
> +/* moved to functions.c
> +   void BuildClassEnvironment ARGLIST((void));
> +*/
> +
>  void Syntax ARGLIST((void));
>  void EmptyActionSequence ARGLIST((void));
>  void GetEnvironment ARGLIST((void));
> @@ -1880,95 +1883,6 @@
>  
>  /*******************************************************************/
>  
> -void BuildClassEnvironment()
> -
> -{ struct Item *ip;
> - int size = 0;
> - char file[CF_BUFSIZE], *sp;
> - FILE *fp;
> - 
> -Debug("(BuildClassEnvironment)\n");
> -
> -snprintf(ALLCLASSBUFFER,CF_BUFSIZE,"%s=",CF_ALLCLASSESVAR);
> -
> -if (!IsPrivileged())
> -   {
> -   Verbose("\n(Non privileged user...)\n\n");
> -   
> -   if ((sp = getenv("HOME")) == NULL)
> -      {
> -      FatalError("You do not have a HOME variable pointing to your home 
> directory");
> -      }  
> -
> -   snprintf(file,CF_BUFSIZE,"%s/.cfagent/allclasses",sp);
> -   }
> -else
> -   {
> -   snprintf(file,CF_BUFSIZE,"%s/state/allclasses",WORKDIR);
> -   }
> -
> -
> -if ((fp = fopen(file,"w")) == NULL)
> -   {
> -   CfLog(cfinform,"Could not open allclasses cache file","");
> -   return;
> -   }
> -
> -for (ip = VHEAP; ip != NULL; ip=ip->next)
> -   {
> -   if (IsDefinedClass(ip->name))
> -      {
> -      if ((size += strlen(ip->name)) > CF_ALLCLASSSIZE - CF_BUFFERMARGIN)
> -         {
> -         Verbose("Class buffer overflowed, dumping class environment for 
> modules\n");
> -         Verbose("This would probably crash the exec interface on most 
> machines\n");
> -         }
> -      else
> -         {
> -         size++; /* Allow for : separator */
> -         strcat(ALLCLASSBUFFER,ip->name);
> -         strcat(ALLCLASSBUFFER,":");
> -         }
> -
> -      fprintf(fp,"%s\n",ip->name);
> -      }
> -   }
> - 
> - for (ip = VALLADDCLASSES; ip != NULL; ip=ip->next)
> -    {
> -    if (IsDefinedClass(ip->name))
> -      {
> -      if ((size += strlen(ip->name)) > 4*CF_BUFSIZE - CF_BUFFERMARGIN)
> -         {
> -         Verbose("Class buffer overflowed, dumping class environment for 
> modules\n");
> -         Verbose("This would probably crash the exec interface on most 
> machines\n");
> -         }
> -      else
> -         {
> -         size++; /* Allow for : separator */
> -         strcat(ALLCLASSBUFFER,ip->name);
> -         strcat(ALLCLASSBUFFER,":");         
> -         }
> -      
> -      fprintf(fp,"%s\n",ip->name);
> -      }
> -    }
> - 
> - Debug2("---\nENVIRONMENT: %s\n---\n",ALLCLASSBUFFER);
> - 
> - if (USEENVIRON)
> -    {
> -    if (putenv(ALLCLASSBUFFER) == -1)
> -       {
> -       perror("putenv");
> -       }
> -    }
> -
> - fclose(fp);
> -}
> -
> -/*******************************************************************/
> -
>  void Syntax()
>  
>  { int i;
> diff -bBur cfengine-2.1.14/src/functions.c cfengine/src/functions.c
> --- cfengine-2.1.14/src/functions.c   2005-07-09 15:42:57.000000000 +0200
> +++ cfengine/src/functions.c  2005-07-09 16:00:11.000000000 +0200
> @@ -1718,6 +1718,8 @@
>  
>  Debug("PrepModule(%s,%s)\n",argv[0],argv[1]);
>   
> +BuildClassEnvironment();
> + 
>  if (CheckForModule(argv[0],argv[1]))
>     {
>     strcpy(value,CF_ANYCLASS);
> @@ -1825,3 +1827,92 @@
>  return true;
>  }
>  
> +/*******************************************************************/
> +
> +void BuildClassEnvironment()
> +
> +{ struct Item *ip;
> + int size = 0;
> + char file[CF_BUFSIZE], *sp;
> + FILE *fp;
> + 
> +Debug("(BuildClassEnvironment)\n");
> +
> +snprintf(ALLCLASSBUFFER,CF_BUFSIZE,"%s=",CF_ALLCLASSESVAR);
> +
> +if (!IsPrivileged())
> +   {
> +   Verbose("\n(Non privileged user...)\n\n");
> +   
> +   if ((sp = getenv("HOME")) == NULL)
> +      {
> +      FatalError("You do not have a HOME variable pointing to your home 
> directory");
> +      }  
> +
> +   snprintf(file,CF_BUFSIZE,"%s/.cfagent/allclasses",sp);
> +   }
> +else
> +   {
> +   snprintf(file,CF_BUFSIZE,"%s/state/allclasses",WORKDIR);
> +   }
> +
> +
> +if ((fp = fopen(file,"w")) == NULL)
> +   {
> +   CfLog(cfinform,"Could not open allclasses cache file","");
> +   return;
> +   }
> +
> +for (ip = VHEAP; ip != NULL; ip=ip->next)
> +   {
> +   if (IsDefinedClass(ip->name))
> +      {
> +      if ((size += strlen(ip->name)) > CF_ALLCLASSSIZE - CF_BUFFERMARGIN)
> +         {
> +         Verbose("Class buffer overflowed, dumping class environment for 
> modules\n");
> +         Verbose("This would probably crash the exec interface on most 
> machines\n");
> +         }
> +      else
> +         {
> +         size++; /* Allow for : separator */
> +         strcat(ALLCLASSBUFFER,ip->name);
> +         strcat(ALLCLASSBUFFER,":");
> +         }
> +
> +      fprintf(fp,"%s\n",ip->name);
> +      }
> +   }
> + 
> + for (ip = VALLADDCLASSES; ip != NULL; ip=ip->next)
> +    {
> +    if (IsDefinedClass(ip->name))
> +      {
> +      if ((size += strlen(ip->name)) > 4*CF_BUFSIZE - CF_BUFFERMARGIN)
> +         {
> +         Verbose("Class buffer overflowed, dumping class environment for 
> modules\n");
> +         Verbose("This would probably crash the exec interface on most 
> machines\n");
> +         }
> +      else
> +         {
> +         size++; /* Allow for : separator */
> +         strcat(ALLCLASSBUFFER,ip->name);
> +         strcat(ALLCLASSBUFFER,":");         
> +         }
> +      
> +      fprintf(fp,"%s\n",ip->name);
> +      }
> +    }
> + 
> + Debug2("---\nENVIRONMENT: %s\n---\n",ALLCLASSBUFFER);
> + 
> + if (USEENVIRON)
> +    {
> +    if (putenv(ALLCLASSBUFFER) == -1)
> +       {
> +       perror("putenv");
> +       }
> +    }
> +
> + fclose(fp);
> +}
> +
> diff -bBur cfengine-2.1.14/src/prototypes.h cfengine/src/prototypes.h
> --- cfengine-2.1.14/src/prototypes.h  2005-07-09 15:42:57.000000000 +0200
> +++ cfengine/src/prototypes.h 2005-07-09 16:00:01.000000000 +0200
> @@ -156,7 +156,7 @@
>  int IsTCPType ARGLIST((char *s));
>  int IsProcessType ARGLIST((char *s));
>  void HandleFriendStatus ARGLIST((char *args,char *value));
> -
> +void BuildClassEnvironment ARGLIST((void));
>  
>  /* granules.c  */
>  
> 
> 
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-cfengine





reply via email to

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