summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-01-30 13:48:56 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-01-30 13:48:56 +0000
commit3896b8c5fe0b0058310a8135660fb74822a89ede (patch)
tree3ebef1a4cdf4db55bc0701de902b8214cbd04ac1
parent2dd6d08b5d4ec053095d532dc1540f6630553c9b (diff)
downloadrsyslog-3896b8c5fe0b0058310a8135660fb74822a89ede.tar.gz
rsyslog-3896b8c5fe0b0058310a8135660fb74822a89ede.tar.xz
rsyslog-3896b8c5fe0b0058310a8135660fb74822a89ede.zip
one more strerror_r fix ;)
-rw-r--r--pidfile.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/pidfile.c b/pidfile.c
index e153a4ed..a0b41579 100644
--- a/pidfile.c
+++ b/pidfile.c
@@ -39,6 +39,21 @@
#include <fcntl.h>
#endif
+
+static 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;
+}
+
+
/* read_pid
*
* Reads the specified pidfile and returns the read pid.
@@ -120,7 +135,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;
@@ -130,7 +145,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;