Source-Changes-HG archive

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

[src/trunk]: src/external/bsd/blacklist checkin commit for logging fixes, bus...



details:   https://anonhg.NetBSD.org/src/rev/159df35f2473
branches:  trunk
changeset: 335732:159df35f2473
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jan 22 15:25:52 2015 +0000

description:
checkin commit for logging fixes, busy socket and pidfile.

diffstat:

 external/bsd/blacklist/TODO               |   8 ++-
 external/bsd/blacklist/bin/blacklistd.c   |   6 +-
 external/bsd/blacklist/bin/support.c      |  19 +++++--
 external/bsd/blacklist/bin/support.h      |   9 +-
 external/bsd/blacklist/include/bl.h       |   5 +-
 external/bsd/blacklist/lib/bl.c           |  80 +++++++++++++++++++++---------
 external/bsd/blacklist/port/configure.ac  |   2 +-
 external/bsd/blacklist/port/getprogname.c |  13 ++++-
 external/bsd/blacklist/port/port.h        |   4 +
 9 files changed, 103 insertions(+), 43 deletions(-)

diffs (truncated from 382 to 300 lines):

diff -r 556f650286cb -r 159df35f2473 external/bsd/blacklist/TODO
--- a/external/bsd/blacklist/TODO       Thu Jan 22 12:33:35 2015 +0000
+++ b/external/bsd/blacklist/TODO       Thu Jan 22 15:25:52 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: TODO,v 1.4 2015/01/22 05:44:35 christos Exp $
+# $NetBSD: TODO,v 1.5 2015/01/22 15:25:52 christos Exp $
 
 - don't poll periodically, find the next timeout
 - perhaps pass addresses through the socket too?
@@ -9,3 +9,9 @@
   <bge0/4>? What to do with multiple addresses?
 - make a pidfile
 - fix CRED on linux and macosx.
+- perhaps rate limit against DoS
+- perhaps instead of scanning the list have a sparse map by port?
+- do we want to use libnpf directly for efficiency?
+- make /etc/rc.d/ file and fix other naming inconsistencies.
+- finalize named.diff
+- add more daemons ftpd?
diff -r 556f650286cb -r 159df35f2473 external/bsd/blacklist/bin/blacklistd.c
--- a/external/bsd/blacklist/bin/blacklistd.c   Thu Jan 22 12:33:35 2015 +0000
+++ b/external/bsd/blacklist/bin/blacklistd.c   Thu Jan 22 15:25:52 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: blacklistd.c,v 1.18 2015/01/22 07:57:31 christos Exp $ */
+/*     $NetBSD: blacklistd.c,v 1.19 2015/01/22 15:25:52 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.18 2015/01/22 07:57:31 christos Exp $");
+__RCSID("$NetBSD: blacklistd.c,v 1.19 2015/01/22 15:25:52 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -316,6 +316,8 @@
                if (tout == 0)
                        tout = 5000;
        } else {
+               if (pidfile(getprogname()) == -1)
+                       err(EXIT_FAILURE, "Can't create pidfile");
                if (tout == 0)
                        tout = 15000;
        }
diff -r 556f650286cb -r 159df35f2473 external/bsd/blacklist/bin/support.c
--- a/external/bsd/blacklist/bin/support.c      Thu Jan 22 12:33:35 2015 +0000
+++ b/external/bsd/blacklist/bin/support.c      Thu Jan 22 15:25:52 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: support.c,v 1.2 2015/01/22 03:10:49 christos Exp $     */
+/*     $NetBSD: support.c,v 1.3 2015/01/22 15:25:52 christos Exp $     */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: support.c,v 1.2 2015/01/22 03:10:49 christos Exp $");
+__RCSID("$NetBSD: support.c,v 1.3 2015/01/22 15:25:52 christos Exp $");
 
 #include <time.h>
 #include <string.h>
@@ -66,16 +66,23 @@
 }
 
 void
-dlog(int level __unused, const char *fmt, ...)
+dlogv(int level __unused, const char *fmt, va_list ap)
 {
        char buf[BUFSIZ];
+
+       fprintf(stderr, "%s: ", getprogname());
+       vfprintf(stderr, expandm(buf, sizeof(buf), fmt), ap);
+       fprintf(stderr, "\n");
+}
+
+void
+dlog(int level, const char *fmt, va_list ap)
+{
        va_list ap;
 
-       fprintf(stderr, "%s: ", getprogname());
        va_start(ap, fmt);
-       vfprintf(stderr, expandm(buf, sizeof(buf), fmt), ap);
+       dlogv(level, fmt, ap);
        va_end(ap);
-       fprintf(stderr, "\n");
 }
 
 const char *
diff -r 556f650286cb -r 159df35f2473 external/bsd/blacklist/bin/support.h
--- a/external/bsd/blacklist/bin/support.h      Thu Jan 22 12:33:35 2015 +0000
+++ b/external/bsd/blacklist/bin/support.h      Thu Jan 22 15:25:52 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: support.h,v 1.1 2015/01/22 03:08:09 christos Exp $     */
+/*     $NetBSD: support.h,v 1.2 2015/01/22 15:25:52 christos Exp $     */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -28,12 +28,13 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-#ifndef _UTIL_H
-#define _UTIL_H
+#ifndef _SUPPORT_H
+#define _SUPPORT_H
 
 __BEGIN_DECLS
 const char *fmttime(char *, size_t, time_t);
+void dlogv(int, const char *, va_list);
 void dlog(int, const char *, ...);
 __END_DECLS
 
-#endif /* _UTIL_H */
+#endif /* _SUPPORT_H */
diff -r 556f650286cb -r 159df35f2473 external/bsd/blacklist/include/bl.h
--- a/external/bsd/blacklist/include/bl.h       Thu Jan 22 12:33:35 2015 +0000
+++ b/external/bsd/blacklist/include/bl.h       Thu Jan 22 15:25:52 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bl.h,v 1.10 2015/01/22 05:35:55 christos Exp $ */
+/*     $NetBSD: bl.h,v 1.11 2015/01/22 15:25:52 christos Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -32,6 +32,7 @@
 #define _BL_H
 
 #include <stdbool.h>
+#include <stdarg.h>
 #include <sys/param.h>
 #include <sys/socket.h>
 #include "blacklist.h"
@@ -61,7 +62,7 @@
 
 typedef struct blacklist *bl_t;
 
-bl_t bl_create(bool, const char *, void (*)(int, const char *, ...));
+bl_t bl_create(bool, const char *, void (*)(int, const char *, va_list));
 void bl_destroy(bl_t);
 int bl_send(bl_t, bl_type_t, int, const struct sockaddr *, socklen_t,
     const char *);
diff -r 556f650286cb -r 159df35f2473 external/bsd/blacklist/lib/bl.c
--- a/external/bsd/blacklist/lib/bl.c   Thu Jan 22 12:33:35 2015 +0000
+++ b/external/bsd/blacklist/lib/bl.c   Thu Jan 22 15:25:52 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bl.c,v 1.16 2015/01/22 05:41:08 christos Exp $ */
+/*     $NetBSD: bl.c,v 1.17 2015/01/22 15:25:52 christos Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: bl.c,v 1.16 2015/01/22 05:41:08 christos Exp $");
+__RCSID("$NetBSD: bl.c,v 1.17 2015/01/22 15:25:52 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -88,11 +88,21 @@
 static void
 bl_reset(bl_t b)
 {
+       int serrno = errno;
        close(b->b_fd);
+       errno = serrno;
        b->b_fd = -1;
        b->b_connected = false;
 }
 
+static void
+bl_log(bl_t b, int level, const char *fmt, va_list ap)
+{
+       int serrno = errno;
+       (*b->b_fun)(level, fmt, ap);
+       errno = serrno;
+}
+
 static int
 bl_init(bl_t b, bool srv)
 {
@@ -107,13 +117,10 @@
 #endif
        };
        mode_t om;
-       int rv;
+       int rv, serrno;
 
        strlcpy(sun.sun_path, b->b_path, sizeof(sun.sun_path));
 
-       if (srv)
-               (void)unlink(b->b_path);
-
 #ifndef SOCK_NONBLOCK
 #define SOCK_NONBLOCK 0
 #endif
@@ -127,9 +134,9 @@
                b->b_fd = socket(PF_LOCAL,
                    SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK|SOCK_NOSIGPIPE, 0);
                if (b->b_fd == -1) {
-                       (*b->b_fun)(LOG_ERR, "%s: socket failed (%m)",
+                       bl_log(bl, LOG_ERR, "%s: socket failed (%m)",
                            __func__);
-                       return 0;
+                       return -1;
                }
 #if SOCK_CLOEXEC == 0
                fcntl(b->b_fd, F_SETFD, FD_CLOEXEC);
@@ -150,21 +157,44 @@
        if (b->b_connected)
                return 0;
 
-       om = umask(0);
-       rv = (srv ? bind : connect)(b->b_fd, (const void *)&sun,
-           (socklen_t)sizeof(sun));
-       (void)umask(om);
-       if (rv == -1) {
-               (*b->b_fun)(LOG_ERR, "%s: %s failed (%m)", __func__,
-                   srv ? "bind" : "connect");
-               goto out;
+       rv = connect(b->b_fd, (const void *)&sun, (socklen_t)sizeof(sun));
+       if (rv == 0) {
+               if (srv) {
+                       bl_log(bl, LOG_ERR,
+                           "%s: another daemon is handling `%s'",
+                           __func__, b->b_path);
+                       goto out;
+               }
+               (void)unlink(b->b_path);
+       } else {
+               if (!srv) {
+                       bl_log(bl, LOG_ERR,
+                           "%s: connect failed for `%s' (%m)",
+                           __func__, b->b_path);
+                       goto out;
+               }
+       }
+
+       if (srv) {
+               om = umask(0);
+               rv = bind(b->b_fd, (const void *)&sun,
+                   (socklen_t)sizeof(sun));
+               serrno = errno;
+               (void)umask(om);
+               errno = serrno;
+               if (rv == -1) {
+                       bl_log(bl, LOG_ERR,
+                           "%s: bind failed for `%s' (%m)",
+                           __func__, b->b_path);
+                       goto out;
+               }
        }
 
        b->b_connected = true;
 #ifdef LOCAL_CREDS
        if (setsockopt(b->b_fd, 0, LOCAL_CREDS,
            &one, (socklen_t)sizeof(one)) == -1) {
-               (*b->b_fun)(LOG_ERR, "%s: setsockopt LOCAL_CREDS "
+               bl_log(bl, LOG_ERR, "%s: setsockopt LOCAL_CREDS "
                    "failed (%m)", __func__);
                goto out;
        }
@@ -177,12 +207,12 @@
 }
 
 bl_t
-bl_create(bool srv, const char *path, void (*fun)(int, const char *, ...))
+bl_create(bool srv, const char *path, void (*fun)(int, const char *, va_list))
 {
        bl_t b = calloc(1, sizeof(*b));
        if (b == NULL)
                goto out;
-       b->b_fun = fun == NULL ? syslog : fun;
+       b->b_fun = fun == NULL ? vsyslog : fun;
        b->b_fd = -1;
        strlcpy(b->b_path, path ? path : _PATH_BLSOCK, MAXPATHLEN);
        b->b_connected = false;
@@ -302,20 +332,20 @@
 
         rlen = recvmsg(b->b_fd, &msg, 0);
         if (rlen == -1) {
-               (*b->b_fun)(LOG_ERR, "%s: recvmsg failed (%m)", __func__);
+               bl_fun(bl, LOG_ERR, "%s: recvmsg failed (%m)", __func__);
                return NULL;
         }
 
        for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
                if (cmsg->cmsg_level != SOL_SOCKET) {
-                       (*b->b_fun)(LOG_ERR, "%s: unexpected cmsg_level %d",
+                       bl_fun(bl, LOG_ERR, "%s: unexpected cmsg_level %d",
                            __func__, cmsg->cmsg_level);
                        continue;
                }
                switch (cmsg->cmsg_type) {
                case SCM_RIGHTS:
                        if (cmsg->cmsg_len != CMSG_LEN(sizeof(int))) {
-                               (*b->b_fun)(LOG_ERR,



Home | Main Index | Thread Index | Old Index