--- cfengine-2.1.15/src/parse.c 2005-05-29 20:34:15.000000000 +1000 +++ cfengine-2.1.15.mpalmer/src/parse.c 2005-12-28 19:33:06.000000000 +1100 @@ -37,6 +37,7 @@ #define INET +#include #include #include "cf.defs.h" #include "cf.extern.h" @@ -1012,7 +1013,11 @@ void ParseFile(char *filename,char *env) -{ FILE *save_yyin = yyin; +{ +FILE *save_yyin = yyin; +glob_t globbuf; +int i; +char *curfile; signal(SIGALRM,(void *)TimeOut); alarm(RPCTIMEOUT); @@ -1022,8 +1027,14 @@ FatalError("Security exception"); } -if ((yyin = fopen(filename,"r")) == NULL) /* Open root file */ - { +/* mpalmer: Extension to use glob() to allow a globbed list of files + * to be processed. Usual shell globbing rules apply -- *, ?, etc. + */ +if (glob(filename, 0, NULL, &globbuf)) +{ + /* Something went wrong with the glob(). Frankly, I don't really care + * what. + */ printf("%s: Can't open file %s\n",VPREFIX,filename); if (env == NULL) @@ -1036,31 +1047,52 @@ } exit (1); +} + +for (i = 0; i < globbuf.gl_pathc; i++) +{ + curfile = globbuf.gl_pathv[i]; + if ((yyin = fopen(curfile, "r")) == NULL) + { + printf("%s: Can't open file %s\n",VPREFIX, curfile); + + if (env == NULL) + { + printf("%s: (%s is set to )\n",VPREFIX,CF_INPUTSVAR); + } + else + { + printf("%s: (%s is set to %s)\n",VPREFIX,CF_INPUTSVAR,env); + } + + exit (1); } - -strcpy(VCURRENTFILE,filename); -Debug("\n##########################################################################\n"); -Debug("# BEGIN PARSING %s\n",VCURRENTFILE); -Debug("##########################################################################\n\n"); + strcpy(VCURRENTFILE,curfile); + + Debug("\n##########################################################################\n"); + Debug("# BEGIN PARSING %s\n",VCURRENTFILE); + Debug("##########################################################################\n\n"); -LINENUMBER=1; + LINENUMBER=1; -while (!feof(yyin)) - { - yyparse(); + while (!feof(yyin)) + { + yyparse(); - if (ferror(yyin)) /* abortable */ - { - printf("%s: Error reading %s\n",VPREFIX,VCURRENTFILE); - perror("cfengine"); - exit(1); + if (ferror(yyin)) /* abortable */ + { + printf("%s: Error reading %s\n",VPREFIX,VCURRENTFILE); + perror("cfengine"); + exit(1); + } } - } -fclose (yyin); -yyin = save_yyin; + fclose (yyin); + yyin = save_yyin; +} +globfree(&globbuf); alarm(0); signal(SIGALRM,SIG_DFL); InstallPending(ACTION);