summaryrefslogtreecommitdiffstats
path: root/plugins/imfile
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-02-13 08:14:47 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-02-13 08:14:47 +0000
commit722e691af737862b32515fd5644feb33547eff8f (patch)
treec6730a14de9a90d9012aac2243e5c87ae743f9b1 /plugins/imfile
parent088ad960e9d77d6a58a3914e53275a5e40b85dc3 (diff)
downloadrsyslog-722e691af737862b32515fd5644feb33547eff8f.tar.gz
rsyslog-722e691af737862b32515fd5644feb33547eff8f.tar.xz
rsyslog-722e691af737862b32515fd5644feb33547eff8f.zip
- introduced a new, more powerful, message submission interface submitMsg()
in additon to logmsg() - a first, rough implementation of imfile that is able to read files (but does not persist or handle rotation or whatever)
Diffstat (limited to 'plugins/imfile')
-rw-r--r--plugins/imfile/imfile.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/plugins/imfile/imfile.c b/plugins/imfile/imfile.c
index d37df02d..3f266a43 100644
--- a/plugins/imfile/imfile.c
+++ b/plugins/imfile/imfile.c
@@ -36,6 +36,7 @@
#include "module-template.h" /* generic module interface code - very important, read it! */
#include "srUtils.h" /* some utility functions */
#include "msg.h"
+#include "stream.h"
MODULE_TYPE_INPUT /* must be present for input modules, do not remove */
@@ -49,7 +50,6 @@ DEF_IMOD_STATIC_DATA /* must be present, starts static data */
* prefix in order not to conflict with other modules or rsyslogd itself (also see comment
* at file header).
*/
-/* static int imtemplateWhateverVar = 0; */
typedef struct fileInfo_s {
uchar *pszFileName;
@@ -58,7 +58,7 @@ typedef struct fileInfo_s {
int64 offsLast; /* offset last read from */
int iFacility;
int iSeverity;
- int fd; /*its file descriptor (-1 if closed) */
+ strm_t *pStrm; /* its stream (NULL if not assigned) */
} fileInfo_t;
@@ -85,23 +85,22 @@ typedef struct _instanceData {
/* enqueue the read file line as a message
*/
-static rsRetVal enqLine(fileInfo_t *pInfo, uchar *pLine)
+static rsRetVal enqLine(fileInfo_t *pInfo, rsCStrObj *cstrLine)
{
DEFiRet;
msg_t *pMsg;
- int flags = 0;
- int pri;
CHKiRet(msgConstruct(&pMsg));
- MsgSetUxTradMsg(pMsg, (char*)pLine);
- MsgSetRawMsg(pMsg, (char*)pLine);
+ MsgSetUxTradMsg(pMsg, (char*)rsCStrGetSzStr(cstrLine));
+ MsgSetRawMsg(pMsg, (char*)rsCStrGetSzStr(cstrLine));
+ MsgSetMSG(pMsg, (char*)rsCStrGetSzStr(cstrLine));
MsgSetHOSTNAME(pMsg, LocalHostName);
MsgSetTAG(pMsg, (char*)pInfo->pszTag);
pMsg->iFacility = pInfo->iFacility;
pMsg->iSeverity = pInfo->iSeverity;
pMsg->bParseHOSTNAME = 0;
getCurrTime(&(pMsg->tTIMESTAMP)); /* use the current time! */
- logmsg(pMsg, flags); /* some time, CHKiRet() will work here, too [today NOT!] */
+ CHKiRet(submitMsg(pMsg));
finalize_it:
RETiRet;
}
@@ -111,20 +110,26 @@ finalize_it:
static rsRetVal pollFile(fileInfo_t *pThis)
{
DEFiRet;
- uchar *pszLine;
+ rsCStrObj *pCStr;
int bAllNewLinesRead; /* set to 1 if all new lines are read */
- if(pThis->fd == -1) {
+ if(pThis->pStrm == NULL) {
/* open file */
+ CHKiRet(strmConstruct(&pThis->pStrm));
+ CHKiRet(strmSettOperationsMode(pThis->pStrm, STREAMMODE_READ));
+ CHKiRet(strmSetsType(pThis->pStrm, STREAMTYPE_FILE_SINGLE));
+ CHKiRet(strmSetFName(pThis->pStrm, pThis->pszFileName, strlen((char*) pThis->pszFileName)));
+ CHKiRet(strmConstructFinalize(pThis->pStrm));
/* move to offset */
}
bAllNewLinesRead = 0;
while(!bAllNewLinesRead) {
/* do read file, put pointer to file line in pszLine */
+ CHKiRet(strmReadLine(pThis->pStrm, &pCStr));
/* do the magic ;) */
- CHKiRet(enqLine(pThis, pszLine));
+ CHKiRet(enqLine(pThis, pCStr));
}
/* save the offset back to structure! */
@@ -243,7 +248,6 @@ ENDwillRun
* module-specific config directive.
*/
BEGINafterRun
- /* place any variables needed here */
CODESTARTafterRun
/* loop through file array and close everything that's open */
@@ -314,16 +318,19 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
/* add a new monitor */
-static rsRetVal addMonitor(void __attribute__((unused)) *pVal, uchar *pNewVal)
+static rsRetVal addMonitor(void __attribute__((unused)) *pVal, uchar __attribute__((unused)) *pNewVal)
{
DEFiRet;
fileInfo_t *pThis;
+RUNLOG_VAR("%d", iFilPtr);
if(iFilPtr < MAX_INPUT_FILES) {
pThis = &files[iFilPtr];
++iFilPtr;
+ /* TODO: check for strdup() NULL return */
pThis->pszFileName = (uchar*) strdup((char*) pszFileName);
pThis->pszTag = (uchar*) strdup((char*) pszFileTag);
+ pThis->pszStateFile = (uchar*) strdup((char*) pszStateFile);
pThis->iSeverity = iSeverity;
pThis->iFacility = iFacility;
pThis->offsLast = 0;