summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--announce.c36
-rw-r--r--cfgdir.c97
-rw-r--r--config.c60
-rw-r--r--ctest.c74
-rw-r--r--idle.c63
-rw-r--r--igmp.c115
-rw-r--r--main.c86
-rw-r--r--main.h9
-rw-r--r--proxy.c22
-rw-r--r--rcon.c50
-rw-r--r--server.c119
-rw-r--r--stest.c102
-rw-r--r--systemd.c16
-rw-r--r--uring.c90
-rw-r--r--utils.c38
15 files changed, 403 insertions, 574 deletions
diff --git a/announce.c b/announce.c
index ecb48af..dd93bec 100644
--- a/announce.c
+++ b/announce.c
@@ -21,7 +21,7 @@ mcast_free(struct uring_task *task)
{
struct announce *aev = container_of(task, struct announce, mcast_task);
- debug(DBG_ANN, "task %p, aev %p\n", task, aev);
+ debug(DBG_ANN, "task %p, aev %p", task, aev);
}
static void
@@ -30,12 +30,12 @@ mcast_sent(struct cfg *cfg, struct uring_task *task, int res)
struct server *server;
if (res < 0)
- error("failure %i\n", res);
+ error("failure %i", res);
else
- debug(DBG_ANN, "result %i\n", res);
+ debug(DBG_ANN, "result %i", res);
if (!task || !task->tbuf) {
- error("task or task->tbuf not set\n");
+ error("task or task->tbuf not set");
return;
}
@@ -56,7 +56,7 @@ mcast_send(struct cfg *cfg, struct announce *aev, struct server *server)
server->pretty_name, server->announce_port);
if (len < 1 || len >= sizeof(server->mcast_buf.buf)) {
- error("snprintf returned %i\n", len);
+ error("snprintf returned %i", len);
return;
}
@@ -72,7 +72,7 @@ mcast_send_all(struct cfg *cfg, struct announce *aev)
struct server *server;
list_for_each_entry(server, &cfg->servers, list) {
- verbose("Announcing server: %s\n", server->name);
+ verbose("Announcing server: %s", server->name);
mcast_send(cfg, aev, server);
}
}
@@ -84,10 +84,12 @@ announce_cb(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_ANN, task);
- if (res != sizeof(aev->value))
- perrordie("timerfd_read");
+ if (res != sizeof(aev->value)) {
+ error("timerfd_read: %m");
+ return;
+ }
- debug(DBG_ANN, "timerfd value %" PRIu64 "\n", aev->value);
+ debug(DBG_ANN, "timerfd value %" PRIu64, aev->value);
mcast_send_all(cfg, aev);
uring_read(cfg, &aev->task, &aev->value, sizeof(aev->value), announce_cb);
}
@@ -97,7 +99,7 @@ announce_free(struct uring_task *task)
{
struct announce *aev = container_of(task, struct announce, task);
- debug(DBG_ANN, "task %p, aev 0x%p\n", task, aev);
+ debug(DBG_ANN, "task %p, aev 0x%p", task, aev);
xfree(aev);
}
@@ -115,11 +117,11 @@ void
announce_delete(struct cfg *cfg)
{
if (!cfg->aev) {
- error("missing parameters\n");
+ error("missing parameters");
return;
}
- debug(DBG_ANN, "closing fd %i\n", cfg->aev->task.fd);
+ debug(DBG_ANN, "closing fd %i", cfg->aev->task.fd);
uring_task_destroy(cfg, &cfg->aev->mcast_task);
uring_task_destroy(cfg, &cfg->aev->task);
cfg->aev = NULL;
@@ -140,7 +142,7 @@ announce_stop(struct announce *aev)
};
if (timerfd_settime(aev->task.fd, 0, &tspec, NULL) != 0)
- perrordie("timerfd_settime");
+ error("timerfd_settime: %m");
}
void
@@ -158,7 +160,7 @@ announce_start(struct announce *aev)
};
if (timerfd_settime(aev->task.fd, 0, &tspec, NULL) != 0)
- perrordie("timerfd_settime");
+ error("timerfd_settime: %m");
}
void
@@ -170,15 +172,15 @@ announce_init(struct cfg *cfg)
aev = zmalloc(sizeof(*aev));
if (!aev)
- perrordie("malloc");
+ die("malloc: %m");
afd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
if (afd < 0)
- perrordie("timerfd_create");
+ die("timerfd_create: %m");
sfd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (sfd < 0)
- perrordie("socket");
+ die("socket: %m");
uring_task_init(&aev->task, "aev", uring_parent(cfg), announce_free);
uring_task_set_fd(&aev->task, afd);
diff --git a/cfgdir.c b/cfgdir.c
index fc1633b..2e73719 100644
--- a/cfgdir.c
+++ b/cfgdir.c
@@ -28,26 +28,26 @@ scfg_dns_cb(struct dns_async *dns, bool (*server_cb)(struct cfg *, struct server
int r;
if (!dns || !dns->priv || !server_cb) {
- error("invalid arguments\n");
+ error("invalid arguments");
return;
}
scfg = dns->priv;
cfg = scfg->cfg;
- debug(DBG_DNS, "called, dns: %p, name: %s, scfg: %p, scfg->name: %s\n",
+ debug(DBG_DNS, "called, dns: %p, name: %s, scfg: %p, scfg->name: %s",
dns, dns->name, scfg, scfg->name);
r = gai_error(&dns->gcb);
if (r == EAI_INPROGRESS) {
/* This shouldn't happen, assume we'll get called again */
- error("called with request in progress\n");
+ error("called with request in progress");
return;
} else if (r == EAI_CANCELED) {
/* The server must be in the process of going away */
goto out;
} else if (r < 0) {
- error("DNS lookup of %s:%s failed: %s\n",
+ error("DNS lookup of %s:%s failed: %s",
dns->name, dns->port, gai_strerror(r));
goto out;
}
@@ -57,7 +57,7 @@ scfg_dns_cb(struct dns_async *dns, bool (*server_cb)(struct cfg *, struct server
for (ai = results; ai; ai = ai->ai_next) {
saddr = zmalloc(sizeof(*saddr));
if (!saddr) {
- error("DNS lookup of %s:%s failed: %m\n", dns->name, dns->port);
+ error("DNS lookup of %s:%s failed: %m", dns->name, dns->port);
goto out;
}
@@ -75,7 +75,7 @@ scfg_dns_cb(struct dns_async *dns, bool (*server_cb)(struct cfg *, struct server
break;
default:
- error("getaddrinfo(%s:%s): unknown address family (%i)\n",
+ error("getaddrinfo(%s:%s): unknown address family (%i)",
dns->name, dns->port, ai->ai_family);
xfree(saddr);
break;
@@ -195,7 +195,7 @@ handle_dns(struct cfg *cfg, struct server *scfg, const char *type,
switch (value->type) {
case CFG_VAL_TYPE_ADDRS:
- debug(DBG_DNS, "%s: got immediate addrs\n", type);
+ debug(DBG_DNS, "%s: got immediate addrs", type);
list_for_each_entry_safe(saddr, tmp, &value->saddrs, list) {
list_del(&saddr->list);
@@ -204,7 +204,7 @@ handle_dns(struct cfg *cfg, struct server *scfg, const char *type,
return true;
case CFG_VAL_TYPE_ASYNC_ADDRS:
- debug(DBG_DNS, "%s: doing async lookup of DNS record: %p\n",
+ debug(DBG_DNS, "%s: doing async lookup of DNS record: %p",
type, value->dns_async);
dns = value->dns_async;
@@ -239,7 +239,7 @@ scfg_parse(struct cfg *cfg, struct server *scfg)
if (key == SCFG_KEY_INVALID)
break;
- debug(DBG_CFG, "%s: key %s\n", scfg->name, keyname);
+ debug(DBG_CFG, "%s: key %s", scfg->name, keyname);
switch (key) {
@@ -344,12 +344,12 @@ scfg_read_cb(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_CFG, task);
if (res <= 0) {
- error("error reading config file for %s: %s\n",
+ error("error reading config file for %s: %s",
scfg->name, strerror(-res));
server_delete(cfg, scfg);
}
- debug(DBG_CFG, "%s: parsing cfg (%i bytes)\n", scfg->name, res);
+ debug(DBG_CFG, "%s: parsing cfg (%i bytes)", scfg->name, res);
uring_task_close_fd(cfg, &scfg->task);
scfg_parse(cfg, scfg);
server_commit(cfg, scfg);
@@ -363,12 +363,12 @@ scfg_open_cb(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_CFG, task);
if (res < 0) {
- error("open(%s) failed: %s\n", scfg->name, strerror(-res));
+ error("open(%s) failed: %s", scfg->name, strerror(-res));
server_delete(cfg, scfg);
return;
}
- debug(DBG_CFG, "reading server cfg %s (fd %i)\n", scfg->name, res);
+ debug(DBG_CFG, "reading server cfg %s (fd %i)", scfg->name, res);
uring_task_set_fd(&scfg->task, res);
uring_tbuf_read_until_eof(cfg, &scfg->task, scfg_read_cb);
}
@@ -401,7 +401,7 @@ inotify_free(struct uring_task *task)
struct inotify_ev *iev = container_of(task, struct inotify_ev, task);
struct cfg *cfg = container_of(task->parent, struct cfg, task);
- debug(DBG_CFG, "called\n");
+ debug(DBG_CFG, "called");
if (!iev || !cfg)
die("iev or cfg is NULL!?");
@@ -413,43 +413,42 @@ inotify_free(struct uring_task *task)
static void
inotify_event_dump(const struct inotify_event *event)
{
- debug(DBG_CFG, "inotify event:\n");
- debug(DBG_CFG, " * WD : %i\n", event->wd);
- debug(DBG_CFG, " * Cookie : %" PRIu32 "\n", event->cookie);
- debug(DBG_CFG, " * Length : %" PRIu32 "\n", event->len);
- debug(DBG_CFG, " * Name : %s\n", event->name);
- debug(DBG_CFG, " * Mask : %" PRIu32 "\n", event->mask);
+ debug(DBG_CFG, "inotify event:");
+ debug(DBG_CFG, " * WD : %i", event->wd);
+ debug(DBG_CFG, " * Cookie : %" PRIu32, event->cookie);
+ debug(DBG_CFG, " * Length : %" PRIu32, event->len);
+ debug(DBG_CFG, " * Name : %s", event->name);
+ debug(DBG_CFG, " * Mask : %" PRIu32, event->mask);
if (event->mask & IN_ACCESS)
- debug(DBG_CFG, "\tIN_ACCESS\n");
+ debug(DBG_CFG, "\tIN_ACCESS");
else if(event->mask & IN_MODIFY)
- debug(DBG_CFG, "\tIN_MODIFY\n");
+ debug(DBG_CFG, "\tIN_MODIFY");
else if(event->mask & IN_ATTRIB)
- debug(DBG_CFG, "\tIN_ATTRIB\n");
+ debug(DBG_CFG, "\tIN_ATTRIB");
else if(event->mask & IN_CLOSE_WRITE)
- debug(DBG_CFG, "\tIN_CLOSE_WRITE\n");
+ debug(DBG_CFG, "\tIN_CLOSE_WRITE");
else if(event->mask & IN_CLOSE_NOWRITE)
- debug(DBG_CFG, "\tIN_CLOSE_NOWRITE\n");
+ debug(DBG_CFG, "\tIN_CLOSE_NOWRITE");
else if(event->mask & IN_OPEN)
- debug(DBG_CFG, "\tIN_OPEN\n");
+ debug(DBG_CFG, "\tIN_OPEN");
else if(event->mask & IN_MOVED_FROM)
- debug(DBG_CFG, "\tIN_MOVED_FROM\n");
+ debug(DBG_CFG, "\tIN_MOVED_FROM");
else if(event->mask & IN_MOVED_TO)
- debug(DBG_CFG, "\tIN_MOVED_TO\n");
+ debug(DBG_CFG, "\tIN_MOVED_TO");
else if(event->mask & IN_CREATE)
- debug(DBG_CFG, "\tIN_CREATE\n");
+ debug(DBG_CFG, "\tIN_CREATE");
else if(event->mask & IN_DELETE)
- debug(DBG_CFG, "\tIN_DELETE\n");
+ debug(DBG_CFG, "\tIN_DELETE");
else if(event->mask & IN_DELETE_SELF)
- debug(DBG_CFG, "\tIN_DELETE_SELF\n");
+ debug(DBG_CFG, "\tIN_DELETE_SELF");
else if(event->mask & IN_MOVE_SELF)
- debug(DBG_CFG, "\tIN_MOVE_SELF\n");
+ debug(DBG_CFG, "\tIN_MOVE_SELF");
else if(event->mask & IN_UNMOUNT)
- debug(DBG_CFG, "\tIN_UNMOUNT\n");
+ debug(DBG_CFG, "\tIN_UNMOUNT");
else if(event->mask & IN_Q_OVERFLOW)
- debug(DBG_CFG, "\tIN_Q_OVERFLOW\n");
+ debug(DBG_CFG, "\tIN_Q_OVERFLOW");
else if(event->mask & IN_IGNORED)
- debug(DBG_CFG, "\tIN_IGNORED\n");
- debug(DBG_CFG, "\n");
+ debug(DBG_CFG, "\tIN_IGNORED");
}
static void
@@ -462,8 +461,10 @@ inotify_cb(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_CFG, task);
- if (res <= 0)
- perrordie("inotify_read (%i)", res);
+ if (res <= 0) {
+ error("inotify_read: %i", res);
+ return;
+ }
for (ptr = iev->buf; ptr < iev->buf + res; ptr += sizeof(struct inotify_event) + event->len) {
event = (const struct inotify_event *)ptr;
@@ -472,10 +473,10 @@ inotify_cb(struct cfg *cfg, struct uring_task *task, int res)
inotify_event_dump(event);
if (event->mask & (IN_IGNORED | IN_MOVE_SELF | IN_DELETE_SELF | IN_UNMOUNT))
- die("Configuration directory gone, exiting");
+ die("configuration directory gone, exiting");
if (event->mask & IN_Q_OVERFLOW) {
- error("inotify queue overflow!\n");
+ error("inotify queue overflow");
continue;
}
@@ -486,10 +487,10 @@ inotify_cb(struct cfg *cfg, struct uring_task *task, int res)
server_delete_by_name(cfg, event->name);
else if (event->mask & (IN_MOVED_TO | IN_CREATE | IN_CLOSE_WRITE)) {
scfg = server_new(cfg, event->name);
- verbose("New server config file detected: %s\n", scfg->name);
+ verbose("New server config file detected: %s", scfg->name);
uring_openat(cfg, &scfg->task, scfg->name, scfg_open_cb);
} else
- error("inotify: unknown event: 0x%08x\n", event->mask);
+ error("inotify: unknown event: 0x%08x", event->mask);
}
uring_read(cfg, &iev->task, iev->buf, sizeof(iev->buf), inotify_cb);
@@ -505,11 +506,11 @@ void
cfgdir_delete(struct cfg *cfg)
{
if (!cfg->iev) {
- error("missing arguments\n");
+ error("missing arguments");
return;
}
- debug(DBG_CFG, "closing fd %i\n", cfg->iev->task.fd);
+ debug(DBG_CFG, "closing fd %i", cfg->iev->task.fd);
uring_task_destroy(cfg, &cfg->iev->task);
cfg->iev = NULL;
}
@@ -526,11 +527,11 @@ cfgdir_init(struct cfg *cfg)
iev = zmalloc(sizeof(*iev));
if (!iev)
- perrordie("malloc");
+ die("malloc: %m");
ifd = inotify_init1(IN_CLOEXEC);
if (ifd < 0)
- perrordie("inotify_init1");
+ die("inotify_init1: %m");
/* ln = IN_CREATE, cp/vi/mv = IN_CREATE, IN_OPEN, IN_CLOSE_WRITE */
iwd = inotify_add_watch(ifd, ".",
@@ -539,7 +540,7 @@ cfgdir_init(struct cfg *cfg)
IN_MOVED_FROM | IN_DONT_FOLLOW |
IN_EXCL_UNLINK | IN_ONLYDIR );
if (iwd < 0)
- perrordie("inotify_add_watch");
+ die("inotify_add_watch: %m");
uring_task_init(&iev->task, "iev", uring_parent(cfg), inotify_free);
uring_task_set_fd(&iev->task, ifd);
@@ -548,7 +549,7 @@ cfgdir_init(struct cfg *cfg)
dir = opendir(".");
if (!dir)
- perrordie("opendir");
+ die("opendir(%s): %m", cfg->homedir);
while ((dent = readdir(dir)) != NULL) {
if (dent->d_type != DT_REG && dent->d_type != DT_UNKNOWN)
diff --git a/config.c b/config.c
index 199ba0b..30c9cde 100644
--- a/config.c
+++ b/config.c
@@ -78,14 +78,14 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue, bool async)
rvalue->dns_async = NULL;
dns = zmalloc(sizeof(*dns));
if (!dns) {
- error("async DNS lookup of %s failed: %m\n", name);
+ error("async DNS lookup of %s failed: %m", name);
goto out;
}
- debug(DBG_DNS, "doing async DNS lookup of %s: %p\n", name, dns);
+ debug(DBG_DNS, "doing async DNS lookup of %s: %p", name, dns);
} else {
memset(&tmp, 0, sizeof(tmp));
dns = &tmp;
- debug(DBG_DNS, "doing sync DNS lookup of %s\n", name);
+ debug(DBG_DNS, "doing sync DNS lookup of %s", name);
}
sprintf(dns->name, "%s", name);
@@ -108,7 +108,7 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue, bool async)
r = getaddrinfo_a(mode, gcbs, ARRAY_SIZE(gcbs), &dns->sev);
if (r != 0) {
- error("getaddrinfo(%s:%" PRIu16 "): %s\n", name, port, gai_strerror(r));
+ error("getaddrinfo(%s:%" PRIu16 "): %s", name, port, gai_strerror(r));
goto out;
}
@@ -123,7 +123,7 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue, bool async)
for (ai = results; ai; ai = ai->ai_next) {
saddr = zmalloc(sizeof(*saddr));
if (!saddr) {
- error("sync DNS lookup of %s failed: %m\n", name);
+ error("sync DNS lookup of %s failed: %m", name);
goto out;
}
@@ -131,19 +131,19 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue, bool async)
case AF_INET:
in4 = (struct sockaddr_in *)ai->ai_addr;
saddr_set_ipv4(saddr, in4->sin_addr.s_addr, in4->sin_port);
- error("addrstr: %s\n", saddr->addrstr);
+ error("addrstr: %s", saddr->addrstr);
list_add(&saddr->list, &rvalue->saddrs);
break;
case AF_INET6:
in6 = (struct sockaddr_in6 *)ai->ai_addr;
saddr_set_ipv6(saddr, &in6->sin6_addr, in6->sin6_port);
- error("addrstr: %s\n", saddr->addrstr);
+ error("addrstr: %s", saddr->addrstr);
list_add(&saddr->list, &rvalue->saddrs);
break;
default:
- error("getaddrinfo(%s:%s): unknown address family (%i)\n",
+ error("getaddrinfo(%s:%s): unknown address family (%i)",
dns->name, dns->port, ai->ai_family);
xfree(saddr);
break;
@@ -175,7 +175,7 @@ strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
if (*str == '[') {
/* IPv6, [a:b:c...h]:p or [*]:p */
- debug(DBG_CFG, "attempting to parse IPv6 addr (%s)\n", str);
+ debug(DBG_CFG, "attempting to parse IPv6 addr (%s)", str);
str++;
tmp = strchr(str, ']');
@@ -208,7 +208,7 @@ strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
} else if (*str == '*') {
/* IPv4, *:p */
- debug(DBG_CFG, "attempting to parse IPv4 addr (%s)\n", str);
+ debug(DBG_CFG, "attempting to parse IPv4 addr (%s)", str);
str++;
if (*str != ':')
@@ -228,7 +228,7 @@ strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
} else if ((tmp = strchr(str, ':'))) {
/* IPv4, a.b.c.d:p or IPv4/6 hostname:p */
- debug(DBG_CFG, "attempting to parse IPv4 addr or hostname (%s)\n", str);
+ debug(DBG_CFG, "attempting to parse IPv4 addr or hostname (%s)", str);
*tmp = '\0';
tmp++;
@@ -240,7 +240,7 @@ strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
goto error;
if (inet_pton(AF_INET, str, &saddr->in4.sin_addr) > 0) {
- debug(DBG_CFG, "got an IPv4:port (%s:%" PRIu16 ")\n", str, port);
+ debug(DBG_CFG, "got an IPv4:port (%s:%" PRIu16 ")", str, port);
saddr_set_ipv4(saddr, saddr->in4.sin_addr.s_addr, htons(port));
list_add(&saddr->list, list);
naddrs++;
@@ -248,13 +248,13 @@ strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
}
xfree(saddr);
- debug(DBG_CFG, "maybe got a hostname:port (%s:%" PRIu16 ")\n", str, port);
+ debug(DBG_CFG, "maybe got a hostname:port (%s:%" PRIu16 ")", str, port);
if (!dnslookup(str, port, rvalue, async))
goto error;
} else if (strtou16_strict(tmp, &port) == 0) {
/* Port */
- debug(DBG_CFG, "attempting to parse a port number (%s)\n", str);
+ debug(DBG_CFG, "attempting to parse a port number (%s)", str);
saddr = zmalloc(sizeof(*saddr));
if (!saddr)
@@ -274,7 +274,7 @@ strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async)
} else {
/* Unknown */
- error("unable to parse address: %s\n", str);
+ error("unable to parse address: %s", str);
goto error;
}
@@ -282,19 +282,19 @@ success:
switch (rvalue->type) {
case CFG_VAL_TYPE_ADDRS:
if (list_empty(list) || naddrs == 0) {
- error("empty address list!?\n");
+ error("empty address list");
return false;
}
- debug(DBG_CFG, "parsed to %u addresses\n", naddrs);
+ debug(DBG_CFG, "parsed to %u addresses", naddrs);
return true;
case CFG_VAL_TYPE_ASYNC_ADDRS:
- debug(DBG_CFG, "looking up address asynchronously\n");
+ debug(DBG_CFG, "looking up address asynchronously");
return true;
default:
- error("invalid rvalue type\n");
+ error("invalid rvalue type");
rvalue->type = CFG_VAL_TYPE_INVALID;
break;
}
@@ -328,7 +328,7 @@ config_parse_line(struct cfg *cfg, const char *filename, char **buf,
if (!line)
return false;
- debug(DBG_CFG, "%s: parsing config line: %s\n", filename, line);
+ debug(DBG_CFG, "%s: parsing config line: %s", filename, line);
tmp = line;
while (isspace(*tmp))
@@ -387,12 +387,12 @@ config_parse_line(struct cfg *cfg, const char *filename, char **buf,
goto error;
if (rvalue->type != CFG_VAL_TYPE_ADDRS) {
- error("invalid type returned from strtosockaddrs\n");
+ error("invalid type returned from strtosockaddrs");
goto error;
}
if (list_empty(&rvalue->saddrs)) {
- error("empty address list\n");
+ error("empty address list");
goto error;
}
break;
@@ -404,20 +404,20 @@ config_parse_line(struct cfg *cfg, const char *filename, char **buf,
switch (rvalue->type) {
case CFG_VAL_TYPE_ADDRS:
if (list_empty(&rvalue->saddrs)) {
- error("empty address list\n");
+ error("empty address list");
goto error;
}
break;
case CFG_VAL_TYPE_ASYNC_ADDRS:
if (!rvalue->dns_async) {
- error("dns_async not set\n");
+ error("dns_async not set");
goto error;
}
break;
default:
- error("invalid type returned from strtosockaddrs\n");
+ error("invalid type returned from strtosockaddrs");
goto error;
}
@@ -431,7 +431,7 @@ config_parse_line(struct cfg *cfg, const char *filename, char **buf,
rvalue->type = CFG_VAL_TYPE_BOOL;
rvalue->boolean = false;
} else {
- error("invalid boolean value (%s)\n", tmp);
+ error("invalid boolean value (%s)", tmp);
goto error;
}
break;
@@ -446,7 +446,7 @@ config_parse_line(struct cfg *cfg, const char *filename, char **buf,
if ((rvalue->type != kvmap[i].value_type) &&
((kvmap[i].value_type != CFG_VAL_TYPE_ASYNC_ADDRS) &&
(rvalue->type != CFG_VAL_TYPE_ADDRS))) {
- error("rvalue->type != kvmap->type\n");
+ error("rvalue->type != kvmap->type");
goto error;
}
@@ -457,7 +457,7 @@ config_parse_line(struct cfg *cfg, const char *filename, char **buf,
error:
/* FIXME: the line is already mangled here, a line number would be nice */
- error("%s: invalid config line: %s\n", filename, line);
+ error("%s: invalid config line: %s", filename, line);
rvalue->type = CFG_VAL_TYPE_INVALID;
*rkey = 0;
*rkeyname = NULL;
@@ -477,14 +477,14 @@ config_parse_header(struct cfg *cfg, const char *filename, const char *title,
line = get_line(buf);
if (!line) {
- error("%s: missing header in configuration file\n", filename);
+ error("%s: missing header in configuration file", filename);
return false;
} else {
char titlehdr[strlen(title) + 3];
sprintf(titlehdr, "[%s]", title);
if (strcmp(line, titlehdr)) {
- error("%s: incorrect header in configuration file\n", filename);
+ error("%s: incorrect header in configuration file", filename);
return false;
}
}
diff --git a/ctest.c b/ctest.c
deleted file mode 100644
index b0a367d..0000000
--- a/ctest.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <netinet/ip.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdbool.h>
-
-#define PIPE_RD 0
-#define PIPE_WR 1
-
-int
-main(int argc, char **argv) {
- int sfd;
- struct sockaddr_in addr;
- int zfd;
- int pfd[2];
- size_t total = 0;
-
- if (argc != 4) {
- fprintf(stderr, "Usage: %s <addr> <port> <64k count>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
-
- sfd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (sfd < 0) {
- perror("socket");
- exit(EXIT_FAILURE);
- }
-
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(atoi(argv[2]));
- addr.sin_addr.s_addr = inet_addr(argv[1]);
-
- if (connect(sfd, &addr, sizeof(addr)) < 0) {
- perror("connect");
- exit(EXIT_FAILURE);
- }
-
- zfd = open("/dev/zero", O_RDONLY | O_CLOEXEC);
- if (zfd < 0) {
- perror("open");
- exit(EXIT_FAILURE);
- }
-
- if (pipe2(pfd, O_CLOEXEC) < 0) {
- perror("pipe2");
- exit(EXIT_FAILURE);
- }
-
- for (int i = 0; i < atoi(argv[3]); i++) {
- ssize_t r, w;
-
- r = splice(zfd, NULL, pfd[PIPE_WR], NULL, 64 * 1024, SPLICE_F_MOVE);
- //fprintf(stderr, "Read %zi bytes from /dev/zero\n", r);
- w = splice(pfd[PIPE_RD], NULL, sfd, NULL, r, SPLICE_F_MOVE);
- //fprintf(stderr, "Wrote %zi bytes to socket\n", w);
- if (r != w) {
- fprintf(stderr, "Read/write mismatch\n");
- exit(EXIT_FAILURE);
- }
- total += w;
- }
-
- printf("Client: sent %zu bytes\n", total);
- exit(EXIT_SUCCESS);
-}
-
diff --git a/idle.c b/idle.c
index 3be8974..4bd0656 100644
--- a/idle.c
+++ b/idle.c
@@ -30,7 +30,7 @@ idle_check_free(struct uring_task *task)
{
struct idle *idle = container_of(task, struct idle, idlecheck);
- debug(DBG_IDLE, "task %p, idle %p\n", task, idle);
+ debug(DBG_IDLE, "task %p, idle %p", task, idle);
}
static inline void
@@ -128,22 +128,22 @@ idle_check_handshake_complete(struct cfg *cfg, struct uring_task *task, int res)
r = read_varint(&pos, &remain, &mclen);
if (r < 0) {
- error("failed to parse message length\n");
+ error("failed to parse message length");
return -EINVAL;
} else if (r == 0) {
return 0;
} else if (mclen < 2) {
- error("short MC message\n");
+ error("short MC message");
return -EINVAL;
}
if (mclen < remain) {
- debug(DBG_IDLE, "short MC message - len: %" PRIi32 ", remain: %zu\n",
+ debug(DBG_IDLE, "short MC message - len: %" PRIi32 ", remain: %zu",
mclen, remain);
return 0;
}
- debug(DBG_IDLE, "Complete message\n");
+ debug(DBG_IDLE, "Complete message");
return 1;
}
@@ -165,7 +165,7 @@ get_player_count(struct cfg *cfg, const char *pos, size_t remain)
online = memmem(pos, remain, ONLINE_NEEDLE, strlen(ONLINE_NEEDLE));
if (!online) {
- error("could not find online count in JSON\n");
+ error("could not find online count in JSON");
return -1;
}
@@ -173,13 +173,13 @@ get_player_count(struct cfg *cfg, const char *pos, size_t remain)
end = memchr(online, '}', remain);
if (!end) {
- error("could not parse JSON (no end)\n");
+ error("could not parse JSON (no end)");
return -1;
}
*end = '\0';
if (sscanf(online, ONLINE_NEEDLE " : %u", &count) != 1) {
- error("could not parse JSON (online count)\n");
+ error("could not parse JSON (online count)");
return -1;
}
@@ -199,15 +199,15 @@ idle_check_handshake_reply(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_IDLE, task);
- debug(DBG_IDLE, "res: %i\n", res);
+ debug(DBG_IDLE, "res: %i", res);
if (res < 0)
goto out;
/*
- fprintf(stderr, "Received MC message (%i bytes):\n", res);
+ fprintf(stderr, "Received MC message (%i bytes):", res);
for (int i = 0; i < res; i++)
fprintf(stderr, "0x%02hhx ", idle->remotebuf[i]);
- fprintf(stderr, "\n");
+ fprintf(stderr, "n");
*/
remain = idle->tbuf.len;
@@ -216,15 +216,15 @@ idle_check_handshake_reply(struct cfg *cfg, struct uring_task *task, int res)
r = read_varint(&pos, &remain, &mclen);
if (r <= 0 || mclen < 2 || mclen < remain) {
/* Should not happen since the msg has been checked already */
- error("invalid message\n");
+ error("invalid message");
goto out;
}
- debug(DBG_IDLE, "MC message - len: %" PRIi32 ", remain: %zu\n",
+ debug(DBG_IDLE, "MC message - len: %" PRIi32 ", remain: %zu",
mclen, remain);
if (*pos != MC_STATUS_REPLY) {
- error("unknown server reply (0x%02hhx)\n", *pos);
+ error("unknown server reply (0x%02hhx)", *pos);
goto out;
}
@@ -233,15 +233,15 @@ idle_check_handshake_reply(struct cfg *cfg, struct uring_task *task, int res)
r = read_varint(&pos, &remain, &jsonlen);
if (r <= 0) {
- error("could not read JSON length\n");
+ error("could not read JSON length");
goto out;
}
- debug(DBG_IDLE, "MC - json len: %" PRIi32 ", remain: %zu\n",
+ debug(DBG_IDLE, "MC - json len: %" PRIi32 ", remain: %zu",
jsonlen, remain);
if (jsonlen < remain) {
- error("invalid JSON length\n");
+ error("invalid JSON length");
goto out;
}
@@ -249,7 +249,6 @@ idle_check_handshake_reply(struct cfg *cfg, struct uring_task *task, int res)
fprintf(stderr, "JSON: ");
for (int i = 0; i < jsonlen; i++)
fprintf(stderr, "%c", pos[i]);
- fprintf(stderr, "\n");
*/
player_count = get_player_count(cfg, pos, remain);
@@ -258,7 +257,7 @@ idle_check_handshake_reply(struct cfg *cfg, struct uring_task *task, int res)
idle->server->state = SERVER_STATE_RUNNING;
- debug(DBG_IDLE, "%s: currently %i active players\n",
+ debug(DBG_IDLE, "%s: currently %i active players",
idle->server->name, player_count);
if (player_count > 0)
@@ -267,7 +266,7 @@ idle_check_handshake_reply(struct cfg *cfg, struct uring_task *task, int res)
idle->server->idle_count++;
if (idle->server->idle_count > idle->server->idle_timeout) {
- verbose("stopping idle server %s\n", idle->server->name);
+ verbose("stopping idle server %s", idle->server->name);
server_stop(cfg, idle->server);
}
@@ -283,7 +282,7 @@ idle_check_handshake_sent(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_IDLE, task);
- debug(DBG_IDLE, "sent %i bytes\n", res);
+ debug(DBG_IDLE, "sent %i bytes", res);
if (res < 0) {
uring_task_close_fd(cfg, task);
return;
@@ -308,14 +307,14 @@ idle_check_connected_cb(struct cfg *cfg, struct connection *conn, bool connected
if (!connected) {
debug(DBG_IDLE,
- "idle check connection to remote server (%s) failed\n",
+ "idle check connection to remote server (%s) failed",
idle->server->name);
idle->server->idle_count = 0;
idle->server->state = SERVER_STATE_STOPPED;
return;
}
- debug(DBG_IDLE, "connected to remote %s\n", idle->conn.remote.addrstr);
+ debug(DBG_IDLE, "connected to remote %s", idle->conn.remote.addrstr);
port = saddr_port(&conn->remote);
saddr_addr(&conn->remote, hostname, sizeof(hostname));
@@ -335,7 +334,7 @@ idle_check_connected_cb(struct cfg *cfg, struct connection *conn, bool connected
write_cmd(&cmdbuf, buf, pos);
idle->tbuf.len = (cmdbuf - idle->tbuf.buf);
- debug(DBG_IDLE, "sending MC message (%zu bytes)\n", idle->tbuf.len);
+ debug(DBG_IDLE, "sending MC message (%zu bytes)", idle->tbuf.len);
uring_tbuf_write(cfg, &idle->idlecheck, idle_check_handshake_sent);
}
@@ -348,11 +347,11 @@ idle_cb(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_IDLE, task);
if (res != sizeof(idle->value)) {
- error("timerfd_read returned %i\n", res);
- perrordie("timerfd_read");
+ error("timerfd_read: %i", res);
+ return;
}
- debug(DBG_IDLE, "timer fired (value: %" PRIu64 ")\n", idle->value);
+ debug(DBG_IDLE, "timer fired (value: %" PRIu64 ")", idle->value);
if (!list_empty(&idle->server->proxys))
idle->server->idle_count = 0;
@@ -368,7 +367,7 @@ idle_free(struct uring_task *task)
{
struct idle *idle = container_of(task, struct idle, task);
- debug(DBG_IDLE, "task %p, idle %p\n", task, idle);
+ debug(DBG_IDLE, "task %p, idle %p", task, idle);
xfree(idle);
}
@@ -390,7 +389,7 @@ idle_delete(struct cfg *cfg, struct server *server)
if (!idle)
return;
- debug(DBG_IDLE, "closing fd %i\n", idle->task.fd);
+ debug(DBG_IDLE, "closing fd %i", idle->task.fd);
uring_task_destroy(cfg, &idle->idlecheck);
uring_task_destroy(cfg, &idle->task);
server->idle = NULL;
@@ -421,14 +420,14 @@ idle_init(struct cfg *cfg, struct server *server)
idle = zmalloc(sizeof(*idle));
if (!idle)
- perrordie("malloc");
+ die("malloc: %m");
ifd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
if (ifd < 0)
- perrordie("timerfd_create");
+ die("timerfd_create: %m");
if (timerfd_settime(ifd, 0, &tspec, NULL) != 0)
- perrordie("timerfd_settime");
+ die("timerfd_settime: %m");
uring_task_init(&idle->task, "idle", &server->task, idle_free);
uring_task_set_fd(&idle->task, ifd);
diff --git a/igmp.c b/igmp.c
index 36f63e2..9ada4e4 100644
--- a/igmp.c
+++ b/igmp.c
@@ -173,7 +173,7 @@ igmp_match()
struct tm *tm = localtime(&t);
char s[64];
strftime(s, sizeof(s), "%c", tm);
- debug(DBG_IGMP, "multicast request discovered at: %s\n", s);
+ debug(DBG_IGMP, "multicast request discovered at: %s", s);
//start announce
}
@@ -218,7 +218,7 @@ igmp_parse(struct cfg *cfg, struct igmp *igmp)
switch (igmp_msg->common.type) {
case IGMP_V1_MEMBERSHIP_REPORT:
- debug(DBG_IGMP, "igmp_v1_membership_report\n");
+ debug(DBG_IGMP, "igmp_v1_membership_report");
/* fall through */
case IGMP_V2_MEMBERSHIP_REPORT: {
@@ -236,29 +236,29 @@ igmp_parse(struct cfg *cfg, struct igmp *igmp)
grp.s_addr = htonl(igmp_msg->v2.addr);
inet_ntop(AF_INET, &grp, grp_str, sizeof(grp_str));
- debug(DBG_IGMP, "igmp_v2_membership_report %s -> %s (%s)\n",
+ debug(DBG_IGMP, "igmp_v2_membership_report %s -> %s (%s)",
src_str, dst_str, grp_str);
if (body_len != IGMP_MIN_LEN) {
- error("IGMPv2 invalid size\n");
+ error("IGMPv2 invalid size");
break;
}
if (!csum_valid((char *)igmp_msg, body_len)) {
- error("IGMPv2 invalid checksum\n");
+ error("IGMPv2 invalid checksum");
break;
}
- debug(DBG_IGMP, "Inet addr: 0x%x\n", inet_addr("224.0.2.60"));
- debug(DBG_IGMP, "Inet addr: 0x%x\n", cinet_addr(224,0,2,60));
- debug(DBG_IGMP, "Inet addr: 0x%x\n", chtobe32(cinet_addr(224,0,2,60)));
+ debug(DBG_IGMP, "Inet addr: 0x%x", inet_addr("224.0.2.60"));
+ debug(DBG_IGMP, "Inet addr: 0x%x", cinet_addr(224,0,2,60));
+ debug(DBG_IGMP, "Inet addr: 0x%x", chtobe32(cinet_addr(224,0,2,60)));
if (htonl(hdr->dst) != cinet_addr(224,0,2,60)) {
- debug(DBG_IGMP, "IGMPv2 invalid dst addr\n");
+ debug(DBG_IGMP, "IGMPv2 invalid dst addr");
break;
}
if (htonl(igmp_msg->v2.addr) != cinet_addr(224,0,2,60)) {
- debug(DBG_IGMP, "IGMPv2 invalid grp addr\n");
+ debug(DBG_IGMP, "IGMPv2 invalid grp addr");
break;
}
@@ -278,7 +278,7 @@ igmp_parse(struct cfg *cfg, struct igmp *igmp)
dst.s_addr = htonl(hdr->dst);
inet_ntop(AF_INET, &dst, dst_str, sizeof(dst_str));
- debug(DBG_IGMP, "igmp_v3_membership_report %s -> %s\n",
+ debug(DBG_IGMP, "igmp_v3_membership_report %s -> %s",
src_str, dst_str);
debug(DBG_IGMP, "IGMPv3\n"
@@ -287,7 +287,7 @@ igmp_parse(struct cfg *cfg, struct igmp *igmp)
" * Csum: %u\n"
" * Reserved: %u\n"
" * NRecs: %u\n"
- " * Size: %zu bytes\n",
+ " * Size: %zu bytes",
igmp_msg->v3.type,
igmp_msg->v3.reserved1,
igmp_msg->v3.checksum,
@@ -296,12 +296,12 @@ igmp_parse(struct cfg *cfg, struct igmp *igmp)
sizeof(igmp_msg->v3));
if (!csum_valid(pos, body_len)) {
- error("IGMPv3 csum invalid\n");
+ error("IGMPv3 csum invalid");
break;
}
if (htonl(hdr->dst) != cinet_addr(224,0,0,22)) {
- debug(DBG_IGMP, "IGMPv2 invalid dst addr\n");
+ debug(DBG_IGMP, "IGMPv2 invalid dst addr");
break;
}
@@ -314,20 +314,20 @@ igmp_parse(struct cfg *cfg, struct igmp *igmp)
char grp_str[INET_ADDRSTRLEN];
if (body_len < sizeof(*record)) {
- error("IGMPv3 too short\n");
+ error("IGMPv3 too short");
break;
}
grp.s_addr = htonl(record->addr);
inet_ntop(AF_INET, &grp, grp_str, sizeof(grp_str));
- debug(DBG_IGMP, "received IGMPv3 record to %s\n", grp_str);
-
- debug(DBG_IGMP, "IGMPv3 rec\n"
- " * Type: %u\n"
- " * Auxlen: %u\n"
- " * NSrcs: %u\n"
- " * Addr: %s\n"
- " * Size: %zu bytes\n",
+ debug(DBG_IGMP, "received IGMPv3 record to %s", grp_str);
+
+ debug(DBG_IGMP, "IGMPv3 rec"
+ " * Type: %un"
+ " * Auxlen: %u"
+ " * NSrcs: %u"
+ " * Addr: %s"
+ " * Size: %zu bytes",
record->type,
record->auxlen,
record->nsrcs,
@@ -338,7 +338,7 @@ igmp_parse(struct cfg *cfg, struct igmp *igmp)
pos += sizeof(*record);
if (body_len < record->nsrcs * sizeof(uint32_t) + record->auxlen) {
- error("IGMPv3 too short\n");
+ error("IGMPv3 too short");
break;
}
@@ -348,7 +348,7 @@ igmp_parse(struct cfg *cfg, struct igmp *igmp)
grp_src.s_addr = htonl(record->saddr[addr]);
inet_ntop(AF_INET, &grp_src, grp_src_str, sizeof(grp_src_str));
- debug(DBG_IGMP, "received IGMPv3 record src %s\n",
+ debug(DBG_IGMP, "received IGMPv3 record src %s",
grp_src_str);
body_len -= sizeof(record->saddr[addr]);
@@ -368,15 +368,15 @@ igmp_parse(struct cfg *cfg, struct igmp *igmp)
}
case IGMP_MEMBERSHIP_QUERY:
- debug(DBG_IGMP, "igmp_membership_query\n");
+ debug(DBG_IGMP, "igmp_membership_query");
break;
case IGMP_V2_LEAVE_GROUP:
- debug(DBG_IGMP, "igmp_v2_leave_group\n");
+ debug(DBG_IGMP, "igmp_v2_leave_group");
break;
default:
- debug(DBG_IGMP, "IGMP msg type %02hhx\n", igmp_msg->common.type);
+ debug(DBG_IGMP, "IGMP msg type %02hhx", igmp_msg->common.type);
break;
}
@@ -389,12 +389,12 @@ igmp_read_cb(struct cfg *cfg, struct uring_task *task, int res)
{
struct igmp *igmp = container_of(task, struct igmp, task);
- debug(DBG_IGMP, "task %p, igmp %p, res %i\n", task, igmp, res);
+ debug(DBG_IGMP, "task %p, igmp %p, res %i", task, igmp, res);
assert_task_alive(DBG_IGMP, task);
if (res < 0) {
- error("res: %i\n", res);
+ error("res: %i", res);
return;
}
@@ -404,7 +404,7 @@ igmp_read_cb(struct cfg *cfg, struct uring_task *task, int res)
task->saddr.ll.sll_protocol == htons(ETH_P_IP))
igmp_parse(cfg, igmp);
else
- debug(DBG_IGMP, "invalid packet type received\n");
+ debug(DBG_IGMP, "invalid packet type received");
uring_tbuf_read(cfg, &igmp->task, igmp_read_cb);
}
@@ -414,7 +414,7 @@ igmp_free(struct uring_task *task)
{
struct igmp *igmp = container_of(task, struct igmp, task);
- debug(DBG_IGMP, "task %p, igmp %p\n", task, igmp);
+ debug(DBG_IGMP, "task %p, igmp %p", task, igmp);
xfree(igmp);
}
@@ -435,7 +435,7 @@ igmp_delete(struct cfg *cfg)
if (!igmp)
return;
- debug(DBG_IGMP, "closing fd %i\n", igmp->task.fd);
+ debug(DBG_IGMP, "closing fd %i", igmp->task.fd);
uring_task_destroy(cfg, &igmp->task);
cfg->igmp = NULL;
}
@@ -498,7 +498,7 @@ igmp_init(struct cfg *cfg)
int opt;
if (!cfg->do_igmp) {
- debug(DBG_IGMP, "igmp snooping disabled\n");
+ debug(DBG_IGMP, "igmp snooping disabled");
return;
}
@@ -513,17 +513,21 @@ igmp_init(struct cfg *cfg)
sfd = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_ALL));
if (sfd < 0) {
if (errno == EACCES || errno == EPERM)
- error("permission denied\n");
+ error("permission denied");
else
- error("%m\n");
- goto error_free;
+ error("%mn");
+ goto error;
}
- if (setsockopt(sfd, SOL_SOCKET, SO_ATTACH_FILTER, &fprog, sizeof(fprog)) < 0)
- die("setsockopt(SO_ATTACH_FILTER): %m");
+ if (setsockopt(sfd, SOL_SOCKET, SO_ATTACH_FILTER, &fprog, sizeof(fprog)) < 0) {
+ error("setsockopt(SO_ATTACH_FILTER): %m");
+ goto error;
+ }
- if (setsockopt(sfd, SOL_SOCKET, SO_LOCK_FILTER, &opt, sizeof(opt)) < 0)
- die("setsockopt(SO_LOCK_FILTER): %m");
+ if (setsockopt(sfd, SOL_SOCKET, SO_LOCK_FILTER, &opt, sizeof(opt)) < 0) {
+ error("setsockopt(SO_LOCK_FILTER): %m");
+ goto error;
+ }
if (cfg->igmp_iface) {
struct ifreq ifreq;
@@ -531,13 +535,17 @@ igmp_init(struct cfg *cfg)
r = snprintf(ifreq.ifr_name, sizeof(ifreq.ifr_name),
"%s", cfg->igmp_iface);
- if (r < 0 || r >= sizeof(ifreq.ifr_name))
- die("invalid interface name");
+ if (r < 0 || r >= sizeof(ifreq.ifr_name)) {
+ error("invalid interface name");
+ goto error;
+ }
- if (ioctl(sfd, SIOCGIFINDEX, &ifreq) < 0)
- perrordie("ioctl");
+ if (ioctl(sfd, SIOCGIFINDEX, &ifreq) < 0) {
+ error("ioctl: %m");
+ goto error;
+ }
- debug(DBG_IGMP, "using interface %s (%i)\n",
+ debug(DBG_IGMP, "using interface %s (%i)",
cfg->igmp_iface, ifreq.ifr_ifindex);
struct packet_mreq mreq = {
@@ -546,17 +554,19 @@ igmp_init(struct cfg *cfg)
};
if (setsockopt(sfd, SOL_PACKET, PACKET_ADD_MEMBERSHIP,
- &mreq, sizeof(mreq)) < 0)
- die("setsockopt(PACKET_ADD_MEMBERSHIP): %m");
+ &mreq, sizeof(mreq)) < 0) {
+ error("setsockopt(PACKET_ADD_MEMBERSHIP): %m");
+ goto error;
+ }
}
/* can't set .sll_protocol to htons(ETH_P_IP), see comment above */
if (bind(sfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
- error("bind: %m\n");
- goto error_fd;
+ error("bind: %m");
+ goto error;
}
- debug(DBG_IGMP, "init successful, using fd %i\n", sfd);
+ debug(DBG_IGMP, "init successful, using fd %i", sfd);
uring_task_init(&igmp->task, "igmp", uring_parent(cfg), igmp_free);
uring_task_set_fd(&igmp->task, sfd);
uring_task_set_buf(&igmp->task, &igmp->tbuf);
@@ -567,8 +577,7 @@ igmp_init(struct cfg *cfg)
return;
-error_fd:
+error:
close(sfd);
-error_free:
xfree(igmp);
}
diff --git a/main.c b/main.c
index 749d1e8..0bd5bb0 100644
--- a/main.c
+++ b/main.c
@@ -162,7 +162,7 @@ __die(const char *fmt, ...)
va_start(ap, fmt);
msg(DBG_ERROR, fmt, ap);
va_end(ap);
- sd_notifyf(0, "STATUS=Error, shutting down\n");
+ sd_notifyf(0, "STATUS=Error, shutting down");
exit(EXIT_FAILURE);
};
@@ -171,7 +171,7 @@ cfg_free(struct uring_task *task)
{
struct cfg *cfg = container_of(task, struct cfg, task);
- debug(DBG_SIG, "called\n");
+ debug(DBG_SIG, "called");
systemd_delete(cfg);
xfree(cfg->igmp_iface);
cfg->igmp_iface = NULL;
@@ -224,12 +224,12 @@ cfg_read(struct cfg *cfg)
if (errno == ENOENT && !cfg->cfg_path)
return;
else if (errno == ENOENT)
- die("main config file (%s) missing\n", path);
+ die("main config file (%s) missing", path);
else
- perrordie("fopen");
+ die("fopen(%s): %m", path);
}
- debug(DBG_CFG, "opened main config file (%s)\n", path);
+ debug(DBG_CFG, "opened main config file (%s)", path);
while (rd < sizeof(buf)) {
r = fread(pos, 1, sizeof(buf) - rd - 1, cfgfile);
@@ -240,17 +240,17 @@ cfg_read(struct cfg *cfg)
}
if (rd == 0)
- die("main config file (%s) invalid\n", path);
+ die("main config file (%s) zero size", path);
if (rd >= sizeof(buf))
- die("main config file (%s) too large\n", path);
+ die("main config file (%s) too large", path);
fclose(cfgfile);
*pos = '\0';
pos = buf;
if (!config_parse_header(cfg, path, "mcproxy", &pos))
- die("main config file (%s) invalid\n", path);
+ die("main config file (%s) invalid", path);
while (true) {
int key;
@@ -262,9 +262,9 @@ cfg_read(struct cfg *cfg)
break;
if (key == MCFG_KEY_INVALID)
- die("main config file (%s) invalid\n", path);
+ die("main config file (%s) invalid", path);
- debug(DBG_CFG, "main cfg: key %s\n", keyname);
+ debug(DBG_CFG, "main cfg: key %s", keyname);
switch (key) {
@@ -275,13 +275,13 @@ cfg_read(struct cfg *cfg)
case MCFG_KEY_IGMP_IFACE:
cfg->igmp_iface = xstrdup(value.str);
if (!cfg->igmp_iface)
- perrordie("xstrdup");
+ die("xstrdup: %m");
break;
case MCFG_KEY_INVALID:
default:
- die("main config file (%s) invalid\n", path);
+ die("main config file (%s) invalid", path);
}
}
}
@@ -339,7 +339,7 @@ __attribute__((noreturn)) static void
usage(int argc, char **argv, bool invalid)
{
if (invalid)
- info("Invalid option(s)\n");
+ info("Invalid option(s)");
info("Usage: %s [OPTIONS]\n"
"\n"
@@ -367,7 +367,7 @@ cfg_init(int argc, char **argv)
cfg = zmalloc(sizeof(*cfg));
if (!cfg)
- perrordie("malloc");
+ die("malloc: %m");
cfg->uid = geteuid();
cfg->gid = getegid();
@@ -423,7 +423,7 @@ cfg_init(int argc, char **argv)
die("failed to find user %s (%m)", optarg);
}
- debug(DBG_CFG, "asked to execute with uid %ji gid %ji\n",
+ debug(DBG_CFG, "asked to execute with uid %ji gid %ji",
(intmax_t)pwd->pw_uid,
(intmax_t)pwd->pw_gid);
cfg->uid = pwd->pw_uid;
@@ -436,10 +436,10 @@ cfg_init(int argc, char **argv)
debug_mask = ~0;
break;
} else if (!strcasecmp(optarg, "list")) {
- error("Debug categories:\n");
- error(" * all\n");
+ error("Debug categories:");
+ error(" * all");
for (i = 0; debug_category_str[i].name; i++)
- error(" * %s\n", debug_category_str[i].name);
+ error(" * %s", debug_category_str[i].name);
exit(EXIT_FAILURE);
}
@@ -449,7 +449,7 @@ cfg_init(int argc, char **argv)
}
if (!debug_category_str[i].name)
- die("invalid debug category");
+ usage(argc, argv, true);
debug_mask |= debug_category_str[i].val;
break;
@@ -515,13 +515,13 @@ cfg_apply(struct cfg *cfg)
* accessing a directory we should have permissions to.
*/
if (chdir(cfg->homedir))
- perrordie("chdir(%s)", cfg->homedir);
+ die("chdir(%s): %m", cfg->homedir);
if (debug_enabled(DBG_VERBOSE)) {
char *wd;
wd = get_current_dir_name();
- verbose("Homedir: %s\n", wd ? wd : "<unknown>");
+ verbose("Homedir: %s", wd ? wd : "<unknown>");
free(wd);
}
}
@@ -538,7 +538,7 @@ signalfd_free(struct uring_task *task)
{
struct signalfd_ev *sev = container_of(task, struct signalfd_ev, task);
- debug(DBG_SIG, "called\n");
+ debug(DBG_SIG, "called");
sev->cfg->sev = NULL;
xfree(sev);
}
@@ -551,9 +551,9 @@ dump_tree(struct cfg *cfg)
if (!debug_enabled(DBG_REF))
return;
- debug(DBG_REF, "\n\n\n\n");
- debug(DBG_REF, "Dumping Tree\n");
- debug(DBG_REF, "============\n");
+ debug(DBG_REF, "\n\n");
+ debug(DBG_REF, "Dumping Tree");
+ debug(DBG_REF, "============");
uring_task_refdump(&cfg->task);
uring_refdump(cfg->uev);
if (cfg->sev)
@@ -564,8 +564,8 @@ dump_tree(struct cfg *cfg)
cfgdir_refdump(cfg->iev);
list_for_each_entry(server, &cfg->servers, list)
server_refdump(server);
- debug(DBG_REF, "============\n");
- debug(DBG_REF, "\n\n\n\n");
+ debug(DBG_REF, "============");
+ debug(DBG_REF, "\n\n");
}
static struct dns_async *hack_dns = NULL;
@@ -582,11 +582,11 @@ signalfd_read(struct cfg *cfg, struct uring_task *task, int res)
die("error in signalfd (%i)", res);
if (sev->buf < 1000) {
- verbose("got a signal to quit\n");
+ verbose("got a signal to quit");
sd_notifyf(0, "STOPPING=1\nSTATUS=Received signal, exiting");
exit(EXIT_SUCCESS);
} else if (sev->buf < 10000) {
- verbose("got a signal to dump tree\n");
+ verbose("got a signal to dump tree");
sd_notifyf(0, "STOPPING=1\nSTATUS=Received signal, exiting");
dump_tree(cfg);
uring_task_put(cfg, &sev->task);
@@ -598,12 +598,12 @@ signalfd_read(struct cfg *cfg, struct uring_task *task, int res)
uring_delete(cfg);
return;
} else {
- debug(DBG_DNS, "DNS lookup complete, dns: %p, dns->cb: %p\n",
+ debug(DBG_DNS, "DNS lookup complete, dns: %p, dns->cb: %p",
hack_dns,
hack_dns ? hack_dns->cb : NULL);
if (!hack_dns || !hack_dns->cb) {
- error("DNS callback not set\n");
+ error("DNS callback not set");
goto out;
}
@@ -623,29 +623,29 @@ hack_handler(int signum, siginfo_t *info, void *ucontext)
switch (signum) {
case SIGUSR1:
- debug(DBG_SIG, "Got a SIGUSR1\n");
+ debug(DBG_SIG, "Got a SIGUSR1");
if (info->si_code != SI_ASYNCNL || info->si_signo != SIGUSR1 || !info->si_ptr) {
- debug(DBG_SIG, "unexpected values in siginfo\n");
+ debug(DBG_SIG, "unexpected values in siginfo");
return;
}
- debug(DBG_SIG, "SIGUSR1 struct dns_async: %p\n", info->si_ptr);
+ debug(DBG_SIG, "SIGUSR1 struct dns_async: %p", info->si_ptr);
hack_dns = info->si_ptr;
val = 10000;
break;
case SIGINT:
- debug(DBG_SIG, "Got a SIGINT\n");
+ debug(DBG_SIG, "Got a SIGINT");
val = 1000;
break;
case SIGHUP:
- debug(DBG_SIG, "Got a SIGHUP\n");
+ debug(DBG_SIG, "Got a SIGHUP");
val = 1000;
break;
case SIGTERM:
- debug(DBG_SIG, "Got a SIGTERM\n");
+ debug(DBG_SIG, "Got a SIGTERM");
val = 1;
break;
default:
- error("Got an unknown sig (%i)\n", signum);
+ error("Got an unknown sig (%i)", signum);
val = 1;
break;
}
@@ -662,7 +662,7 @@ signalfd_init(struct cfg *cfg)
sev = zmalloc(sizeof(*sev));
if (!sev)
- perrordie("malloc");
+ die("malloc: %m");
/*
sigfillset(&mask);
@@ -690,9 +690,9 @@ signalfd_init(struct cfg *cfg)
sfd = eventfd(0, EFD_CLOEXEC);
if (sfd < 0)
- perrordie("eventfd");
+ die("eventfd: %m");
- debug(DBG_SIG, "using fd %i\n", sfd);
+ debug(DBG_SIG, "using fd %i", sfd);
uring_task_init(&sev->task, "sev", uring_parent(cfg), signalfd_free);
uring_task_set_fd(&sev->task, sfd);
cfg->sev = sev;
@@ -753,12 +753,12 @@ main(int argc, char **argv)
server_count,
(unsigned long)getpid());
- info("mcproxy started, %u server configurations loaded\n",
+ info("mcproxy started, %u server configurations loaded",
server_count);
uring_event_loop(cfg);
- verbose("Exiting\n");
+ verbose("Exiting");
xfree(cfg);
diff --git a/main.h b/main.h
index 7d14118..9d50bc8 100644
--- a/main.h
+++ b/main.h
@@ -42,11 +42,12 @@ void __debug(enum debug_lvl lvl, const char *fmt, ...) __attribute__((format(pri
#define __ifdebug(lvl, fmt, ...) \
do { \
if (debug_enabled((lvl))) \
- __debug((lvl), fmt __VA_OPT__(,) __VA_ARGS__); \
+ __debug((lvl), fmt "\n"__VA_OPT__(,) __VA_ARGS__); \
} while (0)
-#define debug(lvl, fmt, ...) __ifdebug((lvl), "%s:%i: " fmt, __func__, \
- __LINE__ __VA_OPT__(,) __VA_ARGS__)
+#define debug(lvl, fmt, ...) __ifdebug((lvl), "%s:%s:%i: " fmt, \
+ __func__, __FILE__, __LINE__ \
+ __VA_OPT__(,) __VA_ARGS__)
#define verbose(fmt, ...) __ifdebug(DBG_VERBOSE, fmt, __VA_ARGS__)
#define info(fmt, ...) __ifdebug(DBG_INFO, fmt, __VA_ARGS__)
#define error(fmt, ...) __ifdebug(DBG_ERROR, "%s: " fmt, \
@@ -56,8 +57,6 @@ void __die(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
#define die(fmt, ...) __die("%s:%i: " fmt "\n", __func__, \
__LINE__ __VA_OPT__(,) __VA_ARGS__)
-#define perrordie(fmt, ...) __die("%s:%i: " fmt ": %m\n", __func__, \
- __LINE__ __VA_OPT__(,) __VA_ARGS__)
struct uring_task;
diff --git a/proxy.c b/proxy.c
index 7fb6c34..6ced85b 100644
--- a/proxy.c
+++ b/proxy.c
@@ -67,7 +67,7 @@ proxy_free(struct uring_task *task)
char stc[100];
char duration[100];
- debug(DBG_PROXY, "server: %s, src: %s, dst: %s\n",
+ debug(DBG_PROXY, "server: %s, src: %s, dst: %s",
proxy->scfg->name,
proxy->client_conn.remote.addrstr,
proxy->server_conn.remote.addrstr);
@@ -78,7 +78,7 @@ proxy_free(struct uring_task *task)
format_bytes(stc, sizeof(stc), proxy->server_bytes);
info("%s: proxy connection %s -> %s closed "
- "(CtS: %s, StC: %s), duration %s\n",
+ "(CtS: %s, StC: %s), duration %s",
proxy->scfg->name,
proxy->client_conn.remote.addrstr,
proxy->server_conn.remote.addrstr,
@@ -94,7 +94,7 @@ proxy_client_free(struct uring_task *task)
{
struct server_proxy *proxy = container_of(task, struct server_proxy, clienttask);
- debug(DBG_PROXY, "%s: client connection closed\n", proxy->scfg->name);
+ debug(DBG_PROXY, "%s: client connection closed", proxy->scfg->name);
}
static void
@@ -102,13 +102,13 @@ proxy_server_free(struct uring_task *task)
{
struct server_proxy *proxy = container_of(task, struct server_proxy, servertask);
- debug(DBG_PROXY, "%s: server connection closed\n", proxy->scfg->name);
+ debug(DBG_PROXY, "%s: server connection closed", proxy->scfg->name);
}
void
proxy_delete(struct cfg *cfg, struct server_proxy *proxy)
{
- debug(DBG_PROXY, "%s: shutting down proxy %p\n", proxy->scfg->name, proxy);
+ debug(DBG_PROXY, "%s: shutting down proxy %p", proxy->scfg->name, proxy);
uring_task_destroy(cfg, &proxy->servertask);
uring_task_destroy(cfg, &proxy->clienttask);
@@ -125,7 +125,7 @@ proxy_client_data_out(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_PROXY, task);
if (res <= 0) {
- debug(DBG_PROXY, "%s: result was %i\n", proxy->scfg->name, res);
+ debug(DBG_PROXY, "%s: result was %i", proxy->scfg->name, res);
uring_task_close_fd(cfg, task);
proxy_delete(cfg, proxy);
return;
@@ -144,7 +144,7 @@ proxy_client_data_in(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_PROXY, task);
if (res <= 0) {
- debug(DBG_PROXY, "%s: result was %i\n", proxy->scfg->name, res);
+ debug(DBG_PROXY, "%s: result was %i", proxy->scfg->name, res);
uring_task_close_fd(cfg, task);
proxy_delete(cfg, proxy);
return;
@@ -164,7 +164,7 @@ proxy_server_data_out(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_PROXY, task);
if (res <= 0) {
- debug(DBG_PROXY, "%s: result was %i\n", proxy->scfg->name, res);
+ debug(DBG_PROXY, "%s: result was %i", proxy->scfg->name, res);
uring_task_close_fd(cfg, task);
proxy_delete(cfg, proxy);
return;
@@ -183,7 +183,7 @@ proxy_server_data_in(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_PROXY, task);
if (res <= 0) {
- debug(DBG_PROXY, "%s: result was %i\n", proxy->scfg->name, res);
+ debug(DBG_PROXY, "%s: result was %i", proxy->scfg->name, res);
uring_task_close_fd(cfg, task);
proxy_delete(cfg, proxy);
return;
@@ -202,14 +202,14 @@ proxy_connected_cb(struct cfg *cfg, struct connection *conn, bool connected)
assert_task_alive(DBG_PROXY, &proxy->servertask);
if (!connected) {
- error("%s: proxy connection to remote server failed\n",
+ error("%s: proxy connection to remote server failed",
proxy->scfg->name);
proxy_delete(cfg, proxy);
return;
}
proxy->sfd = proxy->servertask.fd;
- verbose("%s: proxy connection %s -> %s opened\n",
+ verbose("%s: proxy connection %s -> %s opened",
proxy->scfg->name,
proxy->client_conn.remote.addrstr,
proxy->server_conn.remote.addrstr);
diff --git a/rcon.c b/rcon.c
index e7c37ce..1a57b89 100644
--- a/rcon.c
+++ b/rcon.c
@@ -27,7 +27,7 @@ rcon_free(struct uring_task *task)
{
struct rcon *rcon = container_of(task, struct rcon, task);
- debug(DBG_RCON, "task %p, idle %p\n", task, rcon);
+ debug(DBG_RCON, "task %p, idle %p", task, rcon);
rcon->server->rcon = NULL;
xfree(rcon);
}
@@ -49,7 +49,7 @@ rcon_delete(struct cfg *cfg, struct server *server)
if (!rcon)
return;
- debug(DBG_RCON, "closing fd %i\n", rcon->task.fd);
+ debug(DBG_RCON, "closing fd %i", rcon->task.fd);
uring_task_destroy(cfg, &rcon->task);
server->rcon = NULL;
}
@@ -141,7 +141,7 @@ create_packet(struct cfg *cfg, struct rcon *rcon, int32_t reqid,
write_int(&pos, NULL, rcon->tbuf.len - 4);
debug(DBG_RCON, "created packet (reqid: %" PRIi32 ", type %" PRIi32
- ", len %zu, payload: %s)\n",
+ ", len %zu, payload: %s)",
reqid, type, rcon->tbuf.len, msg);
}
@@ -158,7 +158,7 @@ packet_complete(struct cfg *cfg, struct uring_task *task, int res)
return 0;
plen = read_int(&pos, &len);
- debug(DBG_RCON, "reply size: %zu bytes, packet size %" PRIi32 "\n",
+ debug(DBG_RCON, "reply size: %zu bytes, packet size %" PRIi32,
task->tbuf->len, plen + 4);
if (task->tbuf->len < plen + 4)
@@ -181,7 +181,7 @@ rcon_read_packet(struct cfg *cfg, struct rcon *rcon, int32_t *id,
*rmsg = NULL;
if (plen < 10) {
- error("invalid packet length: %" PRIi32 "\n", plen);
+ error("invalid packet length: %" PRIi32, plen);
return false;
}
@@ -192,17 +192,17 @@ rcon_read_packet(struct cfg *cfg, struct rcon *rcon, int32_t *id,
}
if (len < 2) {
- error("short message\n");
+ error("short message");
return false;
}
if (pos[0] != '\0' || pos[1] != '\0') {
- error("invalid trailer\n");
+ error("invalid trailer");
return false;
}
debug(DBG_RCON, "response - len: %" PRIi32 ", id: %" PRIi32
- ", type: %" PRIi32 ", msg: %s\n",
+ ", type: %" PRIi32 ", msg: %s",
plen, *id, *type, *rmsg);
return true;
@@ -219,22 +219,22 @@ rcon_stop_reply(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_RCON, task);
if (res < 0) {
- debug(DBG_RCON, "res: %i\n", res);
+ debug(DBG_RCON, "res: %i", res);
goto out;
}
- debug(DBG_RCON, "packet complete\n");
+ debug(DBG_RCON, "packet complete");
rcon_read_packet(cfg, rcon, &id, &type, &msg);
if (id != 2) {
- error("rcon stop cmd failed - unexpected reply id (%" PRIi32 ")\n", id);
+ error("rcon stop failed - reply id (%" PRIi32 ")", id);
goto out;
} else if (type != RCON_PACKET_RESPONSE) {
- error("rcon stop cmd failed - unexpected reply type (%" PRIi32 ")\n", type);
+ error("rcon stop failed - reply type (%" PRIi32 ")", type);
goto out;
}
- verbose("rcon stop cmd successful (%s)\n", msg);
+ verbose("rcon stop successful (%s)", msg);
out:
uring_task_put(cfg, &rcon->task);
@@ -248,12 +248,12 @@ rcon_stop_sent(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_RCON, task);
if (res < 0) {
- debug(DBG_RCON, "res: %i\n", res);
+ debug(DBG_RCON, "res: %i", res);
uring_task_put(cfg, &rcon->task);
return;
}
- debug(DBG_RCON, "stop cmd sent\n");
+ debug(DBG_RCON, "stop cmd sent");
uring_tbuf_read_until(cfg, &rcon->task, packet_complete, rcon_stop_reply);
}
@@ -268,25 +268,25 @@ rcon_login_reply(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_RCON, task);
if (res < 0) {
- debug(DBG_RCON, "res: %i\n", res);
+ debug(DBG_RCON, "res: %i", res);
goto error;
}
- debug(DBG_RCON, "packet complete\n");
+ debug(DBG_RCON, "packet complete");
rcon_read_packet(cfg, rcon, &id, &type, &msg);
if (id != 1) {
- error("rcon login failed - unexpected reply id (%" PRIi32 ")\n", id);
+ error("rcon login failed - unexpected reply id (%" PRIi32 ")", id);
goto error;
} else if (type == RCON_PACKET_LOGIN_FAIL) {
- error("rcon login failed - incorrect password\n");
+ error("rcon login failed - incorrect password");
goto error;
} else if (type != RCON_PACKET_LOGIN_OK) {
- error("rcon login failed - unexpected reply type (%" PRIi32 ")\n", type);
+ error("rcon login failed - unexpected reply type (%" PRIi32 ")", type);
goto error;
}
- debug(DBG_RCON, "rcon login successful\n");
+ debug(DBG_RCON, "rcon login successful");
create_packet(cfg, rcon, 2, RCON_PACKET_COMMAND, "stop");
uring_tbuf_write(cfg, &rcon->task, rcon_stop_sent);
return;
@@ -303,12 +303,12 @@ rcon_login_sent(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive(DBG_RCON, task);
if (res < 0) {
- debug(DBG_RCON, "res: %i\n", res);
+ debug(DBG_RCON, "res: %i", res);
uring_task_put(cfg, &rcon->task);
return;
}
- debug(DBG_RCON, "login sent\n");
+ debug(DBG_RCON, "login sent");
uring_tbuf_read_until(cfg, &rcon->task, packet_complete, rcon_login_reply);
}
@@ -320,7 +320,7 @@ rcon_connected_cb(struct cfg *cfg, struct connection *conn, bool connected)
assert_task_alive(DBG_RCON, &rcon->task);
if (!connected) {
- error("rcon connection to remote server (%s) failed\n",
+ error("rcon connection to remote server (%s) failed",
rcon->server->name);
uring_task_put(cfg, &rcon->task);
return;
@@ -343,7 +343,7 @@ rcon_init(struct cfg *cfg, struct server *server)
rcon = zmalloc(sizeof(*rcon));
if (!rcon)
- perrordie("malloc");
+ die("malloc: %m");
uring_task_init(&rcon->task, "rcon", &server->task, rcon_free);
uring_task_set_buf(&rcon->task, &rcon->tbuf);
diff --git a/server.c b/server.c
index edb0551..ea2d370 100644
--- a/server.c
+++ b/server.c
@@ -66,7 +66,7 @@ server_free(struct uring_task *task)
{
struct server *scfg = container_of(task, struct server, task);
- debug(DBG_SRV, "freeing server %s (%p)\n", scfg->name, scfg);
+ debug(DBG_SRV, "freeing server %s (%p)", scfg->name, scfg);
list_del(&scfg->list);
xfree(scfg->pretty_name);
xfree(scfg->start_exec);
@@ -88,7 +88,7 @@ server_delete(struct cfg *cfg, struct server *scfg)
struct saddr *tmp;
struct dns_async *dns, *dtmp;
- verbose("Removing server %s\n", scfg->name);
+ verbose("Removing server %s", scfg->name);
idle_delete(cfg, scfg);
rcon_delete(cfg, scfg);
@@ -140,40 +140,40 @@ server_dump(struct server *scfg)
struct saddr *remote;
struct saddr *rcon;
- verbose("Server %s:\n", scfg->name);
+ verbose("Server %s:", scfg->name);
switch (scfg->type) {
case SERVER_TYPE_ANNOUNCE:
- verbose(" * Type: announce\n");
+ verbose(" * Type: announce");
break;
case SERVER_TYPE_PROXY:
- verbose(" * Type: proxy\n");
+ verbose(" * Type: proxy");
break;
default:
- verbose(" * Type: unknown\n");
+ verbose(" * Type: unknown");
break;
}
- verbose(" * Name: %s\n", scfg->pretty_name ? scfg->pretty_name : "<undefined>");
- verbose(" * Announce port: %" PRIu16 "\n", scfg->announce_port);
+ verbose(" * Name: %s", scfg->pretty_name ? scfg->pretty_name : "<undefined>");
+ verbose(" * Announce port: %" PRIu16, scfg->announce_port);
if (!list_empty(&scfg->locals)) {
- verbose(" * Local:\n");
+ verbose(" * Local:");
list_for_each_entry(local, &scfg->locals, list)
- verbose(" * %s\n", local->local.addrstr);
+ verbose(" * %s", local->local.addrstr);
}
if (!list_empty(&scfg->remotes)) {
- verbose(" * Remote:\n");
+ verbose(" * Remote:");
list_for_each_entry(remote, &scfg->remotes, list)
- verbose(" * %s\n", remote->addrstr);
+ verbose(" * %s", remote->addrstr);
}
if (!list_empty(&scfg->rcons)) {
- verbose(" * RCon:\n");
+ verbose(" * RCon:");
list_for_each_entry(rcon, &scfg->rcons, list)
- verbose(" * %s\n", rcon->addrstr);
+ verbose(" * %s", rcon->addrstr);
}
- verbose("\n");
+ verbose("");
}
static void
@@ -181,7 +181,7 @@ server_local_free(struct uring_task *task)
{
struct server_local *local = container_of(task, struct server_local, task);
- debug(DBG_SRV, "task %p, local %p\n", task, local);
+ debug(DBG_SRV, "task %p, local %p", task, local);
list_del(&local->list);
xfree(local);
}
@@ -193,23 +193,23 @@ server_local_accept(struct cfg *cfg, struct uring_task *task, int res)
struct server *scfg = container_of(task->parent, struct server, task);
struct server_proxy *proxy;
- debug(DBG_SRV, "task %p, res %i, scfg %s\n", task, res, scfg->name);
+ debug(DBG_SRV, "task %p, res %i, scfg %s", task, res, scfg->name);
assert_task_alive(DBG_SRV, task);
if (res < 0) {
- error("result was %i\n", res);
+ error("result was %i", res);
goto out;
}
saddr_set_addrstr(&local->client);
- verbose("%s: incoming proxy connection: %s -> %s\n",
+ verbose("%s: incoming proxy connection: %s -> %s",
scfg->name, local->client.addrstr, local->local.addrstr);
if (list_empty(&scfg->remotes)) {
/* This shouldn't be possible, checked before opening local */
- error("scfg->remotes empty!\n");
+ error("scfg->remotes empty!");
uring_close(cfg, &local->task, res);
goto out;
}
@@ -281,7 +281,7 @@ server_exec_free(struct uring_task *task)
{
//struct server *scfg = container_of(task, struct server, exec_task);
- debug(DBG_SRV, "called\n");
+ debug(DBG_SRV, "called");
}
#ifndef P_PIDFD
@@ -300,7 +300,7 @@ server_exec_done(struct cfg *cfg, struct uring_task *task, int res)
assert_task_alive_or(DBG_SRV, task, goto out);
if (!(res & POLLIN)) {
- error("unexpected result: %i\n", res);
+ error("unexpected result: %i", res);
goto out;
}
@@ -311,9 +311,9 @@ server_exec_done(struct cfg *cfg, struct uring_task *task, int res)
}
if (info.si_status == 0)
- debug(DBG_SRV, "command successfully executed\n");
+ debug(DBG_SRV, "command successfully executed");
else
- error("command failed: %i\n", info.si_status);
+ error("command failed: %i", info.si_status);
out:
uring_task_close_fd(cfg, &scfg->exec_task);
@@ -363,7 +363,7 @@ server_check_running(struct cfg *cfg, struct server *scfg)
{
/* FIXME: other methods, rcon? */
if (scfg->systemd_service) {
- verbose("%s: checking if systemd service is running\n", scfg->name);
+ verbose("%s: checking if systemd service is running", scfg->name);
if (systemd_service_running(cfg, scfg)) {
scfg->state = SERVER_STATE_RUNNING;
return true;
@@ -388,11 +388,11 @@ server_start(struct cfg *cfg, struct server *scfg)
switch (scfg->start_method) {
case SERVER_START_METHOD_EXEC:
- verbose("Starting server %s via external cmd\n", scfg->name);
+ verbose("Starting server %s via external cmd", scfg->name);
return server_exec(cfg, scfg, scfg->start_exec);
case SERVER_START_METHOD_SYSTEMD:
- verbose("Starting server %s via systemd (%s)\n",
+ verbose("Starting server %s via systemd (%s)",
scfg->name, scfg->systemd_service);
if (systemd_service_start(cfg, scfg)) {
@@ -421,11 +421,11 @@ server_stop(struct cfg *cfg, struct server *scfg)
switch (scfg->stop_method) {
case SERVER_STOP_METHOD_EXEC:
- verbose("Stopping server %s via external cmd\n", scfg->name);
+ verbose("Stopping server %s via external cmd", scfg->name);
return server_exec(cfg, scfg, scfg->stop_exec);
case SERVER_STOP_METHOD_SYSTEMD:
- verbose("Stopping server %s via systemd (%s)\n",
+ verbose("Stopping server %s via systemd (%s)",
scfg->name, scfg->systemd_service);
if (systemd_service_stop(cfg, scfg)) {
scfg->state = SERVER_STATE_STOPPED;
@@ -434,7 +434,7 @@ server_stop(struct cfg *cfg, struct server *scfg)
return server_check_running(cfg, scfg);
case SERVER_STOP_METHOD_RCON:
- verbose("Stopping server %s via rcon\n", scfg->name);
+ verbose("Stopping server %s via rcon", scfg->name);
rcon_init(cfg, scfg);
return true;
@@ -453,7 +453,7 @@ server_commit(struct cfg *cfg, struct server *scfg)
uint16_t port;
if (!scfg || !scfg->name) {
- error("called with invalid parameters\n");
+ error("called with invalid parameters");
return false;
}
@@ -461,30 +461,30 @@ server_commit(struct cfg *cfg, struct server *scfg)
return false;
if (scfg->state != SERVER_STATE_INIT) {
- error("called in wrong state\n");
+ error("called in wrong state");
return false;
}
if (!list_empty(&scfg->proxys)) {
- error("%s: proxys not empty?\n", scfg->name);
+ error("%s: proxys not empty?", scfg->name);
return false;
}
if (!list_empty(&scfg->dnslookups)) {
- debug(DBG_SRV, "called with pending DNS requests\n");
+ debug(DBG_SRV, "called with pending DNS requests");
return true;
}
if (scfg->stop_method == SERVER_STOP_METHOD_RCON &&
list_empty(&scfg->rcons)) {
- error("%s: rcon stop method missing rcon address\n",
+ error("%s: rcon stop method missing rcon address",
scfg->name);
return false;
}
if (scfg->stop_method == SERVER_STOP_METHOD_RCON &&
!scfg->rcon_password) {
- error("%s: rcon stop method missing rcon password\n",
+ error("%s: rcon stop method missing rcon password",
scfg->name);
return false;
}
@@ -492,7 +492,7 @@ server_commit(struct cfg *cfg, struct server *scfg)
if ((scfg->start_method == SERVER_START_METHOD_SYSTEMD ||
scfg->stop_method == SERVER_STOP_METHOD_SYSTEMD) &&
!scfg->systemd_service) {
- error("%s: systemd start/stop method missing systemd service\n",
+ error("%s: systemd start/stop method missing systemd service",
scfg->name);
return false;
}
@@ -501,36 +501,37 @@ server_commit(struct cfg *cfg, struct server *scfg)
scfg->systemd_obj = systemd_service_object_path(cfg,
scfg->systemd_service);
if (!scfg->systemd_obj) {
- error("%s: failed to create systemd object path (%s)\n", scfg->name, scfg->systemd_service);
+ error("%s: failed to create systemd object path (%s)",
+ scfg->name, scfg->systemd_service);
return false;
}
}
if (scfg->idle_timeout > 0 &&
scfg->stop_method == SERVER_STOP_METHOD_UNDEFINED) {
- error("%s: idle_timeout set but missing stop method\n", scfg->name);
+ error("%s: idle_timeout set but missing stop method", scfg->name);
return false;
}
switch (scfg->type) {
case SERVER_TYPE_ANNOUNCE:
if (scfg->announce_port < 1) {
- error("%s: missing announce port\n", scfg->name);
+ error("%s: missing announce port", scfg->name);
return false;
}
if (scfg->start_method != SERVER_START_METHOD_UNDEFINED) {
- error("%s: can't set start_method for announce server\n", scfg->name);
+ error("%s: can't set start_method for announce server", scfg->name);
return false;
}
if (!list_empty(&scfg->locals)) {
- error("%s: can't set local addresses for announce server\n", scfg->name);
+ error("%s: can't set local addresses for announce server", scfg->name);
return false;
}
if (!list_empty(&scfg->remotes)) {
- error("%s: can't set remote addresses for announce server\n", scfg->name);
+ error("%s: can't set remote addresses for announce server", scfg->name);
return false;
}
@@ -538,17 +539,17 @@ server_commit(struct cfg *cfg, struct server *scfg)
case SERVER_TYPE_PROXY:
if (scfg->announce_port >= 1) {
- error("%s: can't set announce port for proxy server\n", scfg->name);
+ error("%s: can't set announce port for proxy server", scfg->name);
return false;
}
if (list_empty(&scfg->locals)) {
- error("%s: missing local addresses for proxy server\n", scfg->name);
+ error("%s: missing local addresses for proxy server", scfg->name);
return false;
}
if (list_empty(&scfg->remotes)) {
- error("%s: missing remote addresses for proxy server\n", scfg->name);
+ error("%s: missing remote addresses for proxy server", scfg->name);
return false;
}
@@ -556,7 +557,7 @@ server_commit(struct cfg *cfg, struct server *scfg)
port = saddr_port(&local->local);
if (port == 0) {
- error("%s: invalid local port\n", scfg->name);
+ error("%s: invalid local port", scfg->name);
return false;
}
@@ -564,20 +565,20 @@ server_commit(struct cfg *cfg, struct server *scfg)
scfg->announce_port = port;
if (scfg->announce_port != port) {
- error("%s: multiple local ports\n", scfg->name);
+ error("%s: multiple local ports", scfg->name);
return false;
}
}
if (scfg->announce_port < 1) {
- error("%s: can't determine which port to announce\n", scfg->name);
+ error("%s: can't determine which port to announce", scfg->name);
return false;
}
break;
default:
- error("%s: can't determine server type\n", scfg->name);
+ error("%s: can't determine server type", scfg->name);
return false;
}
@@ -586,13 +587,13 @@ server_commit(struct cfg *cfg, struct server *scfg)
suffix = strrchr(scfg->name, '.');
if (!suffix || suffix == scfg->name) {
- error("%s: invalid server name\n", scfg->name);
+ error("invalid server name: %s", scfg->name);
return false;
}
scfg->pretty_name = xstrndup(scfg->name, suffix - scfg->name);
if (!scfg->pretty_name) {
- error("%s: failed to create display name\n", scfg->name);
+ error("failed to create display name: %s", scfg->name);
return false;
}
}
@@ -609,7 +610,7 @@ server_commit(struct cfg *cfg, struct server *scfg)
server_check_running(cfg, scfg);
- debug(DBG_SRV, "success\n");
+ debug(DBG_SRV, "success");
return true;
}
@@ -622,7 +623,7 @@ server_add_remote(struct cfg *cfg, struct server *scfg, struct saddr *remote)
if (scfg->task.dead)
return false;
- debug(DBG_SRV, "adding remote: %s\n", remote->addrstr);
+ debug(DBG_SRV, "adding remote: %s", remote->addrstr);
list_add(&remote->list, &scfg->remotes);
return true;
}
@@ -633,7 +634,7 @@ server_add_local(struct cfg *cfg, struct server *scfg, struct saddr *saddr)
struct server_local *local;
if (!scfg || !saddr) {
- error("missing arguments\n");
+ error("missing arguments");
return false;
}
@@ -649,7 +650,7 @@ server_add_local(struct cfg *cfg, struct server *scfg, struct saddr *saddr)
local->local = *saddr;
uring_task_init(&local->task, "local", &scfg->task, server_local_free);
- debug(DBG_SRV, "adding local: %s\n", saddr->addrstr);
+ debug(DBG_SRV, "adding local: %s", saddr->addrstr);
list_add(&local->list, &scfg->locals);
xfree(saddr);
return true;
@@ -664,7 +665,7 @@ server_add_rcon(struct cfg *cfg, struct server *scfg, struct saddr *rcon)
if (scfg->task.dead)
return false;
- debug(DBG_SRV, "adding rcon: %s\n", rcon->addrstr);
+ debug(DBG_SRV, "adding rcon: %s", rcon->addrstr);
list_add(&rcon->list, &scfg->rcons);
return true;
}
@@ -793,11 +794,11 @@ server_new(struct cfg *cfg, const char *name)
list_for_each_entry(scfg, &cfg->servers, list) {
if (strcmp(name, scfg->name))
continue;
- error("attempt to add duplicate server: %s\n", name);
+ error("attempt to add duplicate server: %s", name);
return scfg;
}
- verbose("Adding server %s\n", name);
+ verbose("Adding server %s", name);
scfg = zmalloc(sizeof(*scfg));
if (!scfg) {
error("malloc");
diff --git a/stest.c b/stest.c
deleted file mode 100644
index 94b5264..0000000
--- a/stest.c
+++ /dev/null
@@ -1,102 +0,0 @@
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <netinet/ip.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdbool.h>
-
-#define PIPE_RD 0
-#define PIPE_WR 1
-
-int
-main(int argc, char **argv) {
- int sfd;
- struct sockaddr_in addr;
- socklen_t addrsz = sizeof(addr);
- int pfd[2];
- int r;
- int cfd;
- int zfd;
- size_t total = 0;
-
- if (argc != 3) {
- fprintf(stderr, "Usage: %s <addr> <port>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
-
- sfd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (sfd < 0) {
- perror("socket");
- exit(EXIT_FAILURE);
- }
-
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(atoi(argv[2]));
- addr.sin_addr.s_addr = inet_addr(argv[1]);
-
- int enable = 1;
- if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) < 0) {
- perror("setsockopt");
- exit(EXIT_FAILURE);
- }
-
- r = bind(sfd, (struct sockaddr *)&addr, sizeof(addr));
- if (r < 0) {
- perror("bind");
- exit(EXIT_FAILURE);
- }
-
- r = listen(sfd, 100);
- if (r < 0) {
- perror("listen");
- exit(EXIT_FAILURE);
- }
-
- cfd = accept4(sfd, (struct sockaddr *)&addr, &addrsz, SOCK_CLOEXEC);
- if (cfd < 0) {
- perror("accept");
- exit(EXIT_FAILURE);
- }
-
- zfd = open("/dev/null", O_WRONLY | O_CLOEXEC);
- if (zfd < 0) {
- perror("open");
- exit(EXIT_FAILURE);
- }
-
- if (pipe2(pfd, O_CLOEXEC) < 0) {
- perror("pipe2");
- exit(EXIT_FAILURE);
- }
-
- while (true) {
- ssize_t r, w;
-
- r = splice(cfd, NULL, pfd[PIPE_WR], NULL, 64 * 1024, SPLICE_F_MOVE);
- if (r < 0)
- perror("splice");
- //fprintf(stderr, "Read %zi bytes from socket\n", r);
- if (r == 0)
- break;
- w = splice(pfd[PIPE_RD], NULL, zfd, NULL, r, SPLICE_F_MOVE);
- if (w < 0)
- perror("splice");
- if (w != r) {
- fprintf(stderr, "Losing bytes\n");
- exit(EXIT_FAILURE);
- }
- //fprintf(stderr, "Wrote %zi bytes to /dev/null\n", r);
-
- total += w;
- }
-
- printf("Server: received %zu bytes\n", total);
-}
-
diff --git a/systemd.c b/systemd.c
index 21268b7..a592d3a 100644
--- a/systemd.c
+++ b/systemd.c
@@ -37,7 +37,7 @@ systemd_service_object_path(struct cfg *cfg, const char *service)
const char *s;
if (empty_str(service)) {
- error("invalid arguments\n");
+ error("invalid arguments");
return NULL;
}
@@ -86,7 +86,7 @@ get_bus(struct cfg *cfg)
if (!cfg->sd_bus) {
r = sd_bus_open_user(&cfg->sd_bus);
if (r < 0) {
- error("failed to connect to user system bus: %s\n", strerror(-r));
+ error("failed to connect to user system bus: %s", strerror(-r));
cfg->sd_bus_failed = true;
return NULL;
}
@@ -126,17 +126,17 @@ systemd_service_running(struct cfg *cfg, struct server *server)
&error,
&status);
if (r < 0) {
- error("failed to get status for service %s (%s): %s\n",
+ error("failed to get status for service %s (%s): %s",
server->systemd_service, server->systemd_obj, error.message);
goto out;
}
if (!strcmp(status, "active")) {
running = true;
- debug(DBG_SYSD, "systemd service %s (%s) is active\n",
+ debug(DBG_SYSD, "systemd service %s (%s) is active",
server->systemd_service, server->systemd_obj);
} else
- debug(DBG_SYSD, "systemd service %s (%s) is not active\n",
+ debug(DBG_SYSD, "systemd service %s (%s) is not active",
server->systemd_service, server->systemd_obj);
out:
@@ -168,18 +168,18 @@ systemd_service_action(struct cfg *cfg, struct server *server, const char *actio
"s",
"fail");
if (r < 0) {
- error("failed to perform action %s on systemd service %s: %s\n",
+ error("failed to perform action %s on systemd service %s: %s",
action, server->systemd_service, error.message);
goto out;
}
r = sd_bus_message_read(m, "o", &path);
if (r < 0) {
- error("failed to parse response message: %s\n", strerror(-r));
+ error("failed to parse response message: %s", strerror(-r));
goto out;
}
- verbose("action %s queued for service %s\n",
+ verbose("action %s queued for service %s",
action, server->systemd_service);
performed = true;
diff --git a/uring.c b/uring.c
index 5e1b168..c38c028 100644
--- a/uring.c
+++ b/uring.c
@@ -40,7 +40,7 @@ get_sqe(struct cfg *cfg, struct uring_task *task)
io_uring_submit(&cfg->uev->uring);
sqe = io_uring_get_sqe(&cfg->uev->uring);
if (!sqe)
- perrordie("failed to get an sqe!");
+ die("failed to get an sqe!");
}
sqe_count++;
@@ -75,7 +75,7 @@ uring_task_refdump(struct uring_task *task)
memcpy(dst, tmp->name, strlen(tmp->name));
}
- debug(DBG_REF, "%s (0x%p parent 0x%p free 0x%p fd %i ref %u)\n",
+ debug(DBG_REF, "%s (0x%p parent 0x%p free 0x%p fd %i ref %u)",
buf, task, task->parent, task->free, task->fd,
task->refcount);
}
@@ -87,11 +87,11 @@ uring_task_refdump(struct uring_task *task)
void
uring_task_destroy(struct cfg *cfg, struct uring_task *task)
{
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
if (!task) {
- error("called with no task\n");
+ error("called with no task");
return;
}
@@ -112,7 +112,7 @@ uring_task_put(struct cfg *cfg, struct uring_task *task)
{
struct uring_task *parent = task->parent;
- debug(DBG_REF, "task %s (%p), refcount %u\n",
+ debug(DBG_REF, "task %s (%p), refcount %u",
task->name, task, task->refcount);
task->refcount--;
@@ -121,7 +121,7 @@ uring_task_put(struct cfg *cfg, struct uring_task *task)
return;
if (task->refcount < 0)
- error("Negative refcount!\n");
+ error("Negative refcount!");
if (task->fd >= 0) {
uring_task_close_fd(cfg, task);
@@ -130,7 +130,7 @@ uring_task_put(struct cfg *cfg, struct uring_task *task)
}
if (parent)
- debug(DBG_REF, "putting parent %s (%p)\n",
+ debug(DBG_REF, "putting parent %s (%p)",
task->parent->name, task->parent);
if (task->free)
@@ -143,11 +143,11 @@ uring_task_put(struct cfg *cfg, struct uring_task *task)
void
uring_task_get(struct cfg *cfg, struct uring_task *task)
{
- debug(DBG_REF, "task %s (%p), refcount %u\n",
+ debug(DBG_REF, "task %s (%p), refcount %u",
task->name, task, task->refcount);
if (task->refcount < 0)
- error("Negative refcount!\n");
+ error("Negative refcount!");
task->refcount++;
}
@@ -155,7 +155,7 @@ uring_task_get(struct cfg *cfg, struct uring_task *task)
void
uring_task_set_buf(struct uring_task *task, struct uring_task_buf *tbuf)
{
- debug(DBG_UR, "task %s (%p), buf %p, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), buf %p, refcount %u",
task->name, task, tbuf, task->refcount);
if (tbuf) {
@@ -174,7 +174,7 @@ uring_task_set_buf(struct uring_task *task, struct uring_task_buf *tbuf)
void
uring_task_set_fd(struct uring_task *task, int fd)
{
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, fd, task->refcount);
task->fd = fd;
@@ -183,7 +183,7 @@ uring_task_set_fd(struct uring_task *task, int fd)
void
uring_task_close_fd(struct cfg *cfg, struct uring_task *task)
{
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
if (task->fd < 0)
@@ -229,7 +229,7 @@ uring_task_init(struct uring_task *task, const char *name,
if (task->parent) {
debug(DBG_REF, "task %s (%p), refcount %u, "
- "getting parent %s (%p), refcount %u\n",
+ "getting parent %s (%p), refcount %u",
task->name, task, task->refcount,
task->parent->name, task->parent, task->parent->refcount);
uring_task_get(NULL, task->parent);
@@ -241,11 +241,11 @@ uring_close(struct cfg *cfg, struct uring_task *task, int fd)
{
struct io_uring_sqe *sqe;
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
if (!task || fd < 0) {
- error("invalid parameters (task: %p (%s), fd: %i)\n", task, task->name, fd);
+ error("invalid parameters (task: %p (%s), fd: %i)", task, task->name, fd);
return;
}
@@ -262,7 +262,7 @@ uring_tbuf_write_cb(struct cfg *cfg, struct uring_task *task, int res)
if (!task || !task->tbuf || !task->final_cb)
die("missing parameters");
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
if (res < 0) {
@@ -290,11 +290,11 @@ void
uring_tbuf_write(struct cfg *cfg, struct uring_task *task, utask_cb_t final_cb)
{
if (!task || task->fd < 0 || !task->tbuf || task->tbuf->len < 0) {
- error("invalid parameters\n");
+ error("invalid parameters");
return;
}
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
task->tbuf->done = 0;
@@ -308,11 +308,11 @@ uring_write(struct cfg *cfg, struct uring_task *task, void *buf, size_t len, uta
struct io_uring_sqe *sqe;
if (task->fd < 0) {
- error("no fd set\n");
+ error("no fd set");
return;
}
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
sqe = get_sqe(cfg, task);
@@ -327,11 +327,11 @@ uring_tbuf_read_until_cb(struct cfg *cfg, struct uring_task *task, int res)
int r;
if (!task || !task->tbuf || !task->final_cb || !task->is_complete_cb) {
- error("invalid parameters\n");
+ error("invalid parameters");
return;
}
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
if (res < 0) {
@@ -369,11 +369,11 @@ uring_tbuf_read_until(struct cfg *cfg, struct uring_task *task,
rutask_cb_t is_complete_cb, utask_cb_t final_cb)
{
if (!task || task->fd < 0 || !task->tbuf || !is_complete_cb || !final_cb) {
- error("%s: invalid parameters\n", __func__);
+ error("%s: invalid parameters", __func__);
return;
}
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
task->tbuf->len = 0;
@@ -427,11 +427,11 @@ uring_read_offset(struct cfg *cfg, struct uring_task *task, void *buf, size_t le
struct io_uring_sqe *sqe;
if (task->fd < 0) {
- error("uring_read called with no fd set\n");
+ error("uring_read called with no fd set");
return;
}
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
sqe = get_sqe(cfg, task);
@@ -445,7 +445,7 @@ uring_openat(struct cfg *cfg, struct uring_task *task, const char *path, utask_c
{
struct io_uring_sqe *sqe;
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
sqe = get_sqe(cfg, task);
@@ -460,11 +460,11 @@ uring_tbuf_recvmsg(struct cfg *cfg, struct uring_task *task, utask_cb_t cb)
struct io_uring_sqe *sqe;
if (!task->tbuf) {
- error("called with no tbuf set\n");
+ error("called with no tbuf set");
return;
}
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
sqe = get_sqe(cfg, task);
@@ -483,11 +483,11 @@ uring_tbuf_sendmsg(struct cfg *cfg, struct uring_task *task, utask_cb_t cb)
struct io_uring_sqe *sqe;
if (!task->tbuf) {
- error("%s: called with no tbuf set\n", __func__);
+ error("%s: called with no tbuf set", __func__);
return;
}
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
sqe = get_sqe(cfg, task);
@@ -505,11 +505,11 @@ uring_connect(struct cfg *cfg, struct uring_task *task, struct saddr *saddr, uta
struct io_uring_sqe *sqe;
if (task->fd < 0) {
- error("fd set\n");
+ error("no fd set");
return;
}
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
sqe = get_sqe(cfg, task);
@@ -524,11 +524,11 @@ uring_accept(struct cfg *cfg, struct uring_task *task, struct saddr *saddr, utas
struct io_uring_sqe *sqe;
if (task->fd < 0) {
- error("no fd set\n");
+ error("no fd set");
return;
}
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
sqe = get_sqe(cfg, task);
@@ -544,11 +544,11 @@ uring_poll(struct cfg *cfg, struct uring_task *task, short poll_mask, utask_cb_t
struct io_uring_sqe *sqe;
if (task->fd < 0) {
- error("uring_poll called with no fd set\n");
+ error("uring_poll called with no fd set");
return;
}
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
sqe = get_sqe(cfg, task);
@@ -567,7 +567,7 @@ uring_poll_cancel(struct cfg *cfg, struct uring_task *task)
return;
}
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
sqe = get_sqe(cfg, task);
@@ -581,7 +581,7 @@ uring_free(struct uring_task *task)
{
struct uring_ev *uev = container_of(task, struct uring_ev, task);
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
io_uring_queue_exit(&uev->uring);
@@ -600,7 +600,7 @@ uring_delete(struct cfg *cfg)
{
struct uring_task *task = &cfg->uev->task;
- debug(DBG_UR, "task %s (%p), fd %i, refcount %u\n",
+ debug(DBG_UR, "task %s (%p), fd %i, refcount %u",
task->name, task, task->fd, task->refcount);
uring_task_put(cfg, task);
@@ -613,12 +613,12 @@ uring_init(struct cfg *cfg)
uev = zmalloc(sizeof(*uev));
if (!uev)
- perrordie("malloc");
+ die("malloc: %m");
if (io_uring_queue_init_params(4096, &uev->uring, &uev->uring_params) < 0)
- perrordie("io_uring_queue_init_params");
+ die("io_uring_queue_init_params");
- debug(DBG_UR, "uring initialized, features: 0x%08x\n",
+ debug(DBG_UR, "uring initialized, features: 0x%08x",
uev->uring_params.features);
uring_task_init(&uev->task, "uev", &cfg->task, uring_free);
@@ -631,7 +631,7 @@ uring_print_cqe(struct cfg *cfg, const char *type, struct uring_task *task,
struct io_uring_cqe *cqe)
{
debug(DBG_UR, "got CQE "
- "(type: %s, res: %i (%s), task: %s (%p), fd: %i, cb: %p)\n",
+ "(type: %s, res: %i (%s), task: %s (%p), fd: %i, cb: %p)",
type,
cqe->res,
cqe->res < 0 ? strerror(-cqe->res) : "ok",
@@ -655,7 +655,7 @@ uring_event_loop(struct cfg *cfg)
if (errno == EINTR)
continue;
else
- perrordie("io_uring_wait_cqe");
+ die("io_uring_wait_cqe: %i", r);
}
nr = 0;
diff --git a/utils.c b/utils.c
index b07fdff..0ddaa28 100644
--- a/utils.c
+++ b/utils.c
@@ -36,7 +36,7 @@ add_allocation(const char *allocfn, const char *callerfn, int line, void *ptr, s
{
struct allocation *a = malloc(sizeof(*a));
- debug(DBG_MALLOC, "called from %s:%i - %s(%zu) = %p\n",
+ debug(DBG_MALLOC, "called from %s:%i - %s(%zu) = %p",
callerfn, line, allocfn, size, ptr);
a->allocfn = allocfn;
@@ -57,8 +57,6 @@ __zmalloc(const char *fn, int line, size_t size)
ptr = calloc(1, size);
if (ptr)
add_allocation("zmalloc", fn, line, ptr, size);
- else
- perrordie("zmalloc");
return ptr;
}
@@ -70,8 +68,6 @@ __xstrdup(const char *fn, int line, const char *s)
ptr = strdup(s);
if (ptr)
add_allocation("xstrdup", fn, line, ptr, strlen(s) + 1);
- else
- perrordie("strdup");
return ptr;
}
@@ -83,8 +79,6 @@ __xstrndup(const char *fn, int line, const char *s, size_t n)
ptr = strndup(s, n);
if (ptr)
add_allocation("xstrndup", fn, line, ptr, n);
- else
- perrordie("strndup");
return ptr;
}
@@ -99,7 +93,7 @@ __xfree(const char *fn, int line, void *ptr)
free(ptr);
malloc_count--;
- debug(DBG_MALLOC, "called from %s:%i - %p\n", fn, line, ptr);
+ debug(DBG_MALLOC, "called from %s:%i - %p", fn, line, ptr);
list_for_each_entry_safe(a, tmp, &malloc_list, list) {
if (a->ptr == ptr) {
@@ -110,7 +104,7 @@ __xfree(const char *fn, int line, void *ptr)
}
if (delete_count != 1) {
- error("Delete count is %u for ptr 0x%p\n", delete_count, ptr);
+ error("Delete count is %u for ptr 0x%p", delete_count, ptr);
exit(EXIT_FAILURE);
}
}
@@ -125,21 +119,21 @@ debug_resource_usage()
ssize_t r;
unsigned file_count = 0;
- debug(DBG_MALLOC, "Still malloced %i (total %u)\n",
+ debug(DBG_MALLOC, "Still malloced %i (total %u)",
malloc_count, total_malloc_count);
list_for_each_entry(a, &malloc_list, list) {
- debug(DBG_MALLOC, "* Lost allocation - %s:%i - ptr: %p, size: %zu\n",
+ debug(DBG_MALLOC, "* Lost allocation - %s:%i - ptr: %p, size: %zu",
a->callerfn, a->line, a->ptr, a->size);
}
dir = opendir("/proc/self/fd");
if (!dir) {
- error("failed to open fd dir\n");
+ error("failed to open fd dir");
return;
}
- debug(DBG_MALLOC, "Open files:\n");
+ debug(DBG_MALLOC, "Open files:");
while ((dent = readdir(dir)) != NULL) {
if (!strcmp(dent->d_name, ".") ||
!strcmp(dent->d_name, ".."))
@@ -147,19 +141,19 @@ debug_resource_usage()
r = readlinkat(dirfd(dir), dent->d_name, buf, sizeof(buf));
if (r < 0) {
- debug(DBG_MALLOC, "Failed to readlink %s\n", dent->d_name);
+ debug(DBG_MALLOC, "Failed to readlink %s", dent->d_name);
continue;
}
buf[r] = '\0';
- debug(DBG_MALLOC, " * %s -> %s\n", dent->d_name, buf);
+ debug(DBG_MALLOC, " * %s -> %s", dent->d_name, buf);
file_count++;
}
closedir(dir);
if (file_count > 4)
- debug(DBG_MALLOC, "Lost file descriptor(s)\n");
+ debug(DBG_MALLOC, "Lost file descriptor(s)");
- debug(DBG_MALLOC, "CQEs used: %" PRIu64 ", SQEs used: %" PRIu64 "\n",
+ debug(DBG_MALLOC, "CQEs used: %" PRIu64 ", SQEs used: %" PRIu64,
cqe_count, sqe_count);
}
@@ -214,7 +208,7 @@ connect_cb(struct cfg *cfg, struct uring_task *task, int res)
struct connection *conn = task->priv;
if (res < 0) {
- debug(DBG_UR, "%s: connection to %s failed\n",
+ debug(DBG_UR, "%s: connection to %s failed",
task->name, conn->remote.addrstr);
uring_task_close_fd(cfg, task);
connect_next(cfg, task, conn);
@@ -223,7 +217,7 @@ connect_cb(struct cfg *cfg, struct uring_task *task, int res)
connection_set_local(cfg, conn, task->fd);
- debug(DBG_UR, "%s: connection established %s -> %s\n",
+ debug(DBG_UR, "%s: connection established %s -> %s",
task->name, conn->local.addrstr, conn->remote.addrstr);
conn->callback(cfg, conn, true);
@@ -250,14 +244,14 @@ again:
}
if (!remote) {
- debug(DBG_UR, "%s: no more remote addresses to attempt\n",
+ debug(DBG_UR, "%s: no more remote addresses to attempt",
task->name);
goto out;
}
conn->next_addr++;
connection_set_remote(cfg, conn, remote);
- debug(DBG_MALLOC, "%s: attempting to connect to %s\n",
+ debug(DBG_MALLOC, "%s: attempting to connect to %s",
task->name, conn->remote.addrstr);
sfd = socket(conn->remote.storage.ss_family, SOCK_STREAM | SOCK_CLOEXEC, 0);
@@ -283,7 +277,7 @@ connect_any(struct cfg *cfg, struct uring_task *task,
void (*callback)(struct cfg *, struct connection *, bool res))
{
if (!cfg || !task || !addrs || !conn || !callback) {
- error("invalid arguments\n");
+ error("invalid arguments");
return;
}