summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-09-24 13:32:25 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-09-24 13:32:25 +0000
commitb1ca6a351c18f38b9b6fb1b18347a099ae41ef18 (patch)
tree4fa21767d72ff73c1288e1497885a85c306fa8a8
parent7fc7824b866ef7657ba52e8d7bc806d981d73811 (diff)
downloadrsyslog-b1ca6a351c18f38b9b6fb1b18347a099ae41ef18.tar.gz
rsyslog-b1ca6a351c18f38b9b6fb1b18347a099ae41ef18.tar.xz
rsyslog-b1ca6a351c18f38b9b6fb1b18347a099ae41ef18.zip
- simplified code in shouldProcessThisMessage() for debug output
- changed strerror() calls to thread-safe strerror_r() variant
-rw-r--r--configure.ac2
-rw-r--r--net.c5
-rw-r--r--omfwd.c9
-rw-r--r--pidfile.c8
-rw-r--r--rfc3195d.c14
-rw-r--r--syslogd.c46
6 files changed, 48 insertions, 36 deletions
diff --git a/configure.ac b/configure.ac
index aae19485..4bd48eb9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -66,7 +66,7 @@ AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_FUNC_VPRINTF
AC_FUNC_WAIT3
-AC_CHECK_FUNCS([setsid alarm gethostbyname gethostname gettimeofday memset regcomp select socket strcasecmp strchr strerror strndup strnlen strrchr strstr strtol strtoul uname])
+AC_CHECK_FUNCS([setsid alarm gethostbyname gethostname gettimeofday memset regcomp select socket strcasecmp strchr strerror strerror_r strndup strnlen strrchr strstr strtol strtoul uname])
# Large file support
diff --git a/net.c b/net.c
index ee2c0d9d..bcefad41 100644
--- a/net.c
+++ b/net.c
@@ -65,8 +65,9 @@ int should_use_so_bsdcompat(void)
init_done = 1;
if (uname(&utsname) < 0) {
- dbgprintf("uname: %s\r\n", strerror(errno));
- return 1;
+ char errStr[1024];
+ dbgprintf("uname: %s\r\n", strerror_r(errno, errStr, sizeof(errStr)));
+ return 1;
}
/* Format is <version>.<patchlevel>.<sublevel><extraversion>
where the first three are unsigned integers and the last
diff --git a/omfwd.c b/omfwd.c
index b7a7b025..07ff7ac2 100644
--- a/omfwd.c
+++ b/omfwd.c
@@ -232,8 +232,9 @@ static int TCPSendCreateSocket(instanceData *pData, struct addrinfo *addrDest)
TCPSendSetStatus(pData, TCP_SEND_CONNECTING);
return fd;
} else {
+ char errStr[1024];
dbgprintf("create tcp connection failed, reason %s",
- strerror(errno));
+ strerror_r(errno, errStr, sizeof(errStr)));
}
}
@@ -244,7 +245,8 @@ static int TCPSendCreateSocket(instanceData *pData, struct addrinfo *addrDest)
close(fd);
}
else {
- dbgprintf("couldn't create send socket, reason %s", strerror(errno));
+ char errStr[1024];
+ dbgprintf("couldn't create send socket, reason %s", strerror_r(errno, errStr, sizeof(errStr)));
}
r = r->ai_next;
}
@@ -682,8 +684,9 @@ CODESTARTdoAction
break;
} else {
int eno = errno;
+ char errStr[1024];
dbgprintf("sendto() error: %d = %s.\n",
- eno, strerror(eno));
+ eno, strerror_r(eno, errStr, sizeof(errStr)));
}
}
if (lsent == l && !send_to_all)
diff --git a/pidfile.c b/pidfile.c
index 8ab6f822..d2cd230f 100644
--- a/pidfile.c
+++ b/pidfile.c
@@ -21,6 +21,8 @@
#include "config.h"
+#include "rsyslog.h"
+
/*
* Sat Aug 19 13:24:33 MET DST 1995: Martin Schulze
* First version (v0.2) released
@@ -117,7 +119,8 @@ int write_pid (char *pidfile)
pid = getpid();
if (!fprintf(f,"%d\n", pid)) {
- printf("Can't write pid , %s.\n", strerror(errno));
+ char errStr[1024];
+ printf("Can't write pid , %s.\n", strerror_r(errno, errStr, sizeof(errStr)));
close(fd);
return 0;
}
@@ -125,7 +128,8 @@ int write_pid (char *pidfile)
#ifndef __sun
if (flock(fd, LOCK_UN) == -1) {
- printf("Can't unlock pidfile %s, %s.\n", pidfile, strerror(errno));
+ char errStr[1024];
+ printf("Can't unlock pidfile %s, %s.\n", pidfile, strerror_r(errno, errStr, sizeof(errStr)));
close(fd);
return 0;
}
diff --git a/rfc3195d.c b/rfc3195d.c
index 5a7366be..b44550d2 100644
--- a/rfc3195d.c
+++ b/rfc3195d.c
@@ -93,17 +93,20 @@ static void openlog()
strncpy(SyslogAddr.sa_data, pPathLogname,
sizeof(SyslogAddr.sa_data));
LogFile = socket(AF_UNIX, SOCK_DGRAM, 0);
- if(LogFile < 0)
+ if(LogFile < 0) {
+ char errStr[1024];
printf("error opening '%s': %s\n",
- pPathLogname, strerror(errno));
+ pPathLogname, strerror_r(errno, errStr, sizeof(errStr)));
+ }
}
if (LogFile != -1 && !connected &&
connect(LogFile, &SyslogAddr, sizeof(SyslogAddr.sa_family)+
strlen(SyslogAddr.sa_data)) != -1)
connected = 1;
- else
+ else {
printf("error connecting '%s': %s\n",
- pPathLogname, strerror(errno));
+ pPathLogname, strerror_r(errno, errStr, sizeof(errStr)));
+ }
}
@@ -157,7 +160,8 @@ void OnReceive(srAPIObj* pAPI, srSLMGObj* pSLMG)
nWritten = write(LogFile, pszRawMsg, strlen(pszRawMsg));
if(nWritten < 0) {
/* error, recover! */
- printf("error writing to domain socket: %s\r\n", strerror(errno));
+ char errStr[1024];
+ printf("error writing to domain socket: %s\r\n", strerror_r(errno, errStr, sizeof(errStr)));
closelog();
} else {
/* prepare for (potential) next write */
diff --git a/syslogd.c b/syslogd.c
index b919dc9e..58e6a112 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -2289,13 +2289,12 @@ static void logmsgInternal(int pri, char *msg, int flags)
#endif
}
-/*
- * This functions looks at the given message and checks if it matches the
+/* This functions looks at the given message and checks if it matches the
* provided filter condition. If so, it returns true, else it returns
* false. This is a helper to logmsg() and meant to drive the decision
* process if a message is to be processed or not. As I expect this
* decision code to grow more complex over time AND logmsg() is already
- * a very lengthe function, I thought a separate function is more appropriate.
+ * a very lengthy function, I thought a separate function is more appropriate.
* 2005-09-19 rgerhards
*/
int shouldProcessThisMessage(selector_t *f, msg_t *pMsg)
@@ -2398,27 +2397,21 @@ int shouldProcessThisMessage(selector_t *f, msg_t *pMsg)
if(f->f_filterData.prop.isNegated)
iRet = (iRet == 1) ? 0 : 1;
- /* cleanup */
- if(pbMustBeFreed)
- free(pszPropVal);
-
if(Debug) {
- char *pszPropValDeb;
- unsigned short pbMustBeFreedDeb;
- pszPropValDeb = MsgGetProp(pMsg, NULL,
- f->f_filterData.prop.pCSPropName, &pbMustBeFreedDeb);
printf("Filter: check for property '%s' (value '%s') ",
rsCStrGetSzStrNoNULL(f->f_filterData.prop.pCSPropName),
- pszPropValDeb);
+ pszPropVal);
if(f->f_filterData.prop.isNegated)
printf("NOT ");
printf("%s '%s': %s\n",
getFIOPName(f->f_filterData.prop.operation),
rsCStrGetSzStrNoNULL(f->f_filterData.prop.pCSCompValue),
iRet ? "TRUE" : "FALSE");
- if(pbMustBeFreedDeb)
- free(pszPropValDeb);
}
+
+ /* cleanup */
+ if(pbMustBeFreed)
+ free(pszPropVal);
}
return(iRet);
@@ -2475,7 +2468,7 @@ static rsRetVal callAction(msg_t *pMsg, action_t *pAction)
ABORT_FINALIZE(RS_RET_OK);
}
- /* suppress duplicate lines to this file
+ /* suppress duplicate messages
*/
if ((pAction->f_ReduceRepeated == 1) && pAction->f_pMsg != NULL &&
(pMsg->msgFlags & MARK) == 0 && getMSGLen(pMsg) == getMSGLen(pAction->f_pMsg) &&
@@ -2493,7 +2486,7 @@ static rsRetVal callAction(msg_t *pMsg, action_t *pAction)
BACKOFF(pAction);
}
} else {
- /* new line, save it */
+ /* new message, save it */
/* first check if we have a previous message stored
* if so, emit and then discard it first
*/
@@ -2526,7 +2519,7 @@ typedef struct processMsgDoActions_s {
DEFFUNC_llExecFunc(processMsgDoActions)
{
DEFiRet;
- rsRetVal iRetMod; /* return of module - we do not always pass that */
+ rsRetVal iRetMod; /* return value of module - we do not always pass that back */
action_t *pAction = (action_t*) pData;
processMsgDoActions_t *pDoActData = (processMsgDoActions_t*) pParam;
@@ -3330,6 +3323,9 @@ rsRetVal fprintlog(action_t *pAction)
/* it failed - nothing we can do against it... */
dbgprintf("Message duplication failed, dropping repeat message.\n");
return RS_RET_ERR;
+ /* This return is OK. The finalizer frees strings, which are not
+ * yet allocated. So we can not use the finalizer.
+ */
}
/* We now need to update the other message properties.
@@ -3540,13 +3536,14 @@ void logerrorInt(char *type, int errCode)
void logerror(char *type)
{
char buf[1024];
+ char errStr[1024];
dbgprintf("Called logerr, msg: %s\n", type);
if (errno == 0)
snprintf(buf, sizeof(buf), "%s", type);
else
- snprintf(buf, sizeof(buf), "%s: %s", type, strerror(errno));
+ snprintf(buf, sizeof(buf), "%s: %s", type, strerror_r(errno, errStr, sizeof(errStr)));
buf[sizeof(buf)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */
errno = 0;
logmsgInternal(LOG_SYSLOG|LOG_ERR, buf, ADDDATE);
@@ -4270,10 +4267,11 @@ static rsRetVal processConfFile(uchar *pConfFile)
finalize_it:
if(iRet != RS_RET_OK) {
+ char errStr[1024];
if(fCurr != NULL)
selectorDestruct(fCurr);
dbgprintf("error %d processing config file '%s'; os error (if any): %s\n",
- iRet, pConfFile, strerror(errno));
+ iRet, pConfFile, strerror_r(errno, errStr, sizeof(errStr)));
}
return iRet;
}
@@ -4615,7 +4613,7 @@ static rsRetVal cflineProcessTradPRIFilter(uchar **pline, register selector_t *f
assert(f != NULL);
dbgprintf(" - traditional PRI filter\n");
- errno = 0; /* keep strerror() stuff out of logerror messages */
+ errno = 0; /* keep strerror_r() stuff out of logerror messages */
f->f_filter_type = FILTER_PRI;
/* Note: file structure is pre-initialized to zero because it was
@@ -4774,7 +4772,7 @@ static rsRetVal cflineProcessPropFilter(uchar **pline, register selector_t *f)
assert(f != NULL);
dbgprintf(" - property-based filter\n");
- errno = 0; /* keep strerror() stuff out of logerror messages */
+ errno = 0; /* keep strerror_r() stuff out of logerror messages */
f->f_filter_type = FILTER_PROP;
@@ -5627,8 +5625,9 @@ static rsRetVal processSelectAfter(int maxfds, int nfds, fd_set *pReadfds, fd_se
if (iRcvd > 0) {
printchopped(LocalHostName, line, iRcvd, fd, funixParseHost[i]);
} else if (iRcvd < 0 && errno != EINTR) {
+ char errStr[1024];
dbgprintf("UNIX socket error: %d = %s.\n", \
- errno, strerror(errno));
+ errno, strerror_r(errno, errStr, sizeof(errStr)));
logerror("recvfrom UNIX");
}
FDPROCESSED();
@@ -5665,8 +5664,9 @@ static rsRetVal processSelectAfter(int maxfds, int nfds, fd_set *pReadfds, fd_se
}
}
} else if (l < 0 && errno != EINTR && errno != EAGAIN) {
+ char errStr[1024];
dbgprintf("INET socket error: %d = %s.\n",
- errno, strerror(errno));
+ errno, strerror_r(errno, errStr, sizeof(errStr)));
logerror("recvfrom inet");
/* should be harmless */
sleep(1);