summaryrefslogtreecommitdiffstats
path: root/grammar
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2011-07-09 18:00:29 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2011-07-09 18:00:29 +0200
commit6ebf9ada253ffd8c88cbe84a46fd5aa3bfd58367 (patch)
tree4b527b06aaf68dc83268da51dafbe855534ad0f4 /grammar
parentda6489743cd31a7896f17f5500dbfd18e0560260 (diff)
downloadrsyslog-6ebf9ada253ffd8c88cbe84a46fd5aa3bfd58367.tar.gz
rsyslog-6ebf9ada253ffd8c88cbe84a46fd5aa3bfd58367.tar.xz
rsyslog-6ebf9ada253ffd8c88cbe84a46fd5aa3bfd58367.zip
milestone/[WORKS AGAIN!]: looks like the new conf format is integrated
finally completed $IncludeConfig processing.
Diffstat (limited to 'grammar')
-rw-r--r--grammar/lexer.l2
-rw-r--r--grammar/rainerscript.c52
-rw-r--r--grammar/rainerscript.h1
3 files changed, 54 insertions, 1 deletions
diff --git a/grammar/lexer.l b/grammar/lexer.l
index 802b2d89..316b2a65 100644
--- a/grammar/lexer.l
+++ b/grammar/lexer.l
@@ -143,7 +143,7 @@ int fileno(FILE *stream);
* always the longest match :-(
*/
<INCL>.|\n
-<INCL>[^ \t\n]+ { if(cnfSetLexFile(yytext) != 0)
+<INCL>[^ \t\n]+ { if(cnfDoInclude(yytext) != 0)
yyterminate();
BEGIN INITIAL; }
"global"[ \n\t]*"(" { yylval.objType = CNFOBJ_GLOBAL;
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c
index f8809e13..680f8775 100644
--- a/grammar/rainerscript.c
+++ b/grammar/rainerscript.c
@@ -28,6 +28,9 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <glob.h>
+#include <errno.h>
+#include <sys/stat.h>
#include <libestr.h>
#include "rainerscript.h"
#include "parserif.h"
@@ -1050,6 +1053,55 @@ cnffuncNew(es_str_t *fname, struct cnffparamlst* paramlst)
return func;
}
+int
+cnfDoInclude(char *name)
+{
+ char *cfgFile;
+ unsigned i;
+ int result;
+ glob_t cfgFiles;
+ struct stat fileInfo;
+
+ /* Use GLOB_MARK to append a trailing slash for directories.
+ * Required by doIncludeDirectory().
+ */
+ result = glob(name, GLOB_MARK, NULL, &cfgFiles);
+ if(result == GLOB_NOSPACE || result == GLOB_ABORTED) {
+#if 0
+ char errStr[1024];
+ rs_strerror_r(errno, errStr, sizeof(errStr));
+ errmsg.LogError(0, RS_RET_FILE_NOT_FOUND, "error accessing config file or directory '%s': %s",
+ pattern, errStr);
+ ABORT_FINALIZE(RS_RET_FILE_NOT_FOUND);
+#endif
+ dbgprintf("includeconfig glob error %d\n", errno);
+ return 1;
+ }
+
+ for(i = 0; i < cfgFiles.gl_pathc; i++) {
+ cfgFile = cfgFiles.gl_pathv[i];
+
+ if(stat(cfgFile, &fileInfo) != 0)
+ continue; /* continue with the next file if we can't stat() the file */
+
+ if(S_ISREG(fileInfo.st_mode)) { /* config file */
+ dbgprintf("requested to include config file '%s'\n", cfgFile);
+ cnfSetLexFile(cfgFile);
+ } else if(S_ISDIR(fileInfo.st_mode)) { /* config directory */
+ if(strcmp(name, cfgFile)) {
+ /* do not include ourselves! */
+ dbgprintf("requested to include directory '%s'\n", cfgFile);
+ cnfDoInclude(cfgFile);
+ }
+ } else {
+ dbgprintf("warning: unable to process IncludeConfig directive '%s'\n", cfgFile);
+ }
+ }
+
+ globfree(&cfgFiles);
+ return 0;
+}
+
void
cstrPrint(char *text, es_str_t *estr)
{
diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h
index 5d9eff7f..75bb782d 100644
--- a/grammar/rainerscript.h
+++ b/grammar/rainerscript.h
@@ -189,6 +189,7 @@ void cnfrulePrint(struct cnfrule *rule);
struct cnfvar* cnfvarNew(char *name);
struct cnffunc * cnffuncNew(es_str_t *fname, struct cnffparamlst* paramlst);
struct cnffparamlst * cnffparamlstNew(struct cnfexpr *expr, struct cnffparamlst *next);
+int cnfDoInclude(char *name);
/* debug helper */
void cstrPrint(char *text, es_str_t *estr);