Works on both linux and macosx

This commit is contained in:
christos 2015-01-22 04:13:04 +00:00
parent bcdaafa19b
commit 1f0a764fdf
6 changed files with 34 additions and 28 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: blacklistd.c,v 1.15 2015/01/22 03:48:07 christos Exp $ */
/* $NetBSD: blacklistd.c,v 1.16 2015/01/22 04:13:04 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.15 2015/01/22 03:48:07 christos Exp $");
__RCSID("$NetBSD: blacklistd.c,v 1.16 2015/01/22 04:13:04 christos Exp $");
#include <sys/types.h>
#include <sys/socket.h>
@ -162,7 +162,8 @@ process(bl_t bl)
goto out;
}
if (c.c_nfail != -1 && dbi.count >= c.c_nfail) {
int res = run_add(&c, &rss, dbi.id, sizeof(dbi.id));
int res = run_change("add", &c, &rss,
dbi.id, sizeof(dbi.id));
if (res == -1)
goto out;
sockaddr_snprintf(rbuf, sizeof(rbuf), "%a",
@ -218,7 +219,7 @@ update(void)
if (c.c_duration == -1 || when >= ts.tv_sec)
continue;
if (dbi.id[0]) {
run_rem(&c, dbi.id);
run_change("rem", &c, &ss, dbi.id, 0);
sockaddr_snprintf(buf, sizeof(buf), "%a", (void *)&ss);
syslog(LOG_INFO,
"Released %s at port %d after %d seconds",

View File

@ -1,4 +1,4 @@
/* $NetBSD: conf.c,v 1.10 2015/01/22 03:10:49 christos Exp $ */
/* $NetBSD: conf.c,v 1.11 2015/01/22 04:13:04 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: conf.c,v 1.10 2015/01/22 03:10:49 christos Exp $");
__RCSID("$NetBSD: conf.c,v 1.11 2015/01/22 04:13:04 christos Exp $");
#include <stdio.h>
#include <string.h>
@ -519,6 +519,12 @@ conf_parse(const char *f)
for (; (line = fparseln(fp, &len, &lineno, NULL, 0)) != NULL;
free(line))
{
#ifdef __APPLE__
if (!*line)
continue;
if (debug > 4)
printf("%s, %zu: [%s]\n", f, lineno, line);
#endif
if (nc == mc) {
mc += 10;
tc = realloc(c, mc * sizeof(*c));

View File

@ -1,4 +1,4 @@
/* $NetBSD: run.c,v 1.7 2015/01/22 03:10:49 christos Exp $ */
/* $NetBSD: run.c,v 1.8 2015/01/22 04:13:04 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: run.c,v 1.7 2015/01/22 03:10:49 christos Exp $");
__RCSID("$NetBSD: run.c,v 1.8 2015/01/22 04:13:04 christos Exp $");
#include <stdio.h>
#ifdef HAVE_UTIL_H
@ -100,7 +100,7 @@ run_flush(const struct conf *c)
}
int
run_add(const struct conf *c,
run_change(const char *how, const struct conf *c,
const struct sockaddr_storage *ss, char *id, size_t len)
{
const char *prname;
@ -122,18 +122,14 @@ run_add(const struct conf *c,
snprintf(poname, sizeof(poname), "%d", c->c_port);
sockaddr_snprintf(adname, sizeof(adname), "%a", (const void *)ss);
rv = run("add", c->c_name, prname, adname, poname, NULL);
rv = run(how, c->c_name, prname, adname, poname, id, NULL);
if (rv == NULL)
return -1;
rv[strcspn(rv, "\n")] = '\0';
off = strncmp(rv, "OK ", 3) == 0 ? 3 : 0;
strlcpy(id, rv + off, len);
if (len != 0) {
rv[strcspn(rv, "\n")] = '\0';
off = strncmp(rv, "OK ", 3) == 0 ? 3 : 0;
strlcpy(id, rv + off, len);
}
free(rv);
return 0;
}
void
run_rem(const struct conf *c, const char *id)
{
free(run("rem", c->c_name, id, NULL));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: run.h,v 1.3 2015/01/21 19:24:03 christos Exp $ */
/* $NetBSD: run.h,v 1.4 2015/01/22 04:13:04 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@ -35,9 +35,8 @@ __BEGIN_DECLS
struct conf;
void run_flush(const struct conf *);
struct sockaddr_storage;
int run_add(const struct conf *, const struct sockaddr_storage *,
char *, size_t);
void run_rem(const struct conf *, const char *);
int run_change(const char *, const struct conf *,
const struct sockaddr_storage *, char *, size_t);
__END_DECLS
#endif /* _RUN_H */

View File

@ -1,4 +1,4 @@
/* $NetBSD: state.c,v 1.7 2015/01/22 03:10:49 christos Exp $ */
/* $NetBSD: state.c,v 1.8 2015/01/22 04:13:04 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: state.c,v 1.7 2015/01/22 03:10:49 christos Exp $");
__RCSID("$NetBSD: state.c,v 1.8 2015/01/22 04:13:04 christos Exp $");
#include <sys/types.h>
#include <sys/socket.h>
@ -75,6 +75,10 @@ state_open(const char *dbname, int flags, mode_t perm)
{
DB *db;
#ifdef __APPLE__
flags &= O_CREAT|O_EXCL|O_EXLOCK|O_NONBLOCK|O_RDONLY|
O_RDWR|O_SHLOCK|O_TRUNC;
#endif
db = dbopen(dbname, flags, perm, DB_HASH, &openinfo);
if (db == NULL) {
if (errno == ENOENT && (flags & O_CREAT) == 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: srvtest.c,v 1.6 2015/01/22 03:48:07 christos Exp $ */
/* $NetBSD: srvtest.c,v 1.7 2015/01/22 04:13:04 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: srvtest.c,v 1.6 2015/01/22 03:48:07 christos Exp $");
__RCSID("$NetBSD: srvtest.c,v 1.7 2015/01/22 04:13:04 christos Exp $");
#include <sys/types.h>
#include <sys/socket.h>
@ -94,7 +94,7 @@ cr(int af, int type, in_port_t p)
s6->sin6_port = p;
}
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
ss->ss_len = slen;
ss.ss_len = slen;
#endif
if (bind(sfd, (const void *)&ss, slen) == -1)