#ifndef HAVE_ERR
void err(int e, const char *fmt, ...)
{
- const char *serr = strerror(errno);
- char buf[1024];
+ char buf[1024], ebuf[256];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
- errx(e, "%s: %s", buf, serr);
+ errx(e, "%s: %s", buf, strerror_r(e, ebuf, sizeof(ebuf)));
}
#endif
#ifndef HAVE_WARN
void warn(const char *fmt, ...)
{
- const char *serr = strerror(errno);
- char buf[1024];
+ char buf[1024], ebuf[256];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
- warnx("%s: %s", buf, serr);
+ warnx("%s: %s", buf, strerror_r(e, ebuf, sizeof(ebuf)));
}
#endif
void log_generic(enum LogLevel level, const char *fmt, ...)
{
char buf[2048];
+ char ebuf[256];
char timebuf[64];
const struct LevelInfo *lev = &log_level_list[level];
unsigned pid = getpid();
} else if (!cf_quiet && !error_reported) {
/* Unable to open, complain once */
fprintf(stderr, "%s %u %s %s: %s\n", timebuf, pid,
- log_level_list[2].tag, cf_logfile, strerror(errno));
+ log_level_list[2].tag, cf_logfile,
+ strerror_r(errno, ebuf, sizeof(ebuf)));
error_reported = 1;
}
}
void log_fatal(const char *file, int line, const char *func, bool show_perror, const char *fmt, ...)
{
- char buf[2048];
+ char buf[2048], ebuf[256];
const char *estr = NULL;
int old_errno = 0;
va_list ap;
if (show_perror) {
old_errno = errno;
- estr = strerror(errno);
+ estr = strerror_r(errno, ebuf, sizeof(ebuf));
}
va_start(ap, fmt);
int safe_recv(int fd, void *buf, int len, int flags)
{
int res;
+ char ebuf[128];
loop:
res = recv(fd, buf, len, flags);
if (res < 0 && errno == EINTR)
goto loop;
if (res < 0)
- log_noise("safe_recv(%d, %d) = %s", fd, len, strerror(errno));
+ log_noise("safe_recv(%d, %d) = %s", fd, len,
+ strerror_r(errno, ebuf, sizeof(ebuf)));
else if (cf_verbose > 2)
log_noise("safe_recv(%d, %d) = %d", fd, len, res);
return res;
int safe_send(int fd, const void *buf, int len, int flags)
{
int res;
+ char ebuf[128];
loop:
res = send(fd, buf, len, flags);
if (res < 0 && errno == EINTR)
goto loop;
if (res < 0)
- log_noise("safe_send(%d, %d) = %s", fd, len, strerror(errno));
+ log_noise("safe_send(%d, %d) = %s", fd, len,
+ strerror_r(errno, ebuf, sizeof(ebuf)));
else if (cf_verbose > 2)
log_noise("safe_send(%d, %d) = %d", fd, len, res);
return res;
int safe_recvmsg(int fd, struct msghdr *msg, int flags)
{
int res;
+ char ebuf[128];
loop:
res = recvmsg(fd, msg, flags);
if (res < 0 && errno == EINTR)
goto loop;
if (res < 0)
- log_warning("safe_recvmsg(%d, msg, %d) = %s", fd, flags, strerror(errno));
+ log_warning("safe_recvmsg(%d, msg, %d) = %s", fd, flags,
+ strerror_r(errno, ebuf, sizeof(ebuf)));
else if (cf_verbose > 2)
log_noise("safe_recvmsg(%d, msg, %d) = %d", fd, flags, res);
return res;
{
int res;
int msgerr_count = 0;
+ char ebuf[128];
loop:
res = sendmsg(fd, msg, flags);
if (res < 0 && errno == EINTR)
log_warning("safe_sendmsg(%d, msg[%d,%d], %d) = %s", fd,
(int)msg->msg_iov[0].iov_len,
(int)msg->msg_controllen,
- flags, strerror(errno));
+ flags, strerror_r(errno, ebuf, sizeof(ebuf)));
/* with ancillary data on blocking socket OSX returns
* EMSGSIZE instead of blocking. try to solve it by waiting */
{
int res;
char buf[128];
+ char ebuf[128];
loop:
res = connect(fd, sa, sa_len);
if (res < 0 && errno == EINTR)
goto loop;
if (res < 0 && (errno != EINPROGRESS || cf_verbose > 2))
- log_noise("connect(%d, %s) = %s", fd, sa2str(sa, buf, sizeof(buf)), strerror(errno));
+ log_noise("connect(%d, %s) = %s", fd,
+ sa2str(sa, buf, sizeof(buf)),
+ strerror_r(errno, ebuf, sizeof(ebuf)));
else if (cf_verbose > 2)
log_noise("connect(%d, %s) = %d", fd, sa2str(sa, buf, sizeof(buf)), res);
return res;
{
int res;
char buf[128];
+ char ebuf[128];
loop:
res = accept(fd, sa, sa_len_p);
if (res < 0 && errno == EINTR)
goto loop;
if (res < 0)
- log_noise("safe_accept(%d) = %s", fd, strerror(errno));
+ log_noise("safe_accept(%d) = %s", fd,
+ strerror_r(errno, ebuf, sizeof(ebuf)));
else if (cf_verbose > 2)
log_noise("safe_accept(%d) = %d (%s)", fd, res, sa2str(sa, buf, sizeof(buf)));
return res;