Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/blacklist/bin format better.
details: https://anonhg.NetBSD.org/src/rev/70f9f8031bcf
branches: trunk
changeset: 335797:70f9f8031bcf
user: christos <christos%NetBSD.org@localhost>
date: Sat Jan 24 06:05:08 2015 +0000
description:
format better.
diffstat:
external/bsd/blacklist/bin/blacklistctl.c | 43 ++++++++++++++++++++++++------
external/bsd/blacklist/bin/support.c | 40 +++++++++++++++++++++++++++-
external/bsd/blacklist/bin/support.h | 3 +-
3 files changed, 74 insertions(+), 12 deletions(-)
diffs (163 lines):
diff -r 19639d7451bf -r 70f9f8031bcf external/bsd/blacklist/bin/blacklistctl.c
--- a/external/bsd/blacklist/bin/blacklistctl.c Sat Jan 24 02:58:56 2015 +0000
+++ b/external/bsd/blacklist/bin/blacklistctl.c Sat Jan 24 06:05:08 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: blacklistctl.c,v 1.11 2015/01/22 20:21:57 christos Exp $ */
+/* $NetBSD: blacklistctl.c,v 1.12 2015/01/24 06:05:08 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: blacklistctl.c,v 1.11 2015/01/22 20:21:57 christos Exp $");
+__RCSID("$NetBSD: blacklistctl.c,v 1.12 2015/01/24 06:05:08 christos Exp $");
#include <stdio.h>
#include <time.h>
@@ -56,7 +56,7 @@
usage(int c)
{
warnx("Unknown option `%c'", (char)c);
- fprintf(stderr, "Usage: %s [-d]\n", getprogname());
+ fprintf(stderr, "Usage: %s [-abdr]\n", getprogname());
exit(EXIT_FAILURE);
}
@@ -69,14 +69,27 @@
struct sockaddr_storage ss;
struct dbinfo dbi;
unsigned int i;
+ struct timespec ts;
+ int all, blocked, remain;
int o;
+ blocked = all = remain = 0;
lfun = dlog;
- while ((o = getopt(argc, argv, "d")) != -1)
+ while ((o = getopt(argc, argv, "abdr")) != -1)
switch (o) {
+ case 'a':
+ all = 1;
+ blocked = 0;
+ break;
+ case 'b':
+ blocked = 1;
+ break;
case 'd':
debug++;
break;
+ case 'r':
+ remain = 1;
+ break;
default:
usage(o);
break;
@@ -86,14 +99,26 @@
if (db == NULL)
err(EXIT_FAILURE, "Can't open `%s'", dbname);
+ clock_gettime(CLOCK_REALTIME, &ts);
for (i = 1; state_iterate(db, &ss, &c, &dbi, i) != 0; i = 0) {
char buf[BUFSIZ];
- (*lfun)(LOG_DEBUG, "conf: %s", conf_print(buf, sizeof(buf), "",
- ":", &c));
+ if (!all) {
+ if (blocked) {
+ if (dbi.count < c.c_nfail)
+ continue;
+ } else {
+ if (dbi.count >= c.c_nfail)
+ continue;
+ }
+ }
sockaddr_snprintf(buf, sizeof(buf), "%a", (void *)&ss);
- (*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));
+ printf("%15.15s:%d\t", buf, c.c_port);
+ if (remain)
+ fmtydhms(buf, sizeof(buf),
+ (ts.tv_sec - dbi.last) - c.c_duration);
+ else
+ fmttime(buf, sizeof(buf), dbi.last);
+ printf("%s\t%d/%d\t%-s\n", dbi.id, dbi.count, c.c_nfail, buf);
}
state_close(db);
return EXIT_SUCCESS;
diff -r 19639d7451bf -r 70f9f8031bcf external/bsd/blacklist/bin/support.c
--- a/external/bsd/blacklist/bin/support.c Sat Jan 24 02:58:56 2015 +0000
+++ b/external/bsd/blacklist/bin/support.c Sat Jan 24 06:05:08 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: support.c,v 1.4 2015/01/22 16:19:53 christos Exp $ */
+/* $NetBSD: support.c,v 1.5 2015/01/24 06:05:08 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: support.c,v 1.4 2015/01/22 16:19:53 christos Exp $");
+__RCSID("$NetBSD: support.c,v 1.5 2015/01/24 06:05:08 christos Exp $");
#include <time.h>
#include <string.h>
@@ -95,3 +95,39 @@
strftime(b, l, "%Y/%m/%d %H:%M:%S", &tm);
return b;
}
+
+const char *
+fmtydhms(char *b, size_t l, time_t t)
+{
+ time_t s, m, h, d, y;
+ int z;
+ size_t o;
+
+ s = t % 60;
+ t /= 60;
+ m = t % 60;
+ t /= 60;
+ h = t % 60;
+ t /= 24;
+ d = t % 24;
+ t /= 356;
+ y = t;
+
+ z = 0;
+ o = 0;
+#define APPEND(a) \
+ if (a) { \
+ z = snprintf(b + o, l - o, "%jd%s", (intmax_t)a, __STRING(a)); \
+ if (z == -1) \
+ return b; \
+ o += (size_t)z; \
+ if (o >= l) \
+ return b; \
+ }
+ APPEND(y)
+ APPEND(d)
+ APPEND(h)
+ APPEND(m)
+ APPEND(s)
+ return b;
+}
diff -r 19639d7451bf -r 70f9f8031bcf external/bsd/blacklist/bin/support.h
--- a/external/bsd/blacklist/bin/support.h Sat Jan 24 02:58:56 2015 +0000
+++ b/external/bsd/blacklist/bin/support.h Sat Jan 24 06:05:08 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: support.h,v 1.3 2015/01/22 16:19:53 christos Exp $ */
+/* $NetBSD: support.h,v 1.4 2015/01/24 06:05:08 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,6 +33,7 @@
__BEGIN_DECLS
const char *fmttime(char *, size_t, time_t);
+const char *fmtydhms(char *, size_t, time_t);
void vdlog(int, const char *, va_list);
void dlog(int, const char *, ...);
__END_DECLS
Home |
Main Index |
Thread Index |
Old Index