Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/rtadvd use expandm from libwrap.



details:   https://anonhg.NetBSD.org/src/rev/e343416e7d8d
branches:  trunk
changeset: 838335:e343416e7d8d
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jan 11 20:41:53 2019 +0000

description:
use expandm from libwrap.

diffstat:

 usr.sbin/rtadvd/Makefile |   8 +++++++-
 usr.sbin/rtadvd/rtadvd.c |  34 ++++++----------------------------
 2 files changed, 13 insertions(+), 29 deletions(-)

diffs (87 lines):

diff -r 9876852765a9 -r e343416e7d8d usr.sbin/rtadvd/Makefile
--- a/usr.sbin/rtadvd/Makefile  Fri Jan 11 20:37:30 2019 +0000
+++ b/usr.sbin/rtadvd/Makefile  Fri Jan 11 20:41:53 2019 +0000
@@ -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 @@
 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
diff -r 9876852765a9 -r e343416e7d8d usr.sbin/rtadvd/rtadvd.c
--- a/usr.sbin/rtadvd/rtadvd.c  Fri Jan 11 20:37:30 2019 +0000
+++ b/usr.sbin/rtadvd/rtadvd.c  Fri Jan 11 20:41:53 2019 +0000
@@ -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 @@
               (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 @@
                return;
        }
 
-       vfprintf(stderr, expandm(buf, sizeof(buf), fmt), ap);
+       vfprintf(stderr, buf = expandm(fmt, "\n"), ap);
+       if (buf != fmt)
+               free(buf);
        va_end(ap);
 }



Home | Main Index | Thread Index | Old Index