summaryrefslogtreecommitdiff
path: root/cfgdir.c
diff options
context:
space:
mode:
Diffstat (limited to 'cfgdir.c')
-rw-r--r--cfgdir.c97
1 files changed, 49 insertions, 48 deletions
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)