summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <Jiri Olsa jolsa@redhat.com>2010-04-15 14:49:27 +0200
committerJiri Olsa <Jiri Olsa jolsa@redhat.com>2010-04-15 14:49:27 +0200
commit99f24c4e89b78a5926396f5909a1739f6fbce482 (patch)
treed2698f249b8a11f70b817f395ff4fd5ff93a9650
parentae34dbc89a17aae2da2f21eb8293bf0185c149b2 (diff)
downloadtsnif-99f24c4e89b78a5926396f5909a1739f6fbce482.tar.gz
tsnif-99f24c4e89b78a5926396f5909a1739f6fbce482.tar.xz
tsnif-99f24c4e89b78a5926396f5909a1739f6fbce482.zip
debug/verbose flag refactoring
-rw-r--r--src/Makefile30
-rw-r--r--src/fsm.c11
-rw-r--r--src/intf.c17
-rw-r--r--src/intf.h16
-rw-r--r--src/storage-mmap.c97
-rw-r--r--src/test.c3
-rw-r--r--src/test.h1
-rw-r--r--src/trans-libnl.c19
-rw-r--r--src/tsnif-replay.c9
-rw-r--r--src/tsnif.c1
-rw-r--r--src/tsnifd.c11
11 files changed, 109 insertions, 106 deletions
diff --git a/src/Makefile b/src/Makefile
index 57b564c..8da59bc 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -10,29 +10,44 @@ STORAGE_OBJS= \
MISC_OBJS= \
src/misc.o
+DEBUG_OBJS= \
+ src/debug.o
+
INTF_LIB=-lnl
TSNIF=tsnif
TSNIF_OBJS= \
- src/tsnif.o
+ src/tsnif.o \
+ $(INTF_OBJS) \
+ $(STORAGE_OBJS) \
+ $(MISC_OBJS) \
+ $(DEBUG_OBJS)
-$(TSNIF): $(TSNIF_OBJS) $(INTF_OBJS) $(STORAGE_OBJS) $(MISC_OBJS)
+$(TSNIF): $(TSNIF_OBJS)
$(QUIET_LD)$(CC) -o $@ $^ $(INTF_LIB)
TSNIF_REPLAY=tsnif-replay
TSNIF_REPLAY_OBJS= \
- src/tsnif-replay.o
-$(TSNIF_REPLAY): $(TSNIF_REPLAY_OBJS) $(STORAGE_OBJS) $(MISC_OBJS)
+ src/tsnif-replay.o \
+ $(STORAGE_OBJS) \
+ $(MISC_OBJS) \
+ $(DEBUG_OBJS)
+
+$(TSNIF_REPLAY): $(TSNIF_REPLAY_OBJS)
$(QUIET_LD)$(CC) -o $@ $^
TSNIFD=tsnifd
TSNIFD_OBJS= \
- src/tsnifd.o
-$(TSNIFD): $(TSNIFD_OBJS) $(INTF_OBJS) $(STORAGE_OBJS)
+ src/tsnifd.o \
+ $(INTF_OBJS) \
+ $(STORAGE_OBJS) \
+ $(DEBUG_OBJS)
+
+$(TSNIFD): $(TSNIFD_OBJS)
$(QUIET_LD)$(CC) -o $@ $^ $(INTF_LIB)
@@ -46,7 +61,8 @@ TEST=tsnif-test
TEST_OBJS=\
src/test.o \
src/test-storage-mmap.o \
- $(STORAGE_OBJS)
+ $(STORAGE_OBJS) \
+ $(DEBUG_OBJS)
$(TEST): $(TEST_OBJS)
$(QUIET_LD)$(CC) -o $@ $^
diff --git a/src/fsm.c b/src/fsm.c
index 276fd60..31ccd87 100644
--- a/src/fsm.c
+++ b/src/fsm.c
@@ -3,6 +3,7 @@
#include "intf.h"
#include "trans.h"
+#include "debug.h"
static int process_release(struct tsnif_handle *h, struct tsnif_term *term)
@@ -12,7 +13,7 @@ static int process_release(struct tsnif_handle *h, struct tsnif_term *term)
term->state = TSNIF_INTF_STATE_DONE;
- TSNIF_DEBUG("type %d, idx %d\n", term->type, term->idx);
+ TSNIF_DEBUG(FSM, "type %d, idx %d\n", term->type, term->idx);
return h->ops->cb_release(term);
}
@@ -32,7 +33,7 @@ static int process_tgroup(struct tsnif_handle *h, struct tsnif_term *term,
err = trans_group(&h->trans, group);
term->state = err ? TSNIF_INTF_STATE_DONE : TSNIF_INTF_STATE_DATA;
- TSNIF_DEBUG("adding group %d, err %d\n", group, err);
+ TSNIF_DEBUG(FSM, "adding group %d, err %d\n", group, err);
return err;
}
@@ -42,7 +43,7 @@ static int process_data(struct tsnif_handle *h,
{
struct tsnif_data data;
- TSNIF_DEBUG("type %d, idx %d\n",
+ TSNIF_DEBUG(FSM, "type %d, idx %d\n",
term->type, term->idx);
if (!h->ops || !h->ops->cb_data)
@@ -61,7 +62,7 @@ static int new(struct tsnif_handle *h,
struct tsnif_term *term,
struct trans_msg *msg)
{
- TSNIF_DEBUG("got data in the NEW state, something is wrong\n");
+ TSNIF_DEBUG(FSM, "got data in the NEW state, something is wrong\n");
return -1;
}
@@ -150,7 +151,7 @@ int fsm_process(struct tsnif_handle *h,
struct tsnif_term *term,
struct trans_msg *msg)
{
- TSNIF_DEBUG("got cmd %d for term type %d, idx %d, state %d\n",
+ TSNIF_DEBUG(FSM, "got cmd %d for term type %d, idx %d, state %d\n",
msg->cmd, term->type, term->idx, term->state);
/* we can get the release command in any state,
diff --git a/src/intf.c b/src/intf.c
index 6c55571..e03b41a 100644
--- a/src/intf.c
+++ b/src/intf.c
@@ -4,8 +4,7 @@
#include "intf.h"
#include "list.h"
#include "fsm.h"
-
-int tsnif_debug = 0;
+#include "debug.h"
static struct tsnif_term *term_find(struct tsnif_handle *h, int type, int idx)
{
@@ -52,7 +51,7 @@ static int trans_cb(struct trans_handle *h, struct trans_msg *msg)
struct tsnif_handle *handle;
struct tsnif_term *term;
- TSNIF_DEBUG("got cmd %d, type %d, idx %d\n",
+ TSNIF_DEBUG(INTF, "got cmd %d, type %d, idx %d\n",
msg->cmd, msg->type, msg->idx);
handle = container_of(h, struct tsnif_handle, trans);
@@ -90,7 +89,7 @@ static int init_mgroup(struct tsnif_handle *h)
{
struct trans_msg msg;
- TSNIF_DEBUG("sending mgroup command\n");
+ TSNIF_DEBUG(INTF, "sending mgroup command\n");
msg.cmd = TSNIF_CMD_MGROUP;
return trans_send(&h->trans, &msg);
@@ -159,10 +158,10 @@ int tsnif_attach(struct tsnif_term *term)
struct trans_msg msg;
struct tsnif_handle *h = term->handle;
- TSNIF_DEBUG("type %d, idx %d\n", term->type, term->idx);
+ TSNIF_DEBUG(INTF, "type %d, idx %d\n", term->type, term->idx);
if (fsm_send(term, TSNIF_CMD_ATTACH)) {
- TSNIF_DEBUG("wrong state (%d) skiping detach\n",
+ TSNIF_DEBUG(INTF, "wrong state (%d) skiping detach\n",
term->state);
return -1;
}
@@ -179,10 +178,10 @@ int tsnif_detach(struct tsnif_term *term)
struct trans_msg msg;
struct tsnif_handle *h = term->handle;
- TSNIF_DEBUG("type %d, idx %d\n", term->type, term->idx);
+ TSNIF_DEBUG(INTF, "type %d, idx %d\n", term->type, term->idx);
if (fsm_send(term, TSNIF_CMD_DETACH)) {
- TSNIF_DEBUG("wrong state (%d) skiping detach\n",
+ TSNIF_DEBUG(INTF, "wrong state (%d) skiping detach\n",
term->state);
return -1;
}
@@ -198,7 +197,7 @@ int tsnif_list(struct tsnif_handle *h)
{
struct trans_msg msg;
- TSNIF_DEBUG("sending list command\n");
+ TSNIF_DEBUG(INTF, "sending list command\n");
memset(&msg, 0x0, sizeof(msg));
msg.cmd = TSNIF_CMD_TTY_LIST;
diff --git a/src/intf.h b/src/intf.h
index 0723be7..c136b6b 100644
--- a/src/intf.h
+++ b/src/intf.h
@@ -78,20 +78,4 @@ int tsnif_detach(struct tsnif_term *term);
#define tsnif_for_each(term, t, handle) \
list_for_each_entry_safe(term, t, (&handle->terms), list)
-extern int tsnif_debug;
-
-#define TSNIF_DEBUG(fmt, args...) \
- do { \
- if (tsnif_debug) { \
- char lpbuf[256]; \
- snprintf(lpbuf, sizeof(lpbuf)-1, "USER [%3d:%s:%05d %s] %s", \
- (pid_t) syscall(SYS_gettid), \
- __FILE__, \
- __LINE__, \
- __FUNCTION__, \
- fmt); \
- printf(lpbuf, ## args); \
- } \
- } while(0)
-
#endif /* !INTF_H */
diff --git a/src/storage-mmap.c b/src/storage-mmap.c
index 232a442..0cc0419 100644
--- a/src/storage-mmap.c
+++ b/src/storage-mmap.c
@@ -10,6 +10,7 @@
#include "storage.h"
#include "intf.h"
+#include "debug.h"
static int unmap_chunk(struct tsnif_storage_handle *h,
struct tsnif_storage_chunk *chunk);
@@ -59,21 +60,21 @@ static int check_header(struct tsnif_storage_handle *h)
struct tsnif_storage_header *common = &header->common;
if (common->magic != TSNIF_HEADER_MAGIC) {
- TSNIF_DEBUG("failed: wrong header magic %x\n", common->magic);
+ TSNIF_DEBUG(STORAGE, "failed: wrong header magic %x\n", common->magic);
return -1;
}
if (common->version != TSNIF_STORAGE_VERSION) {
- TSNIF_DEBUG("failed: wrong storage version %x\n", common->version);
+ TSNIF_DEBUG(STORAGE, "failed: wrong storage version %x\n", common->version);
return -1;
}
if (common->storage_type != TSNIF_STORAGE_TYPE_MMAP) {
- TSNIF_DEBUG("failed: wrong storage type %x\n", common->storage_type);
+ TSNIF_DEBUG(STORAGE, "failed: wrong storage type %x\n", common->storage_type);
return -1;
}
- TSNIF_DEBUG("got terminal type %d\n", common->term_type);
+ TSNIF_DEBUG(STORAGE, "got terminal type %d\n", common->term_type);
return 0;
}
@@ -100,16 +101,16 @@ int tsnif_storage_init(struct tsnif_storage_handle *h,
fd = open(name, flags, mode);
if (fd < 0) {
- TSNIF_DEBUG("open failed for '%s': %s\n",
+ TSNIF_DEBUG(STORAGE, "open failed for '%s': %s\n",
name, strerror(errno));
return -1;
}
- TSNIF_DEBUG("opened '%s'\n", name);
+ TSNIF_DEBUG(STORAGE, "opened '%s'\n", name);
if (create &&
(err = write_header(fd, opts))) {
- TSNIF_DEBUG("write failed for '%s': %s\n",
+ TSNIF_DEBUG(STORAGE, "write failed for '%s': %s\n",
name, strerror(errno));
close(fd);
return err;
@@ -123,7 +124,7 @@ int tsnif_storage_init(struct tsnif_storage_handle *h,
return err;
}
- TSNIF_DEBUG("records count %d\n", h->header->cnt);
+ TSNIF_DEBUG(STORAGE, "records count %d\n", h->header->cnt);
if (opts->flags & TSNIF_STORAGE_OPT_READ) {
struct stat st;
@@ -143,7 +144,7 @@ int tsnif_storage_init(struct tsnif_storage_handle *h,
int tsnif_storage_close(struct tsnif_storage_handle *h)
{
if (h->header) {
- TSNIF_DEBUG("records count %d\n", h->header->cnt);
+ TSNIF_DEBUG(STORAGE, "records count %d\n", h->header->cnt);
munmap(h->header, sysconf(_SC_PAGESIZE));
}
@@ -177,18 +178,18 @@ static int file_trunc(struct tsnif_storage_handle *h, off_t new_size)
{
off_t old_size;
- TSNIF_DEBUG("new size %d\n", new_size);
+ TSNIF_DEBUG(STORAGE, "new size %d\n", new_size);
old_size = lseek(h->fd, 0, SEEK_END);
if (old_size < 0)
return -1;
- TSNIF_DEBUG("old size %d\n", old_size);
+ TSNIF_DEBUG(STORAGE, "old size %d\n", old_size);
if (old_size >= new_size)
return 0;
- TSNIF_DEBUG("truncating to %d\n", new_size);
+ TSNIF_DEBUG(STORAGE, "truncating to %d\n", new_size);
return ftruncate(h->fd, new_size);
}
@@ -201,7 +202,7 @@ static int map_chunk(struct tsnif_storage_handle *h,
int err, flags = PROT_READ;
- TSNIF_DEBUG("what %d\n", what);
+ TSNIF_DEBUG(STORAGE, "what %d\n", what);
if (what == STORAGE_MMAP_FIRST) {
if (h->opts->flags & TSNIF_STORAGE_OPT_READ)
@@ -218,14 +219,14 @@ static int map_chunk(struct tsnif_storage_handle *h,
if (h->opts->flags & TSNIF_STORAGE_OPT_READ) {
- TSNIF_DEBUG("file size 0x%x\n", h->file_size);
- TSNIF_DEBUG("offset 0x%x\n", offset);
+ TSNIF_DEBUG(STORAGE, "file size 0x%x\n", h->file_size);
+ TSNIF_DEBUG(STORAGE, "offset 0x%x\n", offset);
if (h->file_size == offset)
offset = sysconf(_SC_PAGESIZE);
- TSNIF_DEBUG("offset 0x%x\n", offset);
- TSNIF_DEBUG("start offset 0x%x\n", h->header->offset_start);
+ TSNIF_DEBUG(STORAGE, "offset 0x%x\n", offset);
+ TSNIF_DEBUG(STORAGE, "start offset 0x%x\n", h->header->offset_start);
if (h->header->offset_start == offset)
return TSNIF_STORAGE_READ_EOF;
@@ -235,9 +236,9 @@ static int map_chunk(struct tsnif_storage_handle *h,
offset = sysconf(_SC_PAGESIZE);
}
- TSNIF_DEBUG("chunk offset 0x%x\n", chunk->offset);
- TSNIF_DEBUG("chunk size 0x%x\n", chunk->offset);
- TSNIF_DEBUG("max size 0x%x\n", h->opts->size_max);
+ TSNIF_DEBUG(STORAGE, "chunk offset 0x%x\n", chunk->offset);
+ TSNIF_DEBUG(STORAGE, "chunk size 0x%x\n", chunk->offset);
+ TSNIF_DEBUG(STORAGE, "max size 0x%x\n", h->opts->size_max);
}
if (what == STORAGE_MMAP_PREV) {
@@ -250,12 +251,12 @@ static int map_chunk(struct tsnif_storage_handle *h,
else
offset = chunk->offset - h->opts->chunk_size;
- TSNIF_DEBUG("chunk offset 0x%x\n", chunk->offset);
- TSNIF_DEBUG("chunk size 0x%x\n", chunk->offset);
- TSNIF_DEBUG("max size 0x%x\n", h->opts->size_max);
+ TSNIF_DEBUG(STORAGE, "chunk offset 0x%x\n", chunk->offset);
+ TSNIF_DEBUG(STORAGE, "chunk size 0x%x\n", chunk->offset);
+ TSNIF_DEBUG(STORAGE, "max size 0x%x\n", h->opts->size_max);
}
- TSNIF_DEBUG("new offset 0x%x, old offset 0x%x\n",
+ TSNIF_DEBUG(STORAGE, "new offset 0x%x, old offset 0x%x\n",
offset, chunk->offset);
if (chunk->header)
@@ -275,7 +276,7 @@ static int map_chunk(struct tsnif_storage_handle *h,
if (MAP_FAILED == ptr)
return -1;
- TSNIF_DEBUG("mmap-ed offset %ld, size %d\n",
+ TSNIF_DEBUG(STORAGE, "mmap-ed offset %ld, size %d\n",
offset, h->opts->chunk_size);
chunk->offset = offset;
@@ -299,11 +300,11 @@ static int clear_chunk(struct tsnif_storage_handle *h,
chunk->current_index = (void*) (header) + h->opts->chunk_size
- sizeof(uint32_t);
- TSNIF_DEBUG("chunk header %p\n", chunk->header);
- TSNIF_DEBUG("chunk data %p\n", chunk->current_data);
- TSNIF_DEBUG("chunk index %p\n", chunk->current_index);
- TSNIF_DEBUG("chunk size 0x%x\n", h->opts->chunk_size);
- TSNIF_DEBUG("chunk free %d\n", header->free);
+ TSNIF_DEBUG(STORAGE, "chunk header %p\n", chunk->header);
+ TSNIF_DEBUG(STORAGE, "chunk data %p\n", chunk->current_data);
+ TSNIF_DEBUG(STORAGE, "chunk index %p\n", chunk->current_index);
+ TSNIF_DEBUG(STORAGE, "chunk size 0x%x\n", h->opts->chunk_size);
+ TSNIF_DEBUG(STORAGE, "chunk free %d\n", header->free);
return 0;
}
@@ -333,7 +334,7 @@ static int get_chunk_write_rec(struct tsnif_storage_handle *h, int size)
struct tsnif_storage_chunk *chunk = &h->active_chunk;
struct tsnif_storage_chunk_header *chunk_header = chunk->header;
- TSNIF_DEBUG("chunk header %p\n", chunk_header);
+ TSNIF_DEBUG(STORAGE, "chunk header %p\n", chunk_header);
/* first time */
if (!chunk_header)
@@ -357,14 +358,14 @@ static int get_chunk_read_rec(struct tsnif_storage_handle *h, int what)
struct tsnif_storage_chunk_header *chunk_header = chunk->header;
int map_what = 0;
- TSNIF_DEBUG("chunk header %p\n", chunk_header);
+ TSNIF_DEBUG(STORAGE, "chunk header %p\n", chunk_header);
/* first time */
if (!chunk_header)
return map_read_chunk(h, chunk, STORAGE_MMAP_FIRST);
- TSNIF_DEBUG("chunk cnt 0x%x\n", chunk_header->cnt);
- TSNIF_DEBUG("read index 0x%x\n", chunk->read_index);
+ TSNIF_DEBUG(STORAGE, "chunk cnt 0x%x\n", chunk_header->cnt);
+ TSNIF_DEBUG(STORAGE, "read index 0x%x\n", chunk->read_index);
/* we want next record and we have it */
if (TSNIF_STORAGE_READ_NEXT == what) {
@@ -390,9 +391,9 @@ static int store_rec(struct tsnif_storage_handle *h,
struct tsnif_storage_chunk *chunk = &h->active_chunk;
struct tsnif_storage_chunk_header *header = chunk->header;
- TSNIF_DEBUG("chunk data %p\n", chunk->current_data);
- TSNIF_DEBUG("chunk index %p\n", chunk->current_index);
- TSNIF_DEBUG("time %ld\n", rec->time.tv_sec);
+ TSNIF_DEBUG(STORAGE, "chunk data %p\n", chunk->current_data);
+ TSNIF_DEBUG(STORAGE, "chunk index %p\n", chunk->current_index);
+ TSNIF_DEBUG(STORAGE, "time %ld\n", rec->time.tv_sec);
mrec = chunk->current_data;
mrec->len = rec->len;
@@ -404,8 +405,8 @@ static int store_rec(struct tsnif_storage_handle *h,
#define RECLEN (sizeof(struct tsnif_storage_rec_mmap) + rec->len)
*(chunk->current_index) = (void*) chunk->current_data - (void*) header;
- TSNIF_DEBUG("rec offset 0x%x\n", *(chunk->current_index));
- TSNIF_DEBUG("rec size 0x%x\n", rec->len);
+ TSNIF_DEBUG(STORAGE, "rec offset 0x%x\n", *(chunk->current_index));
+ TSNIF_DEBUG(STORAGE, "rec size 0x%x\n", rec->len);
chunk->current_index--;
chunk->current_data += RECLEN;
@@ -417,10 +418,10 @@ static int store_rec(struct tsnif_storage_handle *h,
header->cnt++;
header->free -= (sizeof(uint32_t) + RECLEN);
- TSNIF_DEBUG("chunk data %p\n", chunk->current_data);
- TSNIF_DEBUG("chunk index %p\n", chunk->current_index);
- TSNIF_DEBUG("chunk free %d\n", header->free);
- TSNIF_DEBUG("chunk cnt %d\n", header->cnt);
+ TSNIF_DEBUG(STORAGE, "chunk data %p\n", chunk->current_data);
+ TSNIF_DEBUG(STORAGE, "chunk index %p\n", chunk->current_index);
+ TSNIF_DEBUG(STORAGE, "chunk free %d\n", header->free);
+ TSNIF_DEBUG(STORAGE, "chunk cnt %d\n", header->cnt);
return 0;
}
@@ -432,9 +433,9 @@ static int read_rec(struct tsnif_storage_handle *h,
struct tsnif_storage_chunk_header *header = chunk->header;
off_t offset;
- TSNIF_DEBUG("chunk data %p\n", chunk->current_data);
- TSNIF_DEBUG("chunk index %p\n", chunk->current_index);
- TSNIF_DEBUG("read index 0x%x\n", chunk->read_index);
+ TSNIF_DEBUG(STORAGE, "chunk data %p\n", chunk->current_data);
+ TSNIF_DEBUG(STORAGE, "chunk index %p\n", chunk->current_index);
+ TSNIF_DEBUG(STORAGE, "read index 0x%x\n", chunk->read_index);
/* the chunk got loaded just now */
if (chunk->read_index == -1) {
@@ -466,7 +467,7 @@ int tsnif_storage_write(struct tsnif_storage_handle *h,
{
int err;
- TSNIF_DEBUG("entry\n");
+ TSNIF_DEBUG(STORAGE, "entry\n");
err = get_chunk_write_rec(h, rec->len);
if (err)
@@ -480,7 +481,7 @@ int tsnif_storage_read(struct tsnif_storage_handle *h, int what,
{
int err;
- TSNIF_DEBUG("entry\n");
+ TSNIF_DEBUG(STORAGE, "entry\n");
err = get_chunk_read_rec(h, what);
if (err)
diff --git a/src/test.c b/src/test.c
index 25a0866..755c1ac 100644
--- a/src/test.c
+++ b/src/test.c
@@ -3,6 +3,8 @@
#include <unistd.h>
#include <getopt.h>
+#include "debug.h"
+
#define TEST_RUN(test) \
do { \
printf("RUNNING " # test "\n"); \
@@ -12,7 +14,6 @@ do { \
} \
} while(0)
-int tsnif_debug = 0;
int assert_debug = 0;
static void usage()
diff --git a/src/test.h b/src/test.h
index 18e8807..443328d 100644
--- a/src/test.h
+++ b/src/test.h
@@ -4,6 +4,7 @@
#include <stdio.h>
#include "intf.h"
+#include "debug.h"
extern int assert_debug;
diff --git a/src/trans-libnl.c b/src/trans-libnl.c
index 61428ca..c623375 100644
--- a/src/trans-libnl.c
+++ b/src/trans-libnl.c
@@ -8,6 +8,7 @@
#include "intf.h"
#include "trans.h"
+#include "debug.h"
#ifndef SOL_NETLINK
#define SOL_NETLINK 270
@@ -64,7 +65,7 @@ static int process_cb(struct trans_handle *h, struct trans_msg *m,
m->cmd = ghdr->cmd;
- TSNIF_DEBUG("got cmd %d, type %d, idx %d, "
+ TSNIF_DEBUG(TRANS, "got cmd %d, type %d, idx %d, "
"ack %d, err %d\n",
m->cmd, m->type, m->idx,
m->ack, m->err);
@@ -85,7 +86,7 @@ static int err_cb(struct sockaddr_nl *nla, struct nlmsgerr *nlerr, void *arg)
m.error = nlerr->error;
}
- TSNIF_DEBUG("got error cb - ack %d, err %d, error %d\n",
+ TSNIF_DEBUG(TRANS, "got error cb - ack %d, err %d, error %d\n",
m.ack, m.err, m.error);
return process_cb(arg, &m, &nlerr->msg);
@@ -95,7 +96,7 @@ static int parse_cb(struct nl_msg *msg, void *arg)
{
struct trans_msg m;
- TSNIF_DEBUG("got parse cb\n");
+ TSNIF_DEBUG(TRANS, "got parse cb\n");
memset(&m, 0x0, sizeof(m));
@@ -127,13 +128,13 @@ int trans_init(struct trans_handle *h, trans_cb_t cb)
if (err)
return err;
- TSNIF_DEBUG("connected\n");
+ TSNIF_DEBUG(TRANS, "connected\n");
family = genl_ctrl_resolve(sock, "tsnif");
if (family < 0)
return family;
- TSNIF_DEBUG("tsnif module found\n");
+ TSNIF_DEBUG(TRANS, "tsnif module found\n");
nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, parse_cb, h);
@@ -146,7 +147,7 @@ int trans_init(struct trans_handle *h, trans_cb_t cb)
err = set_no_enobufs(h);
if (err)
- TSNIF_DEBUG("failed to set ENOBUFS, moving on...\n");
+ TSNIF_DEBUG(TRANS, "failed to set ENOBUFS, moving on...\n");
return 0;
}
@@ -163,7 +164,7 @@ int trans_process(struct trans_handle *h)
err = nl_recvmsgs_default(h->sock);
if (err)
- TSNIF_DEBUG("got error: %s\n", nl_geterror());
+ TSNIF_DEBUG(TRANS, "got error: %s\n", nl_geterror());
return err;
}
@@ -173,7 +174,7 @@ int trans_send(struct trans_handle *h, struct trans_msg *m)
struct nl_msg *msg;
int err;
- TSNIF_DEBUG("sending cmd = %d\n", m->cmd);
+ TSNIF_DEBUG(TRANS, "sending cmd = %d\n", m->cmd);
if ((m->cmd != TSNIF_CMD_ATTACH) &&
(m->cmd != TSNIF_CMD_DETACH) &&
@@ -196,7 +197,7 @@ int trans_send(struct trans_handle *h, struct trans_msg *m)
err = nl_send_auto_complete(h->sock, msg);
nlmsg_free(msg);
- TSNIF_DEBUG("sent result %d\n", err);
+ TSNIF_DEBUG(TRANS, "sent result %d\n", err);
return err > 0 ? 0 : err;
}
diff --git a/src/tsnif-replay.c b/src/tsnif-replay.c
index 2e4700a..bac2b98 100644
--- a/src/tsnif-replay.c
+++ b/src/tsnif-replay.c
@@ -11,6 +11,7 @@
#include "storage.h"
#include "misc.h"
#include "intf.h"
+#include "debug.h"
static int killed;
static char *filename;
@@ -19,8 +20,6 @@ static struct tsnif_storage_opts storage_opts = {
.flags = TSNIF_STORAGE_OPT_READ,
};
-int tsnif_debug = 0;
-
static void usage()
{
printf("tsnif-replay -f <file>\n");
@@ -79,8 +78,8 @@ static struct timeval get_timeout(struct timespec *ts_new,
tv.tv_sec = ts_new->tv_sec - ts_old->tv_sec;
- TSNIF_DEBUG("time new %ld:%ld\n", ts_new->tv_sec, ts_new->tv_nsec);
- TSNIF_DEBUG("time old %ld:%ld\n", ts_old->tv_sec, ts_old->tv_nsec);
+ TSNIF_DEBUG(APP, "time new %ld:%ld\n", ts_new->tv_sec, ts_new->tv_nsec);
+ TSNIF_DEBUG(APP, "time old %ld:%ld\n", ts_old->tv_sec, ts_old->tv_nsec);
if (ts_new->tv_nsec >= ts_old->tv_nsec)
tv.tv_usec = (ts_new->tv_nsec - ts_old->tv_nsec) / 1000;
@@ -90,7 +89,7 @@ static struct timeval get_timeout(struct timespec *ts_new,
tv.tv_sec--;
}
- TSNIF_DEBUG("time fin %ld %ld\n", tv.tv_sec, tv.tv_usec);
+ TSNIF_DEBUG(APP, "time fin %ld %ld\n", tv.tv_sec, tv.tv_usec);
return tv;
}
diff --git a/src/tsnif.c b/src/tsnif.c
index 5b2946f..9cba8e0 100644
--- a/src/tsnif.c
+++ b/src/tsnif.c
@@ -12,6 +12,7 @@
#include "intf.h"
#include "storage.h"
#include "misc.h"
+#include "debug.h"
static struct tsnif_handle handle;
static struct tsnif_term term;
diff --git a/src/tsnifd.c b/src/tsnifd.c
index 22b6da5..8a6c8eb 100644
--- a/src/tsnifd.c
+++ b/src/tsnifd.c
@@ -16,10 +16,9 @@
#include "intf.h"
#include "storage.h"
#include "misc.h"
+#include "debug.h"
-extern int tsnif_debug;
-
static struct tsnif_storage_opts init_storage_opts = {
.flags = TSNIF_STORAGE_OPT_WRITE,
.size_max = 1024*1024,
@@ -130,7 +129,7 @@ static int file_put(char *name)
sprintf(p, "%s", ".tsnif");
- TSNIF_DEBUG("putting to %s\n", new);
+ TSNIF_DEBUG(APP, "putting to %s\n", new);
err = rename(name, new);
free(new);
@@ -143,7 +142,7 @@ static int terminal_add(struct tsnif_term *term)
int err;
char *file;
- TSNIF_DEBUG("type %d, idx %d\n", term->type, term->idx);
+ TSNIF_DEBUG(APP, "type %d, idx %d\n", term->type, term->idx);
/* XXX debug gets only PTY XXX */
if (tsnif_debug) {
@@ -170,7 +169,7 @@ static int terminal_add(struct tsnif_term *term)
return -1;
}
- TSNIF_DEBUG("storing to %s\n", file);
+ TSNIF_DEBUG(APP, "storing to %s\n", file);
t->file = strdup(file);
t->storage_opts = init_storage_opts;
@@ -185,7 +184,7 @@ static int terminal_del(struct tsnif_term *term)
{
struct terminal *t;
- TSNIF_DEBUG("type %d, idx %d\n", term->type, term->idx);
+ TSNIF_DEBUG(APP, "type %d, idx %d\n", term->type, term->idx);
tsnif_term_del(&handle, term);