From c48f30ca53695faa09683fc8f506463c07f9c2c3 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Tue, 16 Jun 2020 22:31:39 +0200 Subject: Fixup remaining missed cases of debugging --- cfgdir.c | 6 ++---- main.c | 20 +++++++++++--------- proxy.c | 5 ++++- uring.c | 8 ++++---- utils.c | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/cfgdir.c b/cfgdir.c index 040e016..28a300a 100644 --- a/cfgdir.c +++ b/cfgdir.c @@ -352,15 +352,13 @@ inotify_cb(struct cfg *cfg, struct uring_task *task, int res) char *ptr; struct server *scfg; - fprintf(stderr, "%s: ret is %i (ref %u)\n", __func__, res, task->refcount); - if (task->dead) { - fprintf(stderr, "%s: task is dead\n", __func__); + debug(DBG_CFG, "task is dead\n"); return; } if (res <= 0) - perrordie("inotify_read"); + perrordie("inotify_read (%i)", res); for (ptr = iev->buf; ptr < iev->buf + res; ptr += sizeof(struct inotify_event) + event->len) { event = (const struct inotify_event *)ptr; diff --git a/main.c b/main.c index 5296171..148b2d2 100644 --- a/main.c +++ b/main.c @@ -129,10 +129,9 @@ cfg_init(int argc, char **argv) unsigned i; cfg = zmalloc(sizeof(*cfg)); - if (!cfg) { - perror("malloc"); - return NULL; - } + if (!cfg) + perrordie("malloc"); + uring_task_init(&cfg->task, "cfg", NULL, cfg_free); list_init(&cfg->servers); @@ -220,9 +219,12 @@ dump_tree(struct cfg *cfg) { struct server *server; - fprintf(stderr, "\n\n\n\n"); - fprintf(stderr, "Dumping Tree\n"); - fprintf(stderr, "============\n"); + if (!debug_enabled(DBG_REF)) + return; + + debug(DBG_REF, "\n\n\n\n"); + debug(DBG_REF, "Dumping Tree\n"); + debug(DBG_REF, "============\n"); uring_task_refdump(&cfg->task); uring_refdump(cfg->uev); if (cfg->sev) @@ -233,8 +235,8 @@ dump_tree(struct cfg *cfg) cfgdir_refdump(cfg->iev); list_for_each_entry(server, &cfg->servers, list) server_refdump(server); - fprintf(stderr, "============\n"); - fprintf(stderr, "\n\n\n\n"); + debug(DBG_REF, "============\n"); + debug(DBG_REF, "\n\n\n\n"); } static void diff --git a/proxy.c b/proxy.c index 91b7c02..fbb9ddf 100644 --- a/proxy.c +++ b/proxy.c @@ -67,7 +67,10 @@ proxy_free(struct uring_task *task) char stc[100]; char duration[100]; - fprintf(stderr, "%s: %s\n", __func__, proxy->scfg->name); + debug(DBG_PROXY, "server: %s, src: %s, dst: %s\n", + proxy->scfg->name, + proxy->client_conn.remotestr, + proxy->server_conn.remotestr); if (proxy->begin > 0) { format_time(duration, sizeof(duration), time(NULL) - proxy->begin); diff --git a/uring.c b/uring.c index dc095c8..10eac79 100644 --- a/uring.c +++ b/uring.c @@ -76,9 +76,9 @@ uring_task_refdump(struct uring_task *task) memcpy(dst, tmp->name, strlen(tmp->name)); } - fprintf(stderr, "%s (0x%p parent 0x%p free 0x%p fd %i ref %u)\n", - buf, task, task->parent, task->free, task->fd, - task->refcount); + debug(DBG_REF, "%s (0x%p parent 0x%p free 0x%p fd %i ref %u)\n", + buf, task, task->parent, task->free, task->fd, + task->refcount); } /* @@ -562,7 +562,7 @@ uring_poll_cancel(struct cfg *cfg, struct uring_task *task) struct io_uring_sqe *sqe; if (task->fd < 0) { - fprintf(stderr, "uring_poll_cancel called with no fd set\n"); + error("no fd set\n"); return; } diff --git a/utils.c b/utils.c index c36d18a..2d0294a 100644 --- a/utils.c +++ b/utils.c @@ -260,7 +260,7 @@ again: sfd = socket(conn->remote.storage.ss_family, SOCK_STREAM | SOCK_CLOEXEC, 0); if (sfd < 0) { - perror("socket"); + error("socket: %m"); goto again; } -- cgit v1.2.3