Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/blacklist - logging fixes



details:   https://anonhg.NetBSD.org/src/rev/49081bcaa515
branches:  trunk
changeset: 805877:49081bcaa515
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jan 22 16:19:53 2015 +0000

description:
- logging fixes
- finish adding pidfile
- credential passing for linux

diffstat:

 external/bsd/blacklist/bin/blacklistctl.c |   11 +-
 external/bsd/blacklist/bin/blacklistd.c   |   28 ++-
 external/bsd/blacklist/bin/conf.c         |   32 ++--
 external/bsd/blacklist/bin/run.c          |   24 ++-
 external/bsd/blacklist/bin/state.c        |   29 +++-
 external/bsd/blacklist/bin/support.c      |   10 +-
 external/bsd/blacklist/bin/support.h      |    4 +-
 external/bsd/blacklist/include/bl.h       |    3 +-
 external/bsd/blacklist/lib/bl.c           |  100 +++++++++-------
 external/bsd/blacklist/lib/blacklist.c    |   39 +-----
 external/bsd/blacklist/port/pidfile.c     |  180 ++++++++++++++++++++++++++++++
 external/bsd/blacklist/port/port.h        |    3 +
 12 files changed, 326 insertions(+), 137 deletions(-)

diffs (truncated from 987 to 300 lines):

diff -r a330bcab13df -r 49081bcaa515 external/bsd/blacklist/bin/blacklistctl.c
--- a/external/bsd/blacklist/bin/blacklistctl.c Thu Jan 22 16:19:08 2015 +0000
+++ b/external/bsd/blacklist/bin/blacklistctl.c Thu Jan 22 16:19:53 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: blacklistctl.c,v 1.9 2015/01/22 15:29:27 christos Exp $        */
+/*     $NetBSD: blacklistctl.c,v 1.10 2015/01/22 16:19:53 christos Exp $       */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: blacklistctl.c,v 1.9 2015/01/22 15:29:27 christos Exp $");
+__RCSID("$NetBSD: blacklistctl.c,v 1.10 2015/01/22 16:19:53 christos Exp $");
 
 #include <stdio.h>
 #include <time.h>
@@ -41,6 +41,7 @@
 #include <util.h>
 #endif
 #include <fcntl.h>
+#include <syslog.h>
 #include <err.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -86,11 +87,11 @@
 
        for (i = 1; state_iterate(db, &ss, &c, &dbi, i) != 0; i = 0) {
                char buf[BUFSIZ];
-               (*lfun)(LOG_DEBUG, "conf: %s\n", conf_print(buf, sizeof(buf), "",
+               (*lfun)(LOG_DEBUG, "conf: %s", conf_print(buf, sizeof(buf), "",
                    ":", &c));
                sockaddr_snprintf(buf, sizeof(buf), "%a", (void *)&ss);
-               (*lfun)(LOG_DEBUG, "addr: %s\n", buf);
-               (*lfun)(LOG_DEBUG, "data: count=%d id=%s time=%s\n", dbi.count,
+               (*lfun)(LOG_DEBUG, "addr: %s", buf);
+               (*lfun)(LOG_DEBUG, "data: count=%d id=%s time=%s", dbi.count,
                    dbi.id, fmttime(buf, sizeof(buf), dbi.last));
        }
        state_close(db);
diff -r a330bcab13df -r 49081bcaa515 external/bsd/blacklist/bin/blacklistd.c
--- a/external/bsd/blacklist/bin/blacklistd.c   Thu Jan 22 16:19:08 2015 +0000
+++ b/external/bsd/blacklist/bin/blacklistd.c   Thu Jan 22 16:19:53 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: blacklistd.c,v 1.20 2015/01/22 15:29:27 christos Exp $ */
+/*     $NetBSD: blacklistd.c,v 1.21 2015/01/22 16:19:53 christos Exp $ */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include "config.h"
 #endif
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: blacklistd.c,v 1.20 2015/01/22 15:29:27 christos Exp $");
+__RCSID("$NetBSD: blacklistd.c,v 1.21 2015/01/22 16:19:53 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -71,6 +71,7 @@
 static const char *dbfile = _PATH_BLSTATE;
 static sig_atomic_t rconf;
 static sig_atomic_t done;
+static int vflag;
 
 static void
 sigusr1(int n __unused)
@@ -100,7 +101,7 @@
 usage(int c)
 {
        warnx("Unknown option `%c'", (char)c);
-       fprintf(stderr, "Usage: %s [-df] [-c <config>] [-r <rulename>] "
+       fprintf(stderr, "Usage: %s [-vdf] [-c <config>] [-r <rulename>] "
            "[-P <sockpathsfile>] [-C <controlprog>] [-D <dbfile>] "
            "[-t <timeout>]\n", getprogname());
        exit(EXIT_FAILURE);
@@ -127,9 +128,10 @@
                return;
 
        if (debug)
-               (*lfun)(LOG_DEBUG, "got type=%d fd=%d msg=%s uid=%lu\n",
+               (*lfun)(LOG_DEBUG, "got type=%d fd=%d msg=%s uid=%lu gid=%lu",
                    bi->bi_type, bi->bi_fd, bi->bi_msg,
-                   (unsigned long)bi->bi_uid);
+                   (unsigned long)bi->bi_uid,
+                   (unsigned long)bi->bi_gid);
 
        if (conf_find(bi->bi_fd, bi->bi_uid, &c) == NULL)
                goto out;
@@ -155,8 +157,8 @@
        if (debug) {
                char b1[128], b2[128];
                sockaddr_snprintf(rbuf, sizeof(rbuf), "%a:%p", (void *)&rss);
-               (*lfun)(LOG_DEBUG, "%s: %s count=%d nfail=%d last=%s now=%s\n", __func__,
-                   rbuf, dbi.count, c.c_nfail,
+               (*lfun)(LOG_DEBUG, "%s: %s count=%d nfail=%d last=%s now=%s",
+                   __func__, rbuf, dbi.count, c.c_nfail,
                    fmttime(b1, sizeof(b1), dbi.last),
                    fmttime(b2, sizeof(b2), ts.tv_sec));
        }
@@ -219,8 +221,9 @@
                        char b1[64], b2[64];
                        sockaddr_snprintf(buf, sizeof(buf), "%a:%p",
                            (void *)&ss);
-                       (*lfun)(LOG_DEBUG, "%s:[%u] %s count=%d duration=%d last=%s "
-                          "now=%s\n", __func__, n, buf, dbi.count,
+                       (*lfun)(LOG_DEBUG,
+                           "%s:[%u] %s count=%d duration=%d last=%s "
+                          "now=%s", __func__, n, buf, dbi.count,
                           c.c_duration, fmttime(b1, sizeof(b1), dbi.last),
                           fmttime(b2, sizeof(b2), ts.tv_sec));
                }
@@ -241,7 +244,7 @@
 addfd(struct pollfd **pfdp, bl_t **blp, size_t *nfd, size_t *maxfd,
     const char *path)
 {
-       bl_t bl = bl_create(true, path, lfun);
+       bl_t bl = bl_create(true, path, vflag ? vdlog : vsyslog);
        if (bl == NULL || !bl_isconnected(bl))
                exit(EXIT_FAILURE);
        if (*nfd >= *maxfd) {
@@ -272,7 +275,7 @@
        reset = 0;
        tout = 0;
        flags = O_RDWR|O_EXCL|O_CLOEXEC;
-       while ((c = getopt(argc, argv, "C:c:D:dfr:P:t:")) != -1) {
+       while ((c = getopt(argc, argv, "C:c:D:dfr:P:t:v")) != -1) {
                switch (c) {
                case 'C':
                        controlprog = optarg;
@@ -298,6 +301,9 @@
                case 't':
                        tout = atoi(optarg) * 1000;
                        break;
+               case 'v':
+                       vflag++;
+                       break;
                default:
                        usage(c);
                }
diff -r a330bcab13df -r 49081bcaa515 external/bsd/blacklist/bin/conf.c
--- a/external/bsd/blacklist/bin/conf.c Thu Jan 22 16:19:08 2015 +0000
+++ b/external/bsd/blacklist/bin/conf.c Thu Jan 22 16:19:53 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: conf.c,v 1.12 2015/01/22 15:29:27 christos Exp $       */
+/*     $NetBSD: conf.c,v 1.13 2015/01/22 16:19:53 christos Exp $       */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: conf.c,v 1.12 2015/01/22 15:29:27 christos Exp $");
+__RCSID("$NetBSD: conf.c,v 1.13 2015/01/22 16:19:53 christos Exp $");
 
 #include <stdio.h>
 #include <string.h>
@@ -168,7 +168,7 @@
                *d++ = '\0';
                p++;
                if (debug)
-                       (*lfun)(LOG_DEBUG, "%s: host6 %s\n", __func__, p);
+                       (*lfun)(LOG_DEBUG, "%s: host6 %s", __func__, p);
                if (strcmp(p, "*") != 0) {
                        if (inet_pton(AF_INET6, p, &s6->sin6_addr) == -1)
                                goto out;
@@ -183,7 +183,7 @@
                struct sockaddr_in *s = (void *)&c->c_ss;
                *d++ = '\0';
                if (debug)
-                       (*lfun)(LOG_DEBUG, "%s: host4 %s\n", __func__, p);
+                       (*lfun)(LOG_DEBUG, "%s: host4 %s", __func__, p);
                if (strcmp(p, "*") != 0) {
                        if (inet_pton(AF_INET, p, &s->sin_addr) == -1)
                                goto out;
@@ -337,14 +337,15 @@
        if (c2->c_ss.ss_family != 0 &&
            memcmp(&c1->c_ss, &c2->c_ss, sizeof(c1->c_ss))) {
                if (debug > 1)
-                       (*lfun)(LOG_DEBUG, "%s: c_ss fail\n", __func__);
+                       (*lfun)(LOG_DEBUG, "%s: c_ss fail", __func__);
                return 0;
        }
                
 #define CMP(a, b, f) \
        if ((a)->f != (b)->f && (b)->f != -1) { \
                if (debug > 1) \
-                       (*lfun)(LOG_DEBUG, "%s: %s fail\n", __func__, __STRING(f)); \
+                       (*lfun)(LOG_DEBUG, "%s: %s fail", __func__, \
+                           __STRING(f)); \
                return 0; \
        }
        CMP(c1, c2, c_port);
@@ -443,7 +444,7 @@
 
        if (debug) {
                sockaddr_snprintf(buf, sizeof(buf), "%a:%p", (void *)&ss);
-               (*lfun)(LOG_DEBUG, "listening socket: %s\n", buf);
+               (*lfun)(LOG_DEBUG, "listening socket: %s", buf);
        }
 
        switch (proto) {
@@ -477,16 +478,17 @@
        cr->c_duration = -1;
 
        if (debug)
-               (*lfun)(LOG_DEBUG, "%s\n", conf_print(buf, sizeof(buf),
+               (*lfun)(LOG_DEBUG, "%s", conf_print(buf, sizeof(buf),
                    "look:\t", "", cr));
 
        for (i = 0; i < nconf; i++) {
                if (debug)
-                       (*lfun)(LOG_DEBUG, "%s\n", conf_print(buf, sizeof(buf), "check:\t",
-                           "", &conf[i]));
+                       (*lfun)(LOG_DEBUG, "%s", conf_print(buf, sizeof(buf),
+                           "check:\t", "", &conf[i]));
                if (conf_eq(cr, &conf[i])) {
                        if (debug)
-                               (*lfun)(LOG_DEBUG, "%s\n", conf_print(buf, sizeof(buf),
+                               (*lfun)(LOG_DEBUG, "%s",
+                                   conf_print(buf, sizeof(buf),
                                    "found:\t", "", &conf[i]));
                        cr->c_ss = conf[i].c_ss;
                        memcpy(cr->c_name, conf[i].c_name, CONFNAMESZ);
@@ -496,7 +498,7 @@
                }
        }
        if (debug)
-               (*lfun)(LOG_DEBUG, "not found\n");
+               (*lfun)(LOG_DEBUG, "not found");
        return NULL;
 }
 
@@ -523,7 +525,7 @@
                if (!*line)
                        continue;
                if (debug > 4)
-                       (*lfun)(LOG_DEBUG, "%s, %zu: [%s]\n", f, lineno, line);
+                       (*lfun)(LOG_DEBUG, "%s, %zu: [%s]", f, lineno, line);
 #endif
                if (nc == mc) {
                        mc += 10;
@@ -550,10 +552,10 @@
        if (debug) {
                char buf[BUFSIZ];
                (*lfun)(LOG_DEBUG,
-                   "%20.20s\ttype\tproto\towner\tname\tnfail\tduration\n",
+                   "%20.20s\ttype\tproto\towner\tname\tnfail\tduration",
                    "target");
                for (nc = 0; nc < nconf; nc++)
-                       (*lfun)(LOG_DEBUG, "%s\n",
+                       (*lfun)(LOG_DEBUG, "%s",
                            conf_print(buf, sizeof(buf), "", "\t", &c[nc]));
        }
 }
diff -r a330bcab13df -r 49081bcaa515 external/bsd/blacklist/bin/run.c
--- a/external/bsd/blacklist/bin/run.c  Thu Jan 22 16:19:08 2015 +0000
+++ b/external/bsd/blacklist/bin/run.c  Thu Jan 22 16:19:53 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: run.c,v 1.9 2015/01/22 15:29:27 christos Exp $ */
+/*     $NetBSD: run.c,v 1.10 2015/01/22 16:19:53 christos Exp $        */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: run.c,v 1.9 2015/01/22 15:29:27 christos Exp $");
+__RCSID("$NetBSD: run.c,v 1.10 2015/01/22 16:19:53 christos Exp $");
 
 #include <stdio.h>
 #ifdef HAVE_UTIL_H
@@ -60,7 +60,7 @@
        size_t i;
        va_list ap;
        FILE *fp;
-       char buf[BUFSIZ], *res;
+       char buf[10240], *res;
 
        argv[0] = "control";
        argv[1] = cmd;
@@ -72,10 +72,18 @@
        va_end(ap);
                
        if (debug) {
-               (*lfun)(LOG_DEBUG, "run %s [", controlprog);
-               for (i = 0; argv[i]; i++)
-                       (*lfun)(LOG_DEBUG, " %s", argv[i]);
-               (*lfun)(LOG_DEBUG, "]\n");
+               size_t z;
+
+               z = snprintf(buf, sizeof(buf), "run %s [", controlprog);
+               if (z >= sizeof(buf))
+                       z = sizeof(buf);
+               for (i = 0; argv[i]; i++) {
+                       z = snprintf(buf + z, sizeof(buf) - z, "%s%s",
+                           argv[i], argv[i + 1] ? " " : "");
+                       if (z >= sizeof(buf))



Home | Main Index | Thread Index | Old Index