diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-16 13:15:33 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-16 13:15:33 +0200 |
commit | 9eeffbeab84e71bd0a4cc0855cb1f72ad1849ba6 (patch) | |
tree | 40e3ee77ce70f8ed2137c3f92ec72e980630e45b | |
parent | cab7429706aa6fce9d217ba6c5e3b6e5557914d5 (diff) |
Some more debug cleanups
-rw-r--r-- | cfgdir.c | 4 | ||||
-rw-r--r-- | main.c | 15 | ||||
-rw-r--r-- | main.h | 31 | ||||
-rw-r--r-- | uring.c | 16 |
4 files changed, 37 insertions, 29 deletions
@@ -291,7 +291,7 @@ inotify_free(struct uring_task *task) fprintf(stderr, "%s called\n", __func__); if (!iev || !cfg) - die("%s: iev or cfg is NULL!?\n", __func__); + die("iev or cfg is NULL!?"); xfree(iev); cfg->iev = NULL; @@ -364,7 +364,7 @@ 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\n"); + die("Configuration directory gone, exiting"); if (event->mask & IN_Q_OVERFLOW) { error("inotify queue overflow!\n"); @@ -30,7 +30,7 @@ bool exiting = false; struct cfg *cfghack = NULL; void -do_debug(enum debug_category category, const char *fmt, ...) +__debug(enum debug_category category, const char *fmt, ...) { va_list ap; @@ -39,9 +39,8 @@ do_debug(enum debug_category category, const char *fmt, ...) va_end(ap); } -__attribute__((noreturn)) -void -die(const char *fmt, ...) +__attribute__((noreturn)) void +__die(const char *fmt, ...) { va_list ap; @@ -138,18 +137,18 @@ cfg_init(int argc, char **argv) } if (!debug_category_str[i].name) - die("Invalid debug category\n"); + die("invalid debug category"); debug_mask |= debug_category_str[i].val; break; default: - die("Invalid arguments\n"); + die("invalid arguments"); } } if (optind < argc) - die("Invalid arguments\n"); + die("invalid arguments"); if (!cfg->homedir) cfg->homedir = "/home/david/intest"; @@ -217,7 +216,7 @@ signalfd_read(struct cfg *cfg, struct uring_task *task, int res) exit(EXIT_FAILURE); if (res != sizeof(sev->buf)) - die("Error in signalfd (%i)\n", res); + die("error in signalfd (%i)", res); if (sev->buf < 1000) { fprintf(stderr, "Got a signal to quit\n"); @@ -27,17 +27,26 @@ debug_enabled(enum debug_category category) return !!(category & debug_mask); } -void do_debug(enum debug_category category, const char *fmt, ...); - -#define __debug(c, ...) do { if (debug_enabled((c))) do_debug((c), __VA_ARGS__); } while (0) -#define debug(c, fmt, ...) __debug(c, "%s:" fmt, __func__, __VA_ARGS__) -#define verbose(...) __debug(DBG_VERBOSE, __VA_ARGS__) -#define info(...) __debug(DBG_ERROR, __VA_ARGS__) -#define error(...) __debug(DBG_ERROR, __VA_ARGS__) - -void die(const char *fmt, ...); - -#define perrordie(msg) die("%s: %m\n", msg) +void __debug(enum debug_category category, const char *fmt, ...) __attribute__((format(printf, 2, 3))); + +#define __ifdebug(c, fmt, ...) \ + do { \ + if (debug_enabled((c))) \ + __debug((c), fmt __VA_OPT__(,) __VA_ARGS__); \ + } while (0) + +#define debug(c, fmt, ...) __ifdebug((c), "%s:%i: " fmt, __func__, \ + __LINE__, __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__) + +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; @@ -34,14 +34,14 @@ get_sqe(struct cfg *cfg, struct uring_task *task) struct io_uring_sqe *sqe; if (!cfg || !task) - die("%s: invalid parameters\n", __func__); + die("invalid parameters"); sqe = io_uring_get_sqe(&cfg->uev->uring); if (!sqe) { io_uring_submit(&cfg->uev->uring); sqe = io_uring_get_sqe(&cfg->uev->uring); if (!sqe) - perrordie("Failed to get an sqe!\n"); + perrordie("failed to get an sqe!"); } sqe_count++; @@ -194,10 +194,10 @@ struct uring_task * uring_parent(struct cfg *cfg) { if (!cfg) - die("%s: called with null cfg\n"); + die("called with null cfg"); if (!cfg->uev) - die("%s: called with uninitialized uring\n"); + die("called with uninitialized uring"); return &cfg->uev->task; } @@ -211,10 +211,10 @@ uring_task_init(struct uring_task *task, const char *name, if (first) first = false; else if (!parent) - die("uring_task_init called without a parent\n"); + die("called without a parent"); if (!free) - die("uring_task_init called without destructor\n"); + die("called without destructor"); task->refcount = 1; task->fd = -1; @@ -254,7 +254,7 @@ uring_tbuf_write_cb(struct cfg *cfg, struct uring_task *task, int res) int r; if (!task || !task->tbuf || !task->final_callback) - perrordie("%s: missing parameters\n"); + die("missing parameters"); if (res < 0) { r = res; @@ -640,7 +640,7 @@ uring_event_loop(struct cfg *cfg) break; default: - die("%s: unknown CQE type\n"); + die("unknown CQE type"); } if (do_callback && task->callback) |