From 2aea45f0c9ffc0dcc9857478f086142ccf7811f0 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Tue, 16 Jun 2020 13:36:06 +0200 Subject: Add all and list debug options, convert announce to use debugging --- announce.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'announce.c') diff --git a/announce.c b/announce.c index 3edee1b..9578b0c 100644 --- a/announce.c +++ b/announce.c @@ -22,13 +22,16 @@ mcast_free(struct uring_task *task) { struct announce *aev = container_of(task, struct announce, mcast_task); - fprintf(stderr, "%s: called with task 0x%p and aev 0x%p\n", __func__, task, aev); + debug(DBG_ANN, "task %p, aev %p\n", task, aev); } static void mcast_sent(struct cfg *cfg, struct uring_task *task, int res) { - fprintf(stderr, "%s: result %i\n", __func__, res); + if (res < 0) + error("failure %i\n", res); + else + debug(DBG_ANN, "result %i\n", res); } static void @@ -44,7 +47,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("%s: snprintf returned %i\n", __func__, len); + error("snprintf returned %i\n", len); return; } @@ -59,7 +62,7 @@ mcast_send_all(struct cfg *cfg, struct announce *aev) struct server *server; list_for_each_entry(server, &cfg->servers, list) { - fprintf(stderr, "Announcing server: %s\n", server->name); + verbose("Announcing server: %s\n", server->name); mcast_send(cfg, aev, server); } } @@ -69,17 +72,17 @@ announce_cb(struct cfg *cfg, struct uring_task *task, int res) { struct announce *aev = container_of(task, struct announce, task); - fprintf(stderr, "%s: ret is %i (ref %u)\n", __func__, res, task->refcount); + debug(DBG_ANN, "res %i\n", res); if (task->dead) { - fprintf(stderr, "%s: task is dead\n", __func__); + debug(DBG_ANN, "task is dead\n"); return; } if (res != sizeof(aev->value)) perrordie("timerfd_read"); - fprintf(stderr, "%s: called with value %" PRIu64 "\n", __func__, aev->value); + debug(DBG_ANN, "timerfd value %" PRIu64 "\n", aev->value); mcast_send_all(cfg, aev); uring_read(cfg, &aev->task, &aev->value, sizeof(aev->value), announce_cb); } @@ -89,7 +92,7 @@ announce_free(struct uring_task *task) { struct announce *aev = container_of(task, struct announce, task); - fprintf(stderr, "%s: called with task 0x%p and aev 0x%p\n", __func__, task, aev); + debug(DBG_ANN, "task %p, aev 0x%p\n", task, aev); xfree(aev); } @@ -107,11 +110,11 @@ void announce_delete(struct cfg *cfg) { if (!cfg->aev) { - fprintf(stderr, "%s called with no announce!\n", __func__); + error("missing parameters\n"); return; } - fprintf(stderr, "%s called, closing fd %i\n", __func__, cfg->aev->task.fd); + debug(DBG_ANN, "closing fd %i\n", cfg->aev->task.fd); uring_task_destroy(cfg, &cfg->aev->mcast_task); uring_task_destroy(cfg, &cfg->aev->task); cfg->aev = NULL; -- cgit v1.2.3