diff --git a/src/Makefile.am b/src/Makefile.am index 619b9399..191071e6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -62,7 +62,8 @@ dsc_SOURCES = base64.c \ xmalloc.c \ inX_addr.c \ pcap-thread/pcap_thread.c \ - parse_conf.c + parse_conf.c \ + compat.c dist_dsc_SOURCES = base64.h \ byteorder.h \ certain_qnames_index.h \ @@ -108,7 +109,8 @@ dist_dsc_SOURCES = base64.h \ pcap_layers/pcap_layers.h \ pcap-thread/pcap_thread.h \ parse_conf.h \ - config_hooks.h + config_hooks.h \ + compat.h dsc_LDADD = $(PTHREAD_LIBS) man1_MANS = dsc.1 man5_MANS = dsc.conf.5 diff --git a/src/compat.c b/src/compat.c new file mode 100644 index 00000000..bafa5ede --- /dev/null +++ b/src/compat.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016-2017, OARC, Inc. + * Copyright (c) 2007, The Measurement Factory, Inc. + * Copyright (c) 2007, Internet Systems Consortium, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "compat.h" + +#include +#include + +const char* dsc_strerror(int errnum, char* buf, size_t buflen) { + if (!buf || buflen < 2) { + return "dsc_strerror() invalid arguments"; + } + + memset(buf, 0, buflen); + +#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE + /* XSI-compliant version */ + { + int ret = strerror_r(errnum, buf, buflen); + if (ret > 0) { + (void)strerror_r(ret, buf, buflen); + } + else { + (void)strerror_r(errno, buf, buflen); + } + } +#else + /* GNU-specific version */ + buf = strerror_r(errnum, buf, buflen); +#endif + + return buf; +} diff --git a/src/compat.h b/src/compat.h new file mode 100644 index 00000000..11a167c8 --- /dev/null +++ b/src/compat.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016-2017, OARC, Inc. + * Copyright (c) 2007, The Measurement Factory, Inc. + * Copyright (c) 2007, Internet Systems Consortium, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __dsc_compat_h +#define __dsc_compat_h + +#include + +const char* dsc_strerror(int errnum, char* buf, size_t buflen); + +#endif /* __dsc_compat_h */ diff --git a/src/config_hooks.c b/src/config_hooks.c index cce92fab..a46113f2 100644 --- a/src/config_hooks.c +++ b/src/config_hooks.c @@ -47,6 +47,7 @@ #include "syslog_debug.h" #include "hashtbl.h" #include "pcap.h" +#include "compat.h" extern int promisc_flag; extern int monitor_flag; @@ -100,8 +101,9 @@ set_run_dir(const char *dir) { dsyslogf(LOG_INFO, "setting current directory to %s", dir); if (chdir(dir) < 0) { + char errbuf[512]; perror(dir); - dsyslogf(LOG_ERR, "chdir: %s: %s", dir, strerror(errno)); + dsyslogf(LOG_ERR, "chdir: %s: %s", dir, dsc_strerror(errno, errbuf, sizeof(errbuf))); return 0; } return 1; @@ -136,7 +138,8 @@ set_statistics_interval (const char *s) dsyslogf(LOG_INFO, "Setting statistics interval to: %s", s); statistics_interval = strtoull(s, NULL, 10); if (statistics_interval == ULLONG_MAX) { - dsyslogf(LOG_ERR, "strtoull: %s", strerror(errno)); + char errbuf[512]; + dsyslogf(LOG_ERR, "strtoull: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); return 0; } if (!statistics_interval) { @@ -247,51 +250,59 @@ set_dump_reports_on_exit(void) int set_geoip_v4_dat(const char * dat, int options) { + char errbuf[512]; + geoip_v4_options = options; if ( (geoip_v4_dat = strdup(dat)) ) { dsyslogf(LOG_INFO, "GeoIP v4 dat %s %d", geoip_v4_dat, geoip_v4_options); return 1; } - dsyslogf(LOG_ERR, "unable to set GeoIP v4 dat, strdup: %s", strerror(errno)); + dsyslogf(LOG_ERR, "unable to set GeoIP v4 dat, strdup: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); return 0; } int set_geoip_v6_dat(const char * dat, int options) { + char errbuf[512]; + geoip_v6_options = options; if ( (geoip_v6_dat = strdup(dat)) ) { dsyslogf(LOG_INFO, "GeoIP v6 dat %s %d", geoip_v6_dat, geoip_v6_options); return 1; } - dsyslogf(LOG_ERR, "unable to set GeoIP v6 dat, strdup: %s", strerror(errno)); + dsyslogf(LOG_ERR, "unable to set GeoIP v6 dat, strdup: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); return 0; } int set_geoip_asn_v4_dat(const char * dat, int options) { + char errbuf[512]; + geoip_asn_v4_options = options; if ( (geoip_asn_v4_dat = strdup(dat)) ) { dsyslogf(LOG_INFO, "GeoIP ASN v4 dat %s %d", geoip_asn_v4_dat, geoip_asn_v4_options); return 1; } - dsyslogf(LOG_ERR, "unable to set GeoIP ASN v4 dat, strdup: %s", strerror(errno)); + dsyslogf(LOG_ERR, "unable to set GeoIP ASN v4 dat, strdup: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); return 0; } int set_geoip_asn_v6_dat(const char * dat, int options) { + char errbuf[512]; + geoip_asn_v6_options = options; if ( (geoip_asn_v6_dat = strdup(dat)) ) { dsyslogf(LOG_INFO, "GeoIP ASN v6 dat %s %d", geoip_asn_v6_dat, geoip_asn_v6_options); return 1; } - dsyslogf(LOG_ERR, "unable to set GeoIP ASN v6 dat, strdup: %s", strerror(errno)); + dsyslogf(LOG_ERR, "unable to set GeoIP ASN v6 dat, strdup: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); return 0; } diff --git a/src/daemon.c b/src/daemon.c index 52122a25..4c1601e8 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -70,6 +70,7 @@ #include "pcap.h" #include "syslog_debug.h" #include "parse_conf.h" +#include "compat.h" char *progname = NULL; char *pid_file_name = NULL; @@ -98,16 +99,17 @@ extern uint64_t statistics_interval; void daemonize(void) { + char errbuf[512]; int fd; pid_t pid; if ((pid = fork()) < 0) { - dsyslogf(LOG_ERR, "fork failed: %s", strerror(errno)); + dsyslogf(LOG_ERR, "fork failed: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); exit(1); } if (pid > 0) exit(0); if (setsid() < 0) - dsyslogf(LOG_ERR, "setsid failed: %s", strerror(errno)); + dsyslogf(LOG_ERR, "setsid failed: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); closelog(); #ifdef TIOCNOTTY if ((fd = open("/dev/tty", O_RDWR)) >= 0) { @@ -117,7 +119,7 @@ daemonize(void) #endif fd = open("/dev/null", O_RDWR); if (fd < 0) { - dsyslogf(LOG_ERR, "/dev/null: %s\n", strerror(errno)); + dsyslogf(LOG_ERR, "/dev/null: %s\n", dsc_strerror(errno, errbuf, sizeof(errbuf))); } else { dup2(fd, 0); dup2(fd, 1); @@ -130,6 +132,7 @@ daemonize(void) void write_pid_file(void) { + char errbuf[512]; FILE *fp; int fd, flags; struct flock lock; @@ -142,7 +145,7 @@ write_pid_file(void) */ if ((fd = open(pid_file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) == -1) { - dsyslogf(LOG_ERR, "unable to open PID file %s: %s", pid_file_name, strerror(errno)); + dsyslogf(LOG_ERR, "unable to open PID file %s: %s", pid_file_name, dsc_strerror(errno, errbuf, sizeof(errbuf))); exit(2); } @@ -151,14 +154,14 @@ write_pid_file(void) */ if ((flags = fcntl(fd, F_GETFD)) == -1) { - dsyslogf(LOG_ERR, "unable to get PID file flags: %s", strerror(errno)); + dsyslogf(LOG_ERR, "unable to get PID file flags: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); exit(2); } flags |= FD_CLOEXEC; if (fcntl(fd, F_SETFD, flags) == 1) { - dsyslogf(LOG_ERR, "unable to set PID file flags: %s", strerror(errno)); + dsyslogf(LOG_ERR, "unable to set PID file flags: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); exit(2); } @@ -177,7 +180,7 @@ write_pid_file(void) exit(3); } - dsyslogf(LOG_ERR, "unable to lock PID file: %s", strerror(errno)); + dsyslogf(LOG_ERR, "unable to lock PID file: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); exit(2); } @@ -186,7 +189,7 @@ write_pid_file(void) */ if (ftruncate(fd, 0) == -1) { - dsyslogf(LOG_ERR, "unable to truncate PID file: %s", strerror(errno)); + dsyslogf(LOG_ERR, "unable to truncate PID file: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); exit(2); } @@ -194,7 +197,7 @@ write_pid_file(void) fp = fdopen(fd, "w"); if (!fp || fprintf(fp, "%d\n", getpid()) < 1 || fflush(fp)) { - dsyslogf(LOG_ERR, "unable to write to PID file: %s", strerror(errno)); + dsyslogf(LOG_ERR, "unable to write to PID file: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); exit(2); } } @@ -245,6 +248,7 @@ version(void) static int dump_report(md_array_printer * printer) { + char errbuf[512]; int fd; FILE *fp; char fname[128]; @@ -258,12 +262,12 @@ dump_report(md_array_printer * printer) snprintf(tname, 128, "%s.XXXXXXXXX", fname); fd = mkstemp(tname); if (fd < 0) { - dsyslogf(LOG_ERR, "%s: %s", tname, strerror(errno)); + dsyslogf(LOG_ERR, "%s: %s", tname, dsc_strerror(errno, errbuf, sizeof(errbuf))); return 1; } fp = fdopen(fd, "w"); if (NULL == fp) { - dsyslogf(LOG_ERR, "%s: %s", tname, strerror(errno)); + dsyslogf(LOG_ERR, "%s: %s", tname, dsc_strerror(errno, errbuf, sizeof(errbuf))); close(fd); return 1; } @@ -286,7 +290,7 @@ dump_report(md_array_printer * printer) dfprintf(0, "renaming to %s", fname); if (rename(tname, fname)) { - dsyslogf(LOG_ERR, "unable to move report from %s to %s: %s", tname, fname, strerror(errno)); + dsyslogf(LOG_ERR, "unable to move report from %s to %s: %s", tname, fname, dsc_strerror(errno, errbuf, sizeof(errbuf))); } return 0; } @@ -352,6 +356,7 @@ sig_thread(void * arg) { int main(int argc, char *argv[]) { + char errbuf[512]; int x; int result; struct timeval break_start = { 0, 0 }; @@ -362,7 +367,6 @@ main(int argc, char *argv[]) progname = xstrdup(strrchr(argv[0], '/') ? strchr(argv[0], '/') + 1 : argv[0]); if (NULL == progname) return 1; - srandom(time(NULL)); openlog(progname, LOG_PID | LOG_NDELAY, LOG_DAEMON); while ((x = getopt(argc, argv, "fpdvmiT")) != -1) { @@ -443,7 +447,7 @@ main(int argc, char *argv[]) sigfillset(&set); if ((err = pthread_sigmask(SIG_BLOCK, &set, 0))) { - dsyslogf(LOG_ERR, "Unable to set signal mask: %s", strerror(err)); + dsyslogf(LOG_ERR, "Unable to set signal mask: %s", dsc_strerror(err, errbuf, sizeof(errbuf))); exit(1); } @@ -454,7 +458,7 @@ main(int argc, char *argv[]) sigaddset(&set, SIGINT); if ((err = pthread_create(&sigthread, 0, &sig_thread, (void*)&set))) { - dsyslogf(LOG_ERR, "Unable to start signal thread: %s", strerror(err)); + dsyslogf(LOG_ERR, "Unable to start signal thread: %s", dsc_strerror(err, errbuf, sizeof(errbuf))); exit(1); } } @@ -475,7 +479,7 @@ main(int argc, char *argv[]) sigdelset(&set, SIGINT); if (sigprocmask(SIG_BLOCK, &set, 0)) - dsyslogf(LOG_ERR, "Unable to set signal mask: %s", strerror(errno)); + dsyslogf(LOG_ERR, "Unable to set signal mask: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); memset(&action, 0, sizeof(action)); sigfillset(&action.sa_mask); @@ -486,11 +490,11 @@ main(int argc, char *argv[]) action.sa_handler = sig_exit; if (sigaction(SIGTERM, &action, NULL)) - dsyslogf(LOG_ERR, "Unable to install signal handler for SIGTERM: %s", strerror(errno)); + dsyslogf(LOG_ERR, "Unable to install signal handler for SIGTERM: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); if (sigaction(SIGQUIT, &action, NULL)) - dsyslogf(LOG_ERR, "Unable to install signal handler for SIGQUIT: %s", strerror(errno)); + dsyslogf(LOG_ERR, "Unable to install signal handler for SIGQUIT: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); if (!nodaemon_flag && sigaction(SIGINT, &action, NULL)) - dsyslogf(LOG_ERR, "Unable to install signal handler for SIGINT: %s", strerror(errno)); + dsyslogf(LOG_ERR, "Unable to install signal handler for SIGINT: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); } if (!debug_flag && 0 == n_pcap_offline) { diff --git a/src/dns_message.c b/src/dns_message.c index f4b31911..7ac360ea 100644 --- a/src/dns_message.c +++ b/src/dns_message.c @@ -314,12 +314,13 @@ dns_message_find_indexer(const char *in) static int dns_message_find_filters(const char *fn, filter_list ** fl) { + char *tok = 0; char *t; char *copy = xstrdup(fn); filter_list *f; if (NULL == copy) return 0; - for (t = strtok(copy, ","); t; t = strtok(NULL, ",")) { + for (t = strtok_r(copy, ",", &tok); t; t = strtok_r(NULL, ",", &tok)) { if (0 == strcmp(t, "any")) continue; for (f = DNSFilters; f; f = f->next) { diff --git a/src/ip_proto_index.c b/src/ip_proto_index.c index 0b09d977..3268ae12 100644 --- a/src/ip_proto_index.c +++ b/src/ip_proto_index.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "dns_message.h" #include "md_array.h" @@ -61,6 +62,12 @@ int ip_proto_iterator(char **label) { static char label_buf[20]; +#if __OpenBSD__ + struct protoent_data pdata; +#else + char buf[1024]; +#endif + struct protoent proto; struct protoent *p; if (NULL == label) { next_iter = 0; @@ -68,7 +75,13 @@ ip_proto_iterator(char **label) } if (next_iter > largest) return -1; - p = getprotobynumber(next_iter); +#if __OpenBSD__ + memset(&pdata, 0, sizeof(struct protoent_data)); + getprotobynumber_r(next_iter, &proto, &pdata); + p = &proto; +#else + getprotobynumber_r(next_iter, &proto, buf, sizeof(buf), &p); +#endif if (p) *label = p->p_name; else diff --git a/src/parse_conf.c b/src/parse_conf.c index 296370c2..7853cb99 100644 --- a/src/parse_conf.c +++ b/src/parse_conf.c @@ -46,6 +46,7 @@ #include "config_hooks.h" #include "dns_message.h" #include "syslog_debug.h" +#include "compat.h" #define PARSE_CONF_EINVAL -2 #define PARSE_CONF_ERROR -1 @@ -672,7 +673,8 @@ int parse_conf_tokens(const conf_token_t* tokens, size_t token_size, size_t line int ret = syntax->parse(tokens); if (ret < 0) { - fprintf(stderr, "CONFIG ERROR [%lu]: %s", line, strerror(errno)); + char errbuf[512]; + fprintf(stderr, "CONFIG ERROR [%lu]: %s", line, dsc_strerror(errno, errbuf, sizeof(errbuf))); } if (ret > 0) { fprintf(stderr, "CONFIG ERROR [%lu]: Unable to configure ", line); diff --git a/src/pcap.c b/src/pcap.c index 38f4a2aa..2ae09400 100644 --- a/src/pcap.c +++ b/src/pcap.c @@ -77,6 +77,7 @@ #include "config.h" #include "pcap-thread/pcap_thread.h" +#include "compat.h" #define PCAP_SNAPLEN 65536 #ifndef ETHER_HDR_LEN @@ -799,6 +800,7 @@ void _callback(u_char* user, const struct pcap_pkthdr* pkthdr, const u_char* pkt void Pcap_init(const char *device, int promisc, int monitor, int immediate, int threads) { + char errbuf[512]; struct stat sb; struct _interface *i; int err; @@ -856,7 +858,7 @@ Pcap_init(const char *device, int promisc, int monitor, int immediate, int threa else if (err == PCAP_THREAD_ERRNO) { dsyslogf(LOG_ERR, "system error [%d]: %s (%s)\n", errno, - strerror(errno), + dsc_strerror(errno, errbuf, sizeof(errbuf)), pcap_thread_errbuf(&pcap_thread) ); } @@ -878,7 +880,7 @@ Pcap_init(const char *device, int promisc, int monitor, int immediate, int threa else if (err == PCAP_THREAD_ERRNO) { dsyslogf(LOG_ERR, "system error [%d]: %s (%s)\n", errno, - strerror(errno), + dsc_strerror(errno, errbuf, sizeof(errbuf)), pcap_thread_errbuf(&pcap_thread) ); } @@ -1021,9 +1023,10 @@ Pcap_run(void) ); } else if (err == PCAP_THREAD_ERRNO) { + char errbuf[512]; dsyslogf(LOG_ERR, "system error [%d]: %s (%s)\n", errno, - strerror(errno), + dsc_strerror(errno, errbuf, sizeof(errbuf)), pcap_thread_errbuf(&pcap_thread) ); } diff --git a/src/query_classification_index.c b/src/query_classification_index.c index a7f48be8..7e3b5be3 100644 --- a/src/query_classification_index.c +++ b/src/query_classification_index.c @@ -123,6 +123,7 @@ a_for_root(const dns_message * m) static int rfc1918_ptr(const dns_message * m) { + char *tok = 0; char *t; char q[128]; unsigned int i = 0; @@ -133,7 +134,7 @@ rfc1918_ptr(const dns_message * m) if (NULL == (t = strstr(q, ".in-addr.arpa"))) return 0; *t = '\0'; - for (t = strtok(q, "."); t; t = strtok(NULL, ".")) { + for (t = strtok_r(q, ".", &tok); t; t = strtok_r(NULL, ".", &tok)) { i >>= 8; i |= ((atoi(t) & 0xff) << 24); } diff --git a/src/xmalloc.c b/src/xmalloc.c index 468d084f..414504a1 100644 --- a/src/xmalloc.c +++ b/src/xmalloc.c @@ -50,42 +50,47 @@ #endif #include "xmalloc.h" #include "syslog_debug.h" +#include "compat.h" /********** xmalloc **********/ void * xmalloc(size_t size) { + char errbuf[512]; void *p = malloc(size); if (NULL == p) - dsyslogf(LOG_CRIT, "malloc: %s", strerror(errno)); + dsyslogf(LOG_CRIT, "malloc: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); return p; } void * xcalloc(size_t number, size_t size) { + char errbuf[512]; void *p = calloc(number, size); if (NULL == p) - dsyslogf(LOG_CRIT, "calloc: %s", strerror(errno)); + dsyslogf(LOG_CRIT, "calloc: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); return p; } void * xrealloc(void *p, size_t size) { + char errbuf[512]; p = realloc(p, size); if (NULL == p) - dsyslogf(LOG_CRIT, "realloc: %s", strerror(errno)); + dsyslogf(LOG_CRIT, "realloc: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); return p; } char * xstrdup(const char *s) { + char errbuf[512]; void *p = strdup(s); if (NULL == p) - dsyslogf(LOG_CRIT, "strdup: %s", strerror(errno)); + dsyslogf(LOG_CRIT, "strdup: %s", dsc_strerror(errno, errbuf, sizeof(errbuf))); return p; } @@ -115,11 +120,12 @@ Arena *currentArena = NULL; static Arena * newArena(size_t size) { + char errbuf[512]; Arena *arena; size = align(size, ALIGNMENT); arena = malloc(HEADERSIZE + size); if (NULL == arena) { - dsyslogf(LOG_CRIT, "amalloc %d: %s", (int) size, strerror(errno)); + dsyslogf(LOG_CRIT, "amalloc %d: %s", (int) size, dsc_strerror(errno, errbuf, sizeof(errbuf))); return NULL; } arena->prevArena = NULL;