use expandm from libwrap.

This commit is contained in:
christos 2019-01-11 20:41:53 +00:00
parent feb39a8c47
commit ea179cc7cf
2 changed files with 13 additions and 29 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.21 2017/10/10 19:30:41 christos Exp $
# $NetBSD: Makefile,v 1.22 2019/01/11 20:41:53 christos Exp $
WARNS?= 4
@ -14,6 +14,12 @@ CPPFLAGS+= -DINET6
LDADD+= -lutil
DPADD+= ${LIBUTIL}
LIBWRAP= ${NETBSDSRCDIR}/lib/libwrap
SRCS+= expandm.c
.PATH.c: ${LIBWRAP}
CPPFLAGS+= -I${LIBWRAP}
.if ${MKSHARE} != "no"
FILESDIR= /usr/share/examples/rtadvd
FILES= rtadvd.conf

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtadvd.c,v 1.66 2018/04/24 18:31:48 roy Exp $ */
/* $NetBSD: rtadvd.c,v 1.67 2019/01/11 20:41:53 christos Exp $ */
/* $KAME: rtadvd.c,v 1.92 2005/10/17 14:40:02 suz Exp $ */
/*
@ -70,6 +70,7 @@
#include "dump.h"
#include "logit.h"
#include "prog_ops.h"
#include "expandm.h"
struct msghdr rcvmhdr;
static unsigned char *rcvcmsgbuf;
@ -1842,36 +1843,11 @@ ra_timer_update(void *data, struct timespec *tm)
(intmax_t)tm->tv_sec, (intmax_t)tm->tv_nsec);
}
__format_arg(3)
static const char *
expandm(char *buf, size_t len, const char *fmt)
{
char *ptr;
const char *e = strerror(errno);
size_t cur = 0, elen = strlen(e);
*buf = '\0';
while ((ptr = strstr(fmt, "%m")) != NULL) {
size_t l = (size_t)(ptr - fmt);
if (cur + elen + l + 1 >= len)
return buf;
memcpy(buf + cur, fmt, l);
cur += l;
memcpy(buf + cur, e, elen);
cur += elen;
fmt += l + 2;
buf[cur] = '\0';
}
strlcat(buf, fmt, len);
strlcat(buf, "\n", len); /* syslog does not need \n, printf does */
return buf;
}
void
logit(int level, const char *fmt, ...)
{
va_list ap;
char buf[1024];
char *buf;
va_start(ap, fmt);
if (!Dflag) {
@ -1880,6 +1856,8 @@ logit(int level, const char *fmt, ...)
return;
}
vfprintf(stderr, expandm(buf, sizeof(buf), fmt), ap);
vfprintf(stderr, buf = expandm(fmt, "\n"), ap);
if (buf != fmt)
free(buf);
va_end(ap);
}