summaryrefslogtreecommitdiffstats
path: root/syslogd.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-12-18 16:20:51 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-12-18 16:20:51 +0000
commit2d824173f21324dc7a5262146dcd374aacdde43b (patch)
treeaa4aee1e5efd30b7d84eebc90f70739247eb59ab /syslogd.c
parentfe94afd52b965a2b60a418ca85298146653c707a (diff)
downloadrsyslog-2d824173f21324dc7a5262146dcd374aacdde43b.tar.gz
rsyslog-2d824173f21324dc7a5262146dcd374aacdde43b.tar.xz
rsyslog-2d824173f21324dc7a5262146dcd374aacdde43b.zip
applied Michael Biebl's patch to enhance $includeconfig to support wildcard
filenames
Diffstat (limited to 'syslogd.c')
-rw-r--r--syslogd.c40
1 files changed, 32 insertions, 8 deletions
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;
}