mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-16 12:10:46 +01:00
imfile: Fixed multiple bugs in new wildcard directory handling
Fixed removal for directory watch and helper functions Fixed invalid setupdirwatch indexes. Changed logfile extensions for new tests
This commit is contained in:
parent
3bf605255a
commit
8025057e39
@ -1469,7 +1469,7 @@ finalize_it:
|
||||
}
|
||||
/* add entry to dirs array */
|
||||
static rsRetVal
|
||||
dirsAdd(uchar *dirName)
|
||||
dirsAdd(uchar *dirName, int* piIndex)
|
||||
{
|
||||
sbool sbAdded;
|
||||
int newMax;
|
||||
@ -1489,6 +1489,10 @@ dirsAdd(uchar *dirName)
|
||||
}
|
||||
}
|
||||
|
||||
/* Save Index for higher functions */
|
||||
if (piIndex != NULL )
|
||||
*piIndex = newindex;
|
||||
|
||||
/* Check if dirstab size needs to be increased */
|
||||
if(sbAdded == TRUE && newindex == allocMaxDirs) {
|
||||
newMax = 2 * allocMaxDirs;
|
||||
@ -1551,7 +1555,7 @@ DBGPRINTF("imfile: dirsInit\n");
|
||||
|
||||
for(inst = runModConf->root ; inst != NULL ; inst = inst->next) {
|
||||
if(dirsFindDir(inst->pszDirName) == -1)
|
||||
dirsAdd(inst->pszDirName);
|
||||
dirsAdd(inst->pszDirName, NULL);
|
||||
}
|
||||
|
||||
finalize_it:
|
||||
@ -1589,17 +1593,24 @@ finalize_it:
|
||||
static void
|
||||
in_setupDirWatch(const int dirIdx)
|
||||
{
|
||||
// TODO HANDLE WILDCARDS!
|
||||
int wd;
|
||||
sbool hasWildcard;
|
||||
char dirnametrunc[MAXFNAME];
|
||||
int dirnamelen = 0;
|
||||
char* psztmp;
|
||||
|
||||
wd = inotify_add_watch(ino_fd, (char*)dirs[dirIdx].dirName, IN_CREATE|IN_DELETE|IN_MOVED_FROM);
|
||||
if(wd < 0) {
|
||||
/* check for wildcard in directoryname, if last character is a wildcard we remove it and try again! */
|
||||
dirnamelen = ustrlen(dirs[dirIdx].dirName);
|
||||
memcpy(dirnametrunc, dirs[dirIdx].dirName, dirnamelen); /* Copy mem */
|
||||
if ( *(dirnametrunc+dirnamelen-1) == '*' ) {
|
||||
*(dirnametrunc+dirnamelen-1) = '\0'; /* remove wildcard */
|
||||
|
||||
hasWildcard = containsGlobWildcard(dirnametrunc);
|
||||
if(hasWildcard) {
|
||||
/* Set NULL Byte on last directory delimiter occurrence,
|
||||
will also remove asterix */
|
||||
psztmp = strrchr(dirnametrunc, '/');
|
||||
*psztmp = '\0';
|
||||
|
||||
/* Try to add inotify watch again */
|
||||
wd = inotify_add_watch(ino_fd, dirnametrunc, IN_CREATE|IN_DELETE|IN_MOVED_FROM);
|
||||
@ -1744,8 +1755,8 @@ in_setupFileWatchDynamic(lstn_t *pLstn, uchar *const __restrict__ newBaseName, u
|
||||
if (idirindex == -1) {
|
||||
/* Add dir to table and create watch */
|
||||
DBGPRINTF("imfile: Adding new dir '%s' to dirs table \n", basedir);
|
||||
dirsAdd(basedir);
|
||||
in_setupDirWatch(currMaxDirs-1);
|
||||
dirsAdd(basedir, &idirindex);
|
||||
in_setupDirWatch(idirindex);
|
||||
}
|
||||
/* Use newFileName */
|
||||
snprintf(fullfn, MAXFNAME, "%s", newFileName);
|
||||
@ -1872,17 +1883,22 @@ in_dbg_showEv(struct inotify_event *ev)
|
||||
static void
|
||||
in_handleDirGetFullDir(char* pszoutput, char* pszrootdir, char* pszsubdir)
|
||||
{
|
||||
sbool hasWildcard;
|
||||
char dirnametrunc[MAXFNAME];
|
||||
int dirnamelen = 0;
|
||||
char* psztmp;
|
||||
|
||||
/* check for wildcard in directoryname, if last character is a wildcard we remove it and try again! */
|
||||
dirnamelen = ustrlen(pszrootdir);
|
||||
memcpy(dirnametrunc, pszrootdir, dirnamelen); /* Copy mem */
|
||||
if ( *(dirnametrunc+dirnamelen-1) == '*' ) {
|
||||
if (*(dirnametrunc+dirnamelen-2) == '/')
|
||||
*(dirnametrunc+dirnamelen-2) = '\0'; /* remove wildcard and slash */
|
||||
else
|
||||
*(dirnametrunc+dirnamelen-1) = '\0'; /* remove wildcard */
|
||||
|
||||
hasWildcard = containsGlobWildcard(dirnametrunc);
|
||||
if(hasWildcard) {
|
||||
// if ( *(dirnametrunc+dirnamelen-1) == '*' ) {
|
||||
/* Set NULL Byte on last directory delimiter occurrence,
|
||||
will also remove asterix */
|
||||
psztmp = strrchr(dirnametrunc, '/');
|
||||
*psztmp = '\0';
|
||||
}
|
||||
|
||||
/* Combine directory and new subdir */
|
||||
@ -1908,7 +1924,7 @@ in_removeFile(const int dirIdx,
|
||||
if(pLstn->bRMStateOnDel) {
|
||||
statefn = getStateFileName(pLstn, statefile, sizeof(statefile));
|
||||
snprintf((char*)toDel, sizeof(toDel), "%s/%s",
|
||||
glbl.GetWorkDir(), (char*)statefn);
|
||||
(char*) glbl.GetWorkDir(), (char*)statefn);
|
||||
bDoRMState = 1;
|
||||
} else {
|
||||
bDoRMState = 0;
|
||||
@ -1946,8 +1962,8 @@ in_handleDirEventDirCREATE(struct inotify_event *ev, const int dirIdx)
|
||||
if(newdiridx == -1) {
|
||||
/* Add dir to table and create watch */
|
||||
DBGPRINTF("imfile: Adding new dir '%s' to dirs table \n", fulldn);
|
||||
dirsAdd((uchar*)fulldn);
|
||||
in_setupDirWatch(currMaxDirs-1);
|
||||
dirsAdd((uchar*)fulldn, &newdiridx);
|
||||
in_setupDirWatch(newdiridx);
|
||||
} else {
|
||||
DBGPRINTF("imfile: dir '%s' already exists in dirs table (Idx %d)\n", fulldn, newdiridx);
|
||||
}
|
||||
|
||||
@ -7,21 +7,16 @@ export IMFILEINPUTFILES="10"
|
||||
. $srcdir/diag.sh init
|
||||
# generate input files first. Note that rsyslog processes it as
|
||||
# soon as it start up (so the file should exist at that point).
|
||||
imfiledirbefore="rsyslog.input.dir1"
|
||||
|
||||
# Create first dir and file
|
||||
mkdir $imfiledirbefore
|
||||
./inputfilegen -m 1 > $imfiledirbefore/file.log
|
||||
|
||||
# Start rsyslog now before adding more files
|
||||
. $srcdir/diag.sh startup imfile-wildcards-dirs.conf
|
||||
# sleep a little to give rsyslog a chance to begin processing
|
||||
sleep 1
|
||||
|
||||
for i in `seq 2 $IMFILEINPUTFILES`;
|
||||
for i in `seq 1 $IMFILEINPUTFILES`;
|
||||
do
|
||||
cp -r $imfiledirbefore rsyslog.input.dir$i
|
||||
imfiledirbefore="rsyslog.input.dir$i"
|
||||
mkdir rsyslog.input.dir$i
|
||||
./inputfilegen -m 1 > rsyslog.input.dir$i/file.logfile
|
||||
done
|
||||
ls -d rsyslog.input.*
|
||||
|
||||
|
||||
@ -9,11 +9,6 @@ export IMFILEINPUTFILESALL=$(($IMFILEINPUTFILES * $IMFILEINPUTFILESSTEPS))
|
||||
. $srcdir/diag.sh init
|
||||
# generate input files first. Note that rsyslog processes it as
|
||||
# soon as it start up (so the file should exist at that point).
|
||||
imfiledirbefore="rsyslog.input.dir1"
|
||||
|
||||
# Create first dir and file
|
||||
mkdir $imfiledirbefore
|
||||
./inputfilegen -m 1 > $imfiledirbefore/file.log
|
||||
|
||||
# Start rsyslog now before adding more files
|
||||
. $srcdir/diag.sh startup imfile-wildcards-dirs.conf
|
||||
@ -24,24 +19,21 @@ for j in `seq 1 $IMFILEINPUTFILESSTEPS`;
|
||||
do
|
||||
echo "Loop Num $j"
|
||||
|
||||
for i in `seq 2 $IMFILEINPUTFILES`;
|
||||
for i in `seq 1 $IMFILEINPUTFILES`;
|
||||
do
|
||||
cp -r $imfiledirbefore rsyslog.input.dir$i
|
||||
imfiledirbefore="rsyslog.input.dir$i"
|
||||
mkdir rsyslog.input.dir$i
|
||||
./inputfilegen -m 1 > rsyslog.input.dir$i/file.logfile
|
||||
done
|
||||
ls -d rsyslog.input.*
|
||||
|
||||
# sleep a little to give rsyslog a chance for processing
|
||||
sleep 1
|
||||
sleep 2
|
||||
|
||||
# Delete all but first!
|
||||
for i in `seq 2 $IMFILEINPUTFILES`;
|
||||
for i in `seq 1 $IMFILEINPUTFILES`;
|
||||
do
|
||||
rm -r rsyslog.input.dir$i
|
||||
done
|
||||
|
||||
# Reset to default
|
||||
imfiledirbefore="rsyslog.input.dir1"
|
||||
done
|
||||
|
||||
. $srcdir/diag.sh shutdown-when-empty # shut down rsyslogd when done processing messages
|
||||
|
||||
@ -5,7 +5,7 @@ module( load="../plugins/imfile/.libs/imfile"
|
||||
PollingInterval="1")
|
||||
|
||||
input(type="imfile"
|
||||
File="./rsyslog.input.*/*.log"
|
||||
File="./rsyslog.input.*/*.logfile"
|
||||
Tag="file:"
|
||||
Severity="error"
|
||||
Facility="local7"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user