summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-06-22 18:19:38 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-06-22 18:19:38 +0200
commit55ead69efa550cbdff11656cb11c4a50439e7749 (patch)
treebcaa7ca5c2998d0bd363cda380d9aab8e3a2a6e4
parent412b7d7df683df5205cf545f248a4fc55478e124 (diff)
parent221dc8a3224dcb59a7dd3158716a8d24cee71618 (diff)
downloadrsyslog-55ead69efa550cbdff11656cb11c4a50439e7749.tar.gz
rsyslog-55ead69efa550cbdff11656cb11c4a50439e7749.tar.xz
rsyslog-55ead69efa550cbdff11656cb11c4a50439e7749.zip
Merge branch 'omfile' into v5-devel
-rw-r--r--runtime/datetime.c5
-rw-r--r--runtime/datetime.h2
-rw-r--r--runtime/msg.c37
-rw-r--r--runtime/msg.h41
4 files changed, 40 insertions, 45 deletions
diff --git a/runtime/datetime.c b/runtime/datetime.c
index a1ba164e..069cf55c 100644
--- a/runtime/datetime.c
+++ b/runtime/datetime.c
@@ -616,10 +616,10 @@ int formatTimestampToPgSQL(struct syslogTime *ts, char *pBuf, size_t iLenDst)
* buffer that will receive the resulting string. The function
* returns the size of the timestamp written in bytes (without
* the string terminator). If 0 is returend, an error occured.
- * The buffer must be at least 10 bytes large.
+ * The buffer must be at least 7 bytes large.
* rgerhards, 2008-06-06
*/
-int formatTimestampSecFrac(struct syslogTime *ts, char* pBuf, size_t iLenBuf)
+int formatTimestampSecFrac(struct syslogTime *ts, char* pBuf)
{
int iBuf;
int power;
@@ -628,7 +628,6 @@ int formatTimestampSecFrac(struct syslogTime *ts, char* pBuf, size_t iLenBuf)
assert(ts != NULL);
assert(pBuf != NULL);
- assert(iLenBuf >= 10);
iBuf = 0;
if(ts->secfracPrecision > 0)
diff --git a/runtime/datetime.h b/runtime/datetime.h
index efb0a0af..1ea99aba 100644
--- a/runtime/datetime.h
+++ b/runtime/datetime.h
@@ -42,7 +42,7 @@ BEGINinterface(datetime) /* name must also be changed in ENDinterface macro! */
int (*formatTimestampToPgSQL)(struct syslogTime *ts, char *pDst, size_t iLenDst);
int (*formatTimestamp3339)(struct syslogTime *ts, char* pBuf, size_t iLenBuf);
int (*formatTimestamp3164)(struct syslogTime *ts, char* pBuf, size_t iLenBuf);
- int (*formatTimestampSecFrac)(struct syslogTime *ts, char* pBuf, size_t iLenBuf);
+ int (*formatTimestampSecFrac)(struct syslogTime *ts, char* pBuf);
ENDinterface(datetime)
#define datetimeCURR_IF_VERSION 2 /* increment whenever you change the interface structure! */
/* interface changes:
diff --git a/runtime/msg.c b/runtime/msg.c
index e47f104c..2ff63d9c 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -335,14 +335,15 @@ static void MsgLockingDummy(msg_t __attribute__((unused)) *pMsg)
static void MsgPrepareEnqueueLockingCase(msg_t *pThis)
{
int iErr;
+ pthread_mutexattr_t mutAttr;
BEGINfunc
assert(pThis != NULL);
- iErr = pthread_mutexattr_init(&pThis->mutAttr);
+ iErr = pthread_mutexattr_init(&mutAttr);
if(iErr != 0) {
dbgprintf("error initializing mutex attribute in %s:%d, trying to continue\n",
__FILE__, __LINE__);
}
- iErr = pthread_mutexattr_settype(&pThis->mutAttr, PTHREAD_MUTEX_RECURSIVE);
+ iErr = pthread_mutexattr_settype(&mutAttr, PTHREAD_MUTEX_RECURSIVE);
if(iErr != 0) {
dbgprintf("ERROR setting mutex attribute to recursive in %s:%d, trying to continue "
"but we will probably either abort or hang soon\n",
@@ -352,14 +353,14 @@ static void MsgPrepareEnqueueLockingCase(msg_t *pThis)
* down. We should do that over time. -- rgerhards, 2008-07-14
*/
}
- pthread_mutex_init(&pThis->mut, &pThis->mutAttr);
+ pthread_mutex_init(&pThis->mut, &mutAttr);
/* we do no longer need the attribute. According to the
* POSIX spec, we can destroy it without affecting the
* initialized mutex (that used the attribute).
* rgerhards, 2008-07-14
*/
- pthread_mutexattr_destroy(&pThis->mutAttr);
+ pthread_mutexattr_destroy(&mutAttr);
pThis->bDoLock = 1;
ENDfunc
}
@@ -531,10 +532,8 @@ CODESTARTobjDestruct(msg)
free(pThis->pszRcvFromIP);
free(pThis->pszRcvdAt3164);
free(pThis->pszRcvdAt3339);
- free(pThis->pszRcvdAt_SecFrac);
free(pThis->pszRcvdAt_MySQL);
free(pThis->pszRcvdAt_PgSQL);
- free(pThis->pszTIMESTAMP_SecFrac);
free(pThis->pszTIMESTAMP_MySQL);
free(pThis->pszTIMESTAMP_PgSQL);
if(pThis->pCSProgName != NULL)
@@ -1007,15 +1006,14 @@ static inline char *getTimeReported(msg_t *pM, enum tplFormatTypes eFmt)
MsgUnlock(pM);
return(pM->pszTIMESTAMP3339);
case tplFmtSecFrac:
- MsgLock(pM);
- if(pM->pszTIMESTAMP_SecFrac == NULL) {
- if((pM->pszTIMESTAMP_SecFrac = malloc(10)) == NULL) {
- MsgUnlock(pM);
- return ""; /* TODO: check this: can it cause a free() of constant memory?) */
+ if(pM->pszTIMESTAMP_SecFrac[0] == '\0') {
+ MsgLock(pM);
+ /* re-check, may have changed while we did not hold lock */
+ if(pM->pszTIMESTAMP_SecFrac[0] == '\0') {
+ datetime.formatTimestampSecFrac(&pM->tTIMESTAMP, pM->pszTIMESTAMP_SecFrac);
}
- datetime.formatTimestampSecFrac(&pM->tTIMESTAMP, pM->pszTIMESTAMP_SecFrac, 10);
+ MsgUnlock(pM);
}
- MsgUnlock(pM);
return(pM->pszTIMESTAMP_SecFrac);
}
ENDfunc
@@ -1085,15 +1083,14 @@ static inline char *getTimeGenerated(msg_t *pM, enum tplFormatTypes eFmt)
MsgUnlock(pM);
return(pM->pszRcvdAt3339);
case tplFmtSecFrac:
- MsgLock(pM);
- if(pM->pszRcvdAt_SecFrac == NULL) {
- if((pM->pszRcvdAt_SecFrac = malloc(10)) == NULL) {
- MsgUnlock(pM);
- return ""; /* TODO: check this: can it cause a free() of constant memory?) */
+ if(pM->pszRcvdAt_SecFrac[0] == '\0') {
+ MsgLock(pM);
+ /* re-check, may have changed while we did not hold lock */
+ if(pM->pszRcvdAt_SecFrac[0] == '\0') {
+ datetime.formatTimestampSecFrac(&pM->tRcvdAt, pM->pszRcvdAt_SecFrac);
}
- datetime.formatTimestampSecFrac(&pM->tRcvdAt, pM->pszRcvdAt_SecFrac, 10);
+ MsgUnlock(pM);
}
- MsgUnlock(pM);
return(pM->pszRcvdAt_SecFrac);
}
ENDfunc
diff --git a/runtime/msg.h b/runtime/msg.h
index ec18b29d..34983704 100644
--- a/runtime/msg.h
+++ b/runtime/msg.h
@@ -56,7 +56,6 @@ struct msg {
BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
flowControl_t flowCtlType; /**< type of flow control we can apply, for enqueueing, needs not to be persisted because
once data has entered the queue, this property is no longer needed. */
- pthread_mutexattr_t mutAttr;
pthread_mutex_t mut;
bool bDoLock; /* use the mutex? */
bool bParseHOSTNAME; /* should the hostname be parsed from the message? */
@@ -69,27 +68,37 @@ struct msg {
*/
short iSeverity; /* the severity 0..7 */
short iFacility; /* Facility code 0 .. 23*/
- uchar *pszRawMsg; /* message as it was received on the wire. This is important in case we
- * need to preserve cryptographic verifiers. */
- int iLenRawMsg; /* length of raw message */
short offAfterPRI; /* offset, at which raw message WITHOUT PRI part starts in pszRawMsg */
short offMSG; /* offset at which the MSG part starts in pszRawMsg */
+ short iLenInputName; /* Length of pszInputName */
+ short iProtocolVersion;/* protocol version of message received 0 - legacy, 1 syslog-protocol) */
+ int msgFlags; /* flags associated with this message */
+ int iLenRawMsg; /* length of raw message */
int iLenMSG; /* Length of the MSG part */
int iLenTAG; /* Length of the TAG part */
- uchar *pszHOSTNAME; /* HOSTNAME from syslog message */
int iLenHOSTNAME; /* Length of HOSTNAME */
- uchar *pszRcvFrom; /* System message was received from */
int iLenRcvFrom; /* Length of pszRcvFrom */
- uchar *pszRcvFromIP; /* IP of system message was received from */
int iLenRcvFromIP; /* Length of pszRcvFromIP */
+ uchar *pszRawMsg; /* message as it was received on the wire. This is important in case we
+ * need to preserve cryptographic verifiers. */
+ uchar *pszHOSTNAME; /* HOSTNAME from syslog message */
+ uchar *pszRcvFrom; /* System message was received from */
+ uchar *pszRcvFromIP; /* IP of system message was received from */
uchar *pszInputName; /* name of the input module that submitted this message */
- int iLenInputName; /* Length of pszInputName */
- short iProtocolVersion;/* protocol version of message received 0 - legacy, 1 syslog-protocol) */
+ char *pszRcvdAt3164; /* time as RFC3164 formatted string (always 15 charcters) */
+ char *pszRcvdAt3339; /* time as RFC3164 formatted string (32 charcters at most) */
+ char *pszRcvdAt_MySQL; /* rcvdAt as MySQL formatted string (always 14 charcters) */
+ char *pszRcvdAt_PgSQL; /* rcvdAt as PgSQL formatted string (always 21 characters) */
+ char *pszTIMESTAMP3164; /* TIMESTAMP as RFC3164 formatted string (always 15 charcters) */
+ char *pszTIMESTAMP3339; /* TIMESTAMP as RFC3339 formatted string (32 charcters at most) */
+ char *pszTIMESTAMP_MySQL;/* TIMESTAMP as MySQL formatted string (always 14 charcters) */
+ char *pszTIMESTAMP_PgSQL;/* TIMESTAMP as PgSQL formatted string (always 21 characters) */
cstr_t *pCSProgName; /* the (BSD) program name */
cstr_t *pCSStrucData; /* STRUCTURED-DATA */
cstr_t *pCSAPPNAME; /* APP-NAME */
cstr_t *pCSPROCID; /* PROCID */
cstr_t *pCSMSGID; /* MSGID */
+ ruleset_t *pRuleset; /* ruleset to be used for processing this message */
time_t ttGenTime; /* time msg object was generated, same as tRcvdAt, but a Unix timestamp.
While this field looks redundant, it is required because a Unix timestamp
is used at later processing stages (namely in the output arena). Thanks to
@@ -98,19 +107,7 @@ struct msg {
enough to reliable, but I prefer to leave the subtle things to the OS, where
it obviously is solved in way or another...). */
struct syslogTime tRcvdAt;/* time the message entered this program */
- char *pszRcvdAt3164; /* time as RFC3164 formatted string (always 15 charcters) */
- char *pszRcvdAt3339; /* time as RFC3164 formatted string (32 charcters at most) */
- char *pszRcvdAt_SecFrac;/* time just as fractional seconds (6 charcters) */
- char *pszRcvdAt_MySQL; /* rcvdAt as MySQL formatted string (always 14 charcters) */
- char *pszRcvdAt_PgSQL; /* rcvdAt as PgSQL formatted string (always 21 characters) */
struct syslogTime tTIMESTAMP;/* (parsed) value of the timestamp */
- char *pszTIMESTAMP3164; /* TIMESTAMP as RFC3164 formatted string (always 15 charcters) */
- char *pszTIMESTAMP3339; /* TIMESTAMP as RFC3339 formatted string (32 charcters at most) */
- char *pszTIMESTAMP_MySQL;/* TIMESTAMP as MySQL formatted string (always 14 charcters) */
- char *pszTIMESTAMP_PgSQL;/* TIMESTAMP as PgSQL formatted string (always 21 characters) */
- char *pszTIMESTAMP_SecFrac;/* TIMESTAMP fractional seconds (always 6 characters) */
- int msgFlags; /* flags associated with this message */
- ruleset_t *pRuleset; /* ruleset to be used for processing this message */
/* some fixed-size buffers to save malloc()/free() for frequently used fields (from the default templates) */
uchar szRawMsg[CONF_RAWMSG_BUFSIZE]; /* most messages are small, and these are stored here (without malloc/free!) */
union {
@@ -119,6 +116,8 @@ struct msg {
} TAG;
char pszTimestamp3164[16];
char pszTimestamp3339[33];
+ char pszTIMESTAMP_SecFrac[7]; /* Note: a pointer is 64 bits/8 char, so this is actually fewer than a pointer! */
+ char pszRcvdAt_SecFrac[7]; /* same as above. Both are fractional seconds for their respective timestamp */
};