Debug tweaks

- Add gcc printf format check to _log()
- Show thread ids
- Enable setting debug level
This commit is contained in:
Kim Woelders
2018-07-17 14:02:44 +02:00
parent 137418ad1e
commit 778242986f
+18 -4
View File
@@ -29,6 +29,9 @@
#define RX_BUF_SIZE 1024
#define _PRF_N_(no) __attribute__((__format__(__printf__, (no), (no) + 1)))
#define _PRF2_ _PRF_N_(2)
static struct ttynvt_param {
unsigned int major;
@@ -69,17 +72,28 @@ typedef struct ttynvt {
tn_ctx_t *tn;
} ttynvt_t;
static void _log(int prio, const char *fmt, ...)
#include <sys/syscall.h>
#define gettid() (pid_t)syscall(__NR_gettid)
_PRF2_ static void _log(int prio, const char *fmt, ...)
{
va_list arg;
char buf[256];
va_start(arg, fmt);
#if 0
vsyslog(prio, fmt, arg);
#else
vsnprintf(buf, sizeof(buf), fmt, arg);
syslog(prio, "[%d] %s", gettid(), buf);
#endif
va_end(arg);
}
#define DBG(...) \
if (ttynvt_param.debug) _log(LOG_DEBUG, __VA_ARGS__)
if (ttynvt_param.debug > 0) _log(LOG_DEBUG, __VA_ARGS__)
#define DBG2(...) \
if (ttynvt_param.debug > 1) _log(LOG_DEBUG, __VA_ARGS__)
static int _check_dev(void)
@@ -812,7 +826,7 @@ static const struct cuse_lowlevel_ops ttynvt_op = {
#define TTYNET_OPT(t, p, v) { t, offsetof(struct ttynvt_param, p), v }
static const struct fuse_opt ttynvt_opts[] = {
TTYNET_OPT("-D", debug, 1),
TTYNET_OPT("-D %d", debug, 1),
TTYNET_OPT("-M %u", major, 1),
TTYNET_OPT("--maj=%u", major, 1),
TTYNET_OPT("-m %u", minor, 1),
@@ -829,7 +843,7 @@ static const struct fuse_opt ttynvt_opts[] = {
static void print_help(void)
{
fprintf(stderr, "ttynvt Usage:\n"
"\t-D\tEnable debug\n"
"\t-D level\tEnable debug\n"
"\t-M major, --maj=major\n"
"\t-m minor, --min=minor\n"
"\t-n name, --name=name (default: ttyNVT0)\n"