summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--syslogd.c40
2 files changed, 34 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 1676f254..51afef32 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,8 @@ Version 3.0.0 (rgerhards), 2007-12-??
by imklog, a loadable input module. This offers a much better integration
into rsyslogd and makes sure that the kernel logger process is brought
up and down at the appropriate times
+- enhanced $IncludeConfig directive to support wildcard characters
+ (thanks to Michael Biebl)
---------------------------------------------------------------------------
Version 1.20.2 (rgerhards), 2007-12-??
---------------------------------------------------------------------------
diff --git a/syslogd.c b/syslogd.c
index 5426df75..c9b41d36 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -187,6 +187,10 @@
#include <netdb.h>
#include <fnmatch.h>
#include <dirent.h>
+#include <glob.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
#ifndef __sun
#endif
@@ -3724,24 +3728,44 @@ finalize_it:
static rsRetVal doIncludeLine(uchar **pp, __attribute__((unused)) void* pVal)
{
DEFiRet;
- uchar cfgFile[MAXFNAME];
+ char pattern[MAXFNAME];
+ char *cfgFile;
+ glob_t cfgFiles;
+ size_t i = 0;
+ struct stat fileInfo;
assert(pp != NULL);
assert(*pp != NULL);
- if(getSubString(pp, (char*) cfgFile, sizeof(cfgFile) / sizeof(uchar), ' ') != 0) {
+ if(getSubString(pp, (char*) pattern, sizeof(pattern) / sizeof(char), ' ') != 0) {
logerror("could not extract group name");
ABORT_FINALIZE(RS_RET_NOT_FOUND);
}
- if(*(cfgFile+strlen((char*) cfgFile) - 1) == '/') {
- dbgprintf("requested to include directory '%s'\n", cfgFile);
- iRet = doIncludeDirectory(cfgFile);
- } else {
- dbgprintf("Requested to include config file '%s'\n", cfgFile);
- iRet = processConfFile(cfgFile);
+ /* Use GLOB_MARK to append a trailing slash for directories.
+ * Required by doIncludeDirectory().
+ */
+ glob(pattern, GLOB_MARK, NULL, &cfgFiles);
+
+ 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);
+ iRet = processConfFile(cfgFile);
+ } else if(S_ISDIR(fileInfo.st_mode)) { /* config directory */
+ dbgprintf("requested to include directory '%s'\n", cfgFile);
+ iRet = doIncludeDirectory(cfgFile);
+ } else { /* TODO: shall we handle symlinks or not? */
+ dbgprintf("warning: unable to process IncludeConfig directive '%s'\n", cfgFile);
+ }
}
+ globfree(&cfgFiles);
+
finalize_it:
return iRet;
}