bugfix: $IncludeConfig did not correctly process directories

closes: http://bugzilla.adiscon.com/show_bug.cgi?id=376
The testbench was also enhanced to check for these cases.
Thanks to Georgi Georgiev for the bug report.

Also minor bugfix: no error msg on unreadable $IncludeConfig path
This commit is contained in:
Rainer Gerhards 2012-11-09 12:12:17 +01:00
parent b05d4a6db4
commit dc8f9b531c
11 changed files with 85 additions and 19 deletions

View File

@ -9,6 +9,11 @@ Version 6.6.1 [v6-stable] 2012-10-??
This did not affect users, but could have caused trouble in the future
for developers.
- bugfix: no error msg on invalid field option in legacy/string template
- bugfix: no error msg on unreadable $IncludeConfig path
- bugfix: $IncludeConfig did not correctly process directories
closes: http://bugzilla.adiscon.com/show_bug.cgi?id=376
The testbench was also enhanced to check for these cases.
Thanks to Georgi Georgiev for the bug report.
---------------------------------------------------------------------------
Version 6.6.0 [v6-stable] 2012-10-22
This starts a new stable branch, based on the 6.5.x series, plus:

View File

@ -680,7 +680,6 @@ nvlstGetParams(struct nvlst *lst, struct cnfparamblk *params,
vals = NULL;
}
dbgprintf("DDDD: vals %p\n", vals);
return vals;
}
@ -1818,24 +1817,29 @@ int
cnfDoInclude(char *name)
{
char *cfgFile;
char *finalName;
unsigned i;
int result;
glob_t cfgFiles;
struct stat fileInfo;
char nameBuf[MAXFNAME+1];
/* 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
finalName = name;
if(stat(name, &fileInfo) == 0) {
/* stat usually fails if we have a wildcard - so this does NOT indicate error! */
if(S_ISDIR(fileInfo.st_mode)) {
/* if we have a directory, we need to add "*" to get its files */
snprintf(nameBuf, sizeof(nameBuf), "%s*", name);
finalName = nameBuf;
}
}
/* Use GLOB_MARK to append a trailing slash for directories. */
result = glob(finalName, GLOB_MARK, NULL, &cfgFiles);
if(result == GLOB_NOSPACE || result == GLOB_ABORTED || cfgFiles.gl_pathc == 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);
parser_errmsg("error accessing config file or directory '%s': %s",
finalName, errStr);
return 1;
}
@ -1849,11 +1853,8 @@ cnfDoInclude(char *name)
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);
}
dbgprintf("requested to include directory '%s'\n", cfgFile);
cnfDoInclude(cfgFile);
} else {
dbgprintf("warning: unable to process IncludeConfig directive '%s'\n", cfgFile);
}

View File

@ -65,6 +65,9 @@ TESTS += \
failover-no-basic.sh \
rcvr_fail_restore.sh \
rscript_contains.sh \
incltest.sh \
incltest_dir.sh \
incltest_dir_wildcard.sh \
linkedlistqueue.sh
if HAVE_VALGRIND
@ -267,6 +270,13 @@ EXTRA_DIST= 1.rstest 2.rstest 3.rstest err1.rstest \
testsuites/arrayqueue.conf \
rscript_contains.sh \
testsuites/rscript_contains.conf \
incltest.sh \
testsuites/incltest.conf \
incltest_dir.sh \
testsuites/incltest_dir.conf \
incltest_dir_wildcard.sh \
testsuites/incltest_dir_wildcard.conf \
testsuites/incltest.d/include.conf \
linkedlistqueue.sh \
testsuites/linkedlistqueue.conf \
da-mainmsg-q.sh \

View File

@ -10,8 +10,8 @@
#valgrind="valgrind --tool=helgrind --log-fd=1"
#valgrind="valgrind --tool=exp-ptrcheck --log-fd=1"
#set -o xtrace
#export RSYSLOG_DEBUG="debug nologfuncflow noprintmutexaction nostdout"
#export RSYSLOG_DEBUGLOG="log"
export RSYSLOG_DEBUG="debug nologfuncflow noprintmutexaction nostdout"
export RSYSLOG_DEBUGLOG="log"
case $1 in
'init') $srcdir/killrsyslog.sh # kill rsyslogd if it runs for some reason
cp $srcdir/testsuites/diag-common.conf diag-common.conf

11
tests/incltest.sh Executable file
View File

@ -0,0 +1,11 @@
echo ===============================================================================
echo \[incltest.sh\]: test $IncludeConfig for specific file
source $srcdir/diag.sh init
source $srcdir/diag.sh startup incltest.conf
# 100 messages are enough - the question is if the include is read ;)
source $srcdir/diag.sh injectmsg 0 100
source $srcdir/diag.sh shutdown-when-empty # shut down rsyslogd when done processing messages
source $srcdir/diag.sh wait-shutdown
source $srcdir/diag.sh seq-check 0 99
source $srcdir/diag.sh exit

11
tests/incltest_dir.sh Executable file
View File

@ -0,0 +1,11 @@
echo ===============================================================================
echo \[incltest_dir.sh\]: test $IncludeConfig for directories
source $srcdir/diag.sh init
source $srcdir/diag.sh startup incltest_dir.conf
# 100 messages are enough - the question is if the include is read ;)
source $srcdir/diag.sh injectmsg 0 100
source $srcdir/diag.sh shutdown-when-empty # shut down rsyslogd when done processing messages
source $srcdir/diag.sh wait-shutdown
source $srcdir/diag.sh seq-check 0 99
source $srcdir/diag.sh exit

11
tests/incltest_dir_wildcard.sh Executable file
View File

@ -0,0 +1,11 @@
echo ===============================================================================
echo \[incltest_dir_wildcard.sh\]: test $IncludeConfig for directories with wildcards
source $srcdir/diag.sh init
source $srcdir/diag.sh startup incltest_dir_wildcard.conf
# 100 messages are enough - the question is if the include is read ;)
source $srcdir/diag.sh injectmsg 0 100
source $srcdir/diag.sh shutdown-when-empty # shut down rsyslogd when done processing messages
source $srcdir/diag.sh wait-shutdown
source $srcdir/diag.sh seq-check 0 99
source $srcdir/diag.sh exit

View File

@ -0,0 +1,5 @@
# see .sh file for description
# rgerhards, 2009-11-30
$IncludeConfig diag-common.conf
$IncludeConfig testsuites/incltest.d/include.conf

View File

@ -0,0 +1,2 @@
$template outfmt,"%msg:F,58:2%\n"
:msg, contains, "msgnum:" ./rsyslog.out.log;outfmt

View File

@ -0,0 +1,5 @@
# see .sh file for description
# rgerhards, 2009-11-30
$IncludeConfig diag-common.conf
$IncludeConfig testsuites/incltest.d/

View File

@ -0,0 +1,5 @@
# see .sh file for description
# rgerhards, 2009-11-30
$IncludeConfig diag-common.conf
$IncludeConfig testsuites/incltest.d/*.conf