diff options
-rw-r--r-- | net.c | 1 | ||||
-rw-r--r-- | pidfile.c | 7 | ||||
-rw-r--r-- | plugins/imudp/imudp.c | 3 | ||||
-rw-r--r-- | plugins/imuxsock/imuxsock.c | 3 | ||||
-rwxr-xr-x | srUtils.c | 31 | ||||
-rwxr-xr-x | srUtils.h | 1 | ||||
-rw-r--r-- | syslogd.c | 15 | ||||
-rw-r--r-- | syslogd.h | 1 | ||||
-rw-r--r-- | tcpsyslog.c | 1 |
9 files changed, 43 insertions, 20 deletions
@@ -53,6 +53,7 @@ #include "syslogd-types.h" #include "net.h" #include "parse.h" +#include "srUtils.h" /* support for defining allowed TCP and UDP senders. We use the same * structure to implement this (a linked list), but we define two different @@ -23,6 +23,7 @@ #include "rsyslog.h" +#include "syslogd.h" /* * Sat Aug 19 13:24:33 MET DST 1995: Martin Schulze @@ -40,6 +41,8 @@ #include <fcntl.h> #endif +#include "srUtils.h" + /* read_pid * * Reads the specified pidfile and returns the read pid. @@ -121,7 +124,7 @@ int write_pid (char *pidfile) pid = getpid(); if (!fprintf(f,"%d\n", pid)) { char errStr[1024]; - strerror_r(errno, errStr, sizeof(errStr)); + rs_strerror_r(errno, errStr, sizeof(errStr)); printf("Can't write pid , %s.\n", errStr); close(fd); return 0; @@ -131,7 +134,7 @@ int write_pid (char *pidfile) #ifndef __sun if (flock(fd, LOCK_UN) == -1) { char errStr[1024]; - strerror_r(errno, errStr, sizeof(errStr)); + rs_strerror_r(errno, errStr, sizeof(errStr)); printf("Can't unlock pidfile %s, %s.\n", pidfile, errStr); close(fd); return 0; diff --git a/plugins/imudp/imudp.c b/plugins/imudp/imudp.c index d68e3772..fa9db53a 100644 --- a/plugins/imudp/imudp.c +++ b/plugins/imudp/imudp.c @@ -37,6 +37,7 @@ #include "net.h" #include "cfsysline.h" #include "module-template.h" +#include "srUtils.h" MODULE_TYPE_INPUT @@ -200,7 +201,7 @@ CODESTARTrunInput } } else if (l < 0 && errno != EINTR && errno != EAGAIN) { char errStr[1024]; - strerror_r(errno, errStr, sizeof(errStr)); + rs_strerror_r(errno, errStr, sizeof(errStr)); dbgprintf("INET socket error: %d = %s.\n", errno, errStr); logerror("recvfrom inet"); /* should be harmless */ diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c index 530bb2d4..54bbe039 100644 --- a/plugins/imuxsock/imuxsock.c +++ b/plugins/imuxsock/imuxsock.c @@ -38,6 +38,7 @@ #include "syslogd.h" #include "cfsysline.h" #include "module-template.h" +#include "srUtils.h" MODULE_TYPE_INPUT @@ -169,7 +170,7 @@ static rsRetVal readSocket(int fd, int bParseHost) printchopped(LocalHostName, line, iRcvd, fd, bParseHost); } else if (iRcvd < 0 && errno != EINTR) { char errStr[1024]; - strerror_r(errno, errStr, sizeof(errStr)); + rs_strerror_r(errno, errStr, sizeof(errStr)); dbgprintf("UNIX socket error: %d = %s.\n", errno, errStr); logerror("recvfrom UNIX"); } @@ -389,6 +389,37 @@ srSleep(int iSeconds, int iuSeconds) select(0, NULL, NULL, NULL, &tvSelectTimeout); ENDfunc } + + +/* From varmojfekoj's mail on why he provided rs_strerror_r(): + * There are two problems with strerror_r(): + * I see you've rewritten some of the code which calls it to use only + * the supplied buffer; unfortunately the GNU implementation sometimes + * doesn't use the buffer at all and returns a pointer to some + * immutable string instead, as noted in the man page. + * + * The other problem is that on some systems strerror_r() has a return + * type of int. + * + * So I've written a wrapper function rs_strerror_r(), which should + * take care of all this and be used instead. + * + * Added 2008-01-30 + */ +char *rs_strerror_r(int errnum, char *buf, size_t buflen) { +#ifdef STRERROR_R_CHAR_P + char *p = strerror_r(errnum, buf, buflen); + if (p != buf) { + strncpy(buf, p, buflen); + buf[buflen - 1] = '\0'; + } +#else + strerror_r(errnum, buf, buflen); +#endif + return buf; +} + + /* * vi:set ai: */ @@ -70,6 +70,7 @@ rsRetVal timeoutComp(struct timespec *pt, long iTimeout); long timeoutVal(struct timespec *pt); void mutexCancelCleanup(void *arg); void srSleep(int iSeconds, int iuSeconds); +char *rs_strerror_r(int errnum, char *buf, size_t buflen); /* mutex operations */ /* some macros to cancel-safe lock a mutex (it will automatically be released @@ -4132,21 +4132,6 @@ int decode(uchar *name, struct code *codetab) } - -char *rs_strerror_r(int errnum, char *buf, size_t buflen) { -#ifdef STRERROR_R_CHAR_P - char *p = strerror_r(errnum, buf, buflen); - if (p != buf) { - strncpy(buf, p, buflen); - buf[buflen - 1] = '\0'; - } -#else - strerror_r(errnum, buf, buflen); -#endif - return buf; -} - - /* * The following function is resposible for handling a SIGHUP signal. Since * we are now doing mallocs/free as part of init we had better not being @@ -49,7 +49,6 @@ #define ADDDATE 0x004 /* add a date to the message */ #define MARK 0x008 /* this message is a mark */ -char *rs_strerror_r(int errnum, char *buf, size_t buflen); void logerror(char *type); void logerrorSz(char *type, char *errMsg); void logerrorInt(char *type, int iErr); diff --git a/tcpsyslog.c b/tcpsyslog.c index 0674f669..f8620e38 100644 --- a/tcpsyslog.c +++ b/tcpsyslog.c @@ -53,6 +53,7 @@ #include "gss-misc.h" #endif #include "tcpsyslog.h" +#include "srUtils.h" /******************************************************************** * ### SYSLOG/TCP CODE ### * This is code for syslog/tcp. This code would belong to a separate |