#ifndef foomainhfoo #define foomainhfoo #include #include struct cfg; #include "utils.h" extern bool exiting; extern unsigned debug_mask; enum debug_category { DBG_ERROR = (0x1 << 1), DBG_INFO = (0x1 << 2), DBG_VERBOSE = (0x1 << 3), DBG_CFG = (0x1 << 4), DBG_REF = (0x1 << 5), DBG_MALLOC = (0x1 << 6), DBG_ANN = (0x1 << 7), DBG_SIG = (0x1 << 7), DBG_UR = (0x1 << 8), DBG_SRV = (0x1 << 9), DBG_PROXY = (0x1 << 10), DBG_RCON = (0x1 << 11), DBG_IDLE = (0x1 << 12), DBG_IGMP = (0x1 << 13), DBG_SYSD = (0x1 << 14), }; static inline bool debug_enabled(enum debug_category category) { return !!(category & debug_mask); } 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_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, "%s: " fmt, \ __func__ __VA_OPT__(,) __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; /* To save typing in all the function definitions below */ typedef void (*callback_t)(struct cfg *, struct uring_task *, int res); typedef int (*rcallback_t)(struct cfg *, struct uring_task *, int res); struct uring_task_buf { char buf[4096]; size_t len; size_t done; struct iovec iov; struct msghdr msg; }; struct uring_task { const char *name; unsigned refcount; int fd; struct uring_task *parent; void (*free)(struct uring_task *); bool dead; struct uring_task_buf *tbuf; callback_t callback; rcallback_t complete_callback; /* to check if tbuf processing is done */ callback_t final_callback; /* once tbuf processing is done */ struct sockaddr_in46 addr; /* used for recvmsg/sendmsg */ void *priv; }; struct cfg { const char *homedir; struct uring_ev *uev; struct inotify_ev *iev; struct signalfd_ev *sev; struct announce *aev; struct igmp *igmp; struct sd_bus *sd_bus; bool sd_bus_failed; struct uring_task task; struct list_head servers; }; #endif