summaryrefslogtreecommitdiffstats
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
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)
-rw-r--r--debug.c6
-rw-r--r--plugins/imfile/imfile.c33
-rw-r--r--stream.c12
-rw-r--r--stream.h1
-rw-r--r--syslogd.c24
-rw-r--r--syslogd.h1
6 files changed, 51 insertions, 26 deletions
diff --git a/debug.c b/debug.c
index d634b247..74794e7f 100644
--- a/debug.c
+++ b/debug.c
@@ -58,6 +58,7 @@ static dbgThrdInfo_t *dbgGetThrdInfo(void);
int Debug; /* debug flag - read-only after startup */
int debugging_on = 0; /* read-only, except on sig USR1 */
static int bLogFuncFlow = 0; /* shall the function entry and exit be logged to the debug log? */
+static int bLogAllocFree = 0; /* shall calls to (m/c)alloc and free be logged to the debug log? */
static int bPrintFuncDBOnExit = 0; /* shall the function entry and exit be logged to the debug log? */
static int bPrintMutexAction = 0; /* shall mutex calls be printed to the debug log? */
static int bPrintTime = 1; /* print a timestamp together with debug message */
@@ -554,8 +555,9 @@ int dbgCondTimedWait(pthread_cond_t *cond, pthread_mutex_t *pmut, const struct t
void dbgFree(void *pMem, dbgFuncDB_t *pFuncDB, int ln, int iStackPtr)
{
dbgRecordExecLocation(iStackPtr, ln);
- dbgprintf("%s:%d:%s: free %p\n", pFuncDB->file,
- ln, pFuncDB->func, (void*) pMem);
+ if(bLogAllocFree) {
+ dbgprintf("%s:%d:%s: free %p\n", pFuncDB->file, ln, pFuncDB->func, (void*) pMem);
+ }
free(pMem);
}
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;
diff --git a/stream.c b/stream.c
index 40a4e8ce..94080358 100644
--- a/stream.c
+++ b/stream.c
@@ -249,18 +249,14 @@ rsRetVal strmUnreadChar(strm_t *pThis, uchar c)
return RS_RET_OK;
}
-#if 0
-/* we have commented out the code below because we would like to preserve it. It
- * is currently not needed, but may be useful if we implemented a bufferred file
- * class. NOTE: YOU MUST REVIEW THIS CODE BEFORE ACTIVATION. It may be pretty
- * outdated! -- rgerhards, 2008-01-10
- */
+
/* read a line from a strm file. A line is terminated by LF. The LF is read, but it
* is not returned in the buffer (it is discared). The caller is responsible for
* destruction of the returned CStr object!
* rgerhards, 2008-01-07
*/
-static rsRetVal strmReadLine(strm_t *pThis, rsCStrObj **ppCStr)
+rsRetVal
+strmReadLine(strm_t *pThis, rsCStrObj **ppCStr)
{
DEFiRet;
uchar c;
@@ -288,8 +284,6 @@ finalize_it:
RETiRet;
}
-#endif /* #if 0 - saved code */
-
/* Standard-Constructor for the strm object
*/
diff --git a/stream.h b/stream.h
index 579514bf..423ab492 100644
--- a/stream.h
+++ b/stream.h
@@ -96,6 +96,7 @@ rsRetVal strmSetMaxFileSize(strm_t *pThis, int64 iMaxFileSize);
rsRetVal strmSetFileName(strm_t *pThis, uchar *pszName, size_t iLenName);
rsRetVal strmReadChar(strm_t *pThis, uchar *pC);
rsRetVal strmUnreadChar(strm_t *pThis, uchar c);
+rsRetVal strmReadLine(strm_t *pThis, rsCStrObj **ppCStr);
rsRetVal strmSeekCurrOffs(strm_t *pThis);
rsRetVal strmWrite(strm_t *pThis, uchar *pBuf, size_t lenBuf);
rsRetVal strmWriteChar(strm_t *pThis, uchar c);
diff --git a/syslogd.c b/syslogd.c
index bb4cda87..fa364d4d 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -2131,6 +2131,27 @@ static int parseLegacySyslogMsg(msg_t *pMsg, int flags)
}
+/* submit a fully created message to the main message queue. The message is
+ * fully processed and parsed, so no parsing at all happens. This is primarily
+ * a hook to prevent the need for callers to know about the main message queue
+ * (which may change in the future as we will probably have multiple rule
+ * sets and thus queues...).
+ * rgerhards, 2008-02-13
+ */
+rsRetVal
+submitMsg(msg_t *pMsg)
+{
+ DEFiRet;
+
+ ISOBJ_TYPE_assert(pMsg, msg);
+
+ MsgPrepareEnqueue(pMsg);
+ queueEnqObj(pMsgQueue, (void*) pMsg);
+
+ RETiRet;
+}
+
+
/*
* Log a message to the appropriate log files, users, etc. based on
* the priority.
@@ -4869,6 +4890,5 @@ int main(int argc, char **argv)
}
-/*
- * vi:set ai:
+/* vim:set ai:
*/
diff --git a/syslogd.h b/syslogd.h
index 8bfcc5c7..43a95ae5 100644
--- a/syslogd.h
+++ b/syslogd.h
@@ -71,6 +71,7 @@ int getSubString(uchar **ppSrc, char *pDst, size_t DstSize, char cSep);
*/
rsRetVal logmsgInternal(int pri, char *msg, int flags);
void logmsg(msg_t *pMsg, int flags);
+rsRetVal submitMsg(msg_t *pMsg);
extern int glblHadMemShortage; /* indicates if we had memory shortage some time during the run */
extern char LocalHostName[];
extern int family;