summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cfgdir.c4
-rw-r--r--main.c15
-rw-r--r--main.h31
-rw-r--r--uring.c16
4 files changed, 37 insertions, 29 deletions
diff --git a/cfgdir.c b/cfgdir.c
index 85646bc..3d5c2f7 100644
--- a/cfgdir.c
+++ b/cfgdir.c
@@ -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");
diff --git a/main.c b/main.c
index 51ae12a..1ebe59e 100644
--- a/main.c
+++ b/main.c
@@ -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");
diff --git a/main.h b/main.h
index 255a252..a794f6b 100644
--- a/main.h
+++ b/main.h
@@ -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;
diff --git a/uring.c b/uring.c
index ea5934d..37b65eb 100644
--- a/uring.c
+++ b/uring.c
@@ -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)