[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to define variables using a plugin
From: |
Adrian Phillips |
Subject: |
Re: How to define variables using a plugin |
Date: |
01 Aug 2001 10:51:46 +0200 |
User-agent: |
Gnus/5.0807 (Gnus v5.8.7) Emacs/20.7 |
>>>>> "Adrian" == Adrian Phillips <a.phillips@dnmi.no> writes:
Adrian> Good day,
Adrian> I'm trying to define variables using a shell script as a
Adrian> plugin but the variables are not being used in actions
Adrian> later in the actionsequence. Is this possible ?
Adrian> A simple example :-
Adrian> control:
Adrian> domain = ( oslo.dnmi.no )
Adrian> master_server = ( freeze )
Adrian> actionsequence = ( "module:defvars ${cache}" copy
Adrian> )
Adrian> copy:
Adrian> ${kernel_dir} server=${master_server} exclude=*~
Adrian> dest=/usr/src recurse=1
Okay, I tried 2.0.a11 but it still didn't work and I must admit not
knowing how it is supposed to work either. I fixed it with the
following patch but this only handles variables in a copy action and
doesn't help with the underlying problem with variables being defined
by a plugin not being used in actions.
Sincerely,
Adrian
diff -u -r cfengine-2.0.a11/src/do.c cfengine-2.0.a11.new/src/do.c
--- cfengine-2.0.a11/src/do.c Fri Jun 8 18:32:17 2001
+++ cfengine-2.0.a11.new/src/do.c Wed Aug 1 10:43:41 2001
@@ -2209,17 +2209,20 @@
{ 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];
-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 */
@@ -2261,7 +2264,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;
@@ -2272,7 +2289,7 @@
ResetOutputRoute(ip->log,ip->inform);
- snprintf(VBUFF,bufsize,"%.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))
{
@@ -2283,9 +2300,9 @@
IMAGEBACKUP = ip->backup;
- if (cfstat(ip->path,&statbuf,ip) == -1)
+ if (cfstat(path,&statbuf,ip) == -1)
{
- snprintf(OUTPUT,bufsize*2,"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;
@@ -2293,7 +2310,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);
@@ -2307,11 +2324,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;
@@ -2319,7 +2336,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]
- Re: How to define variables using a plugin,
Adrian Phillips <=