summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--announce.c23
-rw-r--r--main.c20
-rw-r--r--main.h8
3 files changed, 37 insertions, 14 deletions
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;
diff --git a/main.c b/main.c
index 1ebe59e..f7023c4 100644
--- a/main.c
+++ b/main.c
@@ -93,6 +93,9 @@ const struct {
.name = "malloc",
.val = DBG_MALLOC
},{
+ .name = "announce",
+ .val = DBG_ANN
+ },{
.name = NULL,
.val = 0
}
@@ -118,10 +121,11 @@ cfg_init(int argc, char **argv)
static struct option long_options[] = {
{ "homedir", required_argument, 0, 'h' },
{ "debug", required_argument, 0, 'd' },
+ { "verbose", no_argument, 0, 'v' },
{ 0, 0, 0, 0 }
};
- c = getopt_long(argc, argv, ":h:d:",
+ c = getopt_long(argc, argv, ":h:d:v",
long_options, &option_index);
if (c == -1)
break;
@@ -130,7 +134,21 @@ cfg_init(int argc, char **argv)
case 'h':
cfg->homedir = optarg;
break;
+ case 'v':
+ debug_mask |= DBG_VERBOSE;
+ break;
case 'd':
+ if (!strcasecmp(optarg, "all")) {
+ debug_mask = ~0;
+ break;
+ } else if (!strcasecmp(optarg, "list")) {
+ error("Debug categories:\n");
+ error(" * all\n");
+ for (i = 0; debug_category_str[i].name; i++)
+ error(" * %s\n", debug_category_str[i].name);
+ exit(EXIT_FAILURE);
+ }
+
for (i = 0; debug_category_str[i].name; i++) {
if (!strcasecmp(optarg, debug_category_str[i].name))
break;
diff --git a/main.h b/main.h
index a794f6b..9710d23 100644
--- a/main.h
+++ b/main.h
@@ -19,6 +19,7 @@ enum debug_category {
DBG_CFG = (0x1 << 4),
DBG_REF = (0x1 << 5),
DBG_MALLOC = (0x1 << 6),
+ DBG_ANN = (0x1 << 7),
};
static inline bool
@@ -35,11 +36,12 @@ void __debug(enum debug_category category, const char *fmt, ...) __attribute__((
__debug((c), fmt __VA_OPT__(,) __VA_ARGS__); \
} while (0)
-#define debug(c, fmt, ...) __ifdebug((c), "%s:%i: " fmt, __func__, \
- __LINE__, __VA_ARGS__)
+#define debug(c, fmt, ...) __ifdebug((c), "%s:%i: " fmt, __func__, \
+ __LINE__ __VA_OPT__(,) __VA_ARGS__)
#define verbose(fmt, ...) __ifdebug(DBG_VERBOSE, fmt, __VA_ARGS__)
#define info(fmt, ...) __ifdebug(DBG_ERROR, fmt, __VA_ARGS__)
-#define error(fmt, ...) __ifdebug(DBG_ERROR, fmt, __VA_ARGS__)
+#define error(fmt, ...) __ifdebug(DBG_ERROR, "%s: " fmt, \
+ __func__ __VA_OPT__(,) __VA_ARGS__)
void __die(const char *fmt, ...) __attribute__((format(printf, 1, 2)));