From f156e8906c981da99d3429793f26bc349eed8888 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sun, 21 Nov 2010 16:38:04 +0100 Subject: [PATCH] removed debug.h in favor for log.h --- src/database/mongo.c | 1 - src/debug.h | 41 ----------------------------------------- src/fscrawl.c | 15 +++++++-------- src/inotify.c | 34 ++++++++++++++++------------------ src/path.c | 1 - src/rbtree.c | 4 +--- src/strbuf.c | 1 - test/Makefile | 4 ++++ test/t_rbtree.c | 1 - 9 files changed, 28 insertions(+), 74 deletions(-) delete mode 100644 src/debug.h diff --git a/src/database/mongo.c b/src/database/mongo.c index 100bec6..60c14b7 100644 --- a/src/database/mongo.c +++ b/src/database/mongo.c @@ -19,7 +19,6 @@ #include #include #include -#include "../debug.h" #include "../path.h" #include "../database.h" diff --git a/src/debug.h b/src/debug.h deleted file mode 100644 index d4e53aa..0000000 --- a/src/debug.h +++ /dev/null @@ -1,41 +0,0 @@ -/* debug.h - debugging macros and definitions - * - * Copyright (C) 2010 Henrik Hautakoski - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - */ - -#ifndef __DEBUG_H -#define __DEBUG_H - -#include -#include - -#include "util.h" - -#define __perror(...) fprintf(stderr, __VA_ARGS__) - -#ifdef __DEBUG__ - -#define __str(x) #x - -#define dassert(expr) \ - ((expr) ? \ - (void) 0 : \ - __perror("ASSERT: \"" #expr "\" at %s:%i\n", __FILE__, __LINE__)) - -#define dprint(...) \ - __dprint(__FILE__, __LINE__, __VA_ARGS__) - -#define __dprint(file, line, ...) \ - __perror("# " file ":" __str(line) " -> " __VA_ARGS__) - -#else -#define dassert(expr) -#define dprint(...) -#endif /* __DEBUG__ */ - -#endif /* __DEBUG_H */ diff --git a/src/fscrawl.c b/src/fscrawl.c index e84971e..d133710 100644 --- a/src/fscrawl.c +++ b/src/fscrawl.c @@ -9,13 +9,14 @@ */ #include #include +#include #include #include #include +#include "log.h" #include "strbuf.h" #include "path.h" -#include "debug.h" #include "fscrawl.h" #define MAX_DEPTH 0x20 @@ -32,16 +33,14 @@ struct __fscrawl { static int mvup(struct __fscrawl *f) { if (closedir(f->dirs[f->depth]) == -1) { - perror("closedir"); + logerrno(LOG_WARN, "ftc: closedir", errno); errno = 0; return -1; } if (f->depth == 0) return 0; - - dprint("fscrawl: tree depth is: %i \n", f->depth); - + f->depth--; if (f->path.buf[f->path.len-1] == '/') @@ -67,7 +66,7 @@ static int mvdown(struct __fscrawl *f, const char *dir) { if (!ds) { if (errno != EACCES) - perror("opendir"); + logerrno(LOG_WARN, "ftc: opendir", errno); errno = 0; strbuf_reduce(&f->path, 1); @@ -104,7 +103,7 @@ fscrawl_t fsc_open(const char *path) { if (!f->dirs[f->depth]) { - perror("fsc_open"); + logerrno(LOG_WARN, "fsc_open", errno); errno = 0; strbuf_free(&f->path); @@ -164,7 +163,7 @@ fs_entry* fsc_read(fscrawl_t f) { if (errno) { if (errno != EACCES) - perror("fsc_read"); + logerrno(LOG_WARN, "fsc_read", errno); continue; } diff --git a/src/inotify.c b/src/inotify.c index 89ded8f..659ad8d 100644 --- a/src/inotify.c +++ b/src/inotify.c @@ -10,6 +10,8 @@ */ #include +#include +#include #include #include #include @@ -19,7 +21,7 @@ #include "util.h" /* red black tree for watch descriptors */ #include "rbtree.h" -#include "debug.h" +#include "log.h" #include "path.h" #include "queue.h" #include "fscrawl.h" @@ -60,7 +62,7 @@ static int addwatch(const char *path, const char *name, unsigned recursive) { rbtree_insert(&tree, wd, npath); - dprint("added wd = %i on %s\n", wd, npath); + logmsg(LOG_DEBUG, "added wd = %i on %s", wd, npath); if (recursive) { fscrawl_t f = fsc_open(npath); @@ -105,13 +107,13 @@ static int rmwatch(const char *path, const char *name) { node = rbtree_cmp_search(&tree, fpath); if (node == NULL) { - dprint("remove watch: can't find %s\n", fpath); + logmsg(LOG_DEBUG, "remove watch: can't find %s", fpath); free(fpath); return -1; } free(fpath); - dprint("remove watch: %i %s\n", node->key, (char*) node->data); + logmsg(LOG_DEBUG, "remove watch: %i %s", node->key, (char*) node->data); return inotify_rm_watch(fd, node->key); } @@ -122,13 +124,7 @@ static void proc_event(inoev *iev) { notify_event *event; uint8_t type = NOTIFY_UNKNOWN; -#ifdef __DEBUG__ - fprintf(stderr, "RAW EVENT: %i, %x", iev->wd, iev->mask); - if (iev->len) - fprintf(stderr, ", %s\n", iev->name); - else - fprintf(stderr, "\n"); -#endif + logmsg(LOG_DEBUG, "RAW EVENT: %i, %x, %s", iev->wd, iev->mask, iev->name); /* this event is triggered when a watch descriptor is removed. so we can do a binary search instead of useing the IN_DELETE @@ -142,7 +138,7 @@ static void proc_event(inoev *iev) { node = rbtree_search(&tree, iev->wd); if (!node) { - dprint("-- IGNORING EVENT -- invalid watchdescriptor %i\n", iev->wd); + logmsg(LOG_WARN, "-- IGNORING EVENT -- invalid watchdescriptor %i", iev->wd); return; } @@ -165,14 +161,14 @@ static void proc_event(inoev *iev) { switch(iev->mask) { case IN_CREATE : if (event->dir) { - dprint("IN_CREATE on directory, adding\n"); + logmsg(LOG_DEBUG, "IN_CREATE on directory, adding"); addwatch(event->path, event->filename, 0); } type = NOTIFY_CREATE; break; case IN_MOVED_TO : if (event->dir) { - dprint("IN_MOVED_TO on directory, adding\n"); + logmsg(LOG_DEBUG, "IN_MOVED_TO on directory, adding"); addwatch(event->path, event->filename, 1); } type = NOTIFY_CREATE; @@ -280,13 +276,15 @@ notify_event* notify_read() { while(ioready > 0) { - dprint("%i bytes avail\n", ioready); - char buf[INOBUFSIZE]; int offset = 0, rbytes = read(fd, buf, INOBUFSIZE); - if (rbytes == -1) - die_errno("INOTIFY"); + logmsg(LOG_DEBUG, "%i bytes avail", ioready); + + if (rbytes == -1) { + logerrno(LOG_WARN, "INOTIFY", errno); + break; + } while(rbytes > offset) { inoev *rev = (inoev *) &buf[offset]; diff --git a/src/path.c b/src/path.c index 5052516..36bac2c 100644 --- a/src/path.c +++ b/src/path.c @@ -17,7 +17,6 @@ #include #include -#include "debug.h" #include "strbuf.h" #include "path.h" diff --git a/src/rbtree.c b/src/rbtree.c index ba2f415..ed8eb11 100644 --- a/src/rbtree.c +++ b/src/rbtree.c @@ -10,9 +10,9 @@ * Based on the work of Julienne Walker's rbtree implementation * http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_rbtree.aspx */ +#include #include #include "xalloc.h" -#include "debug.h" #include "rbtree.h" #define is_red(n) ((n) != NULL && (n)->color == RB_RED) @@ -114,8 +114,6 @@ rbnode* rbtree_search(rbtree *tree, unsigned key) { while(n) { - dprint("SEARCH: check %u\n", n->key); - if (n->key == key) break; diff --git a/src/strbuf.c b/src/strbuf.c index 483744b..c098563 100644 --- a/src/strbuf.c +++ b/src/strbuf.c @@ -12,7 +12,6 @@ #include #include "xalloc.h" #include "strbuf.h" -#include "debug.h" #define CHNK_SIZE 128 diff --git a/test/Makefile b/test/Makefile index c25c453..9fabdd1 100644 --- a/test/Makefile +++ b/test/Makefile @@ -35,6 +35,8 @@ rbtree : inotify : $(CC) -lpthread -D INOTIFY_DEBUG -D RB_DEBUG $(CFLAGS) \ ../src/rbtree.c \ + ../src/log.c \ + ../src/log-file.c \ ../src/xalloc.c \ ../src/die.c \ ../src/strbuf.c \ @@ -49,6 +51,8 @@ fscrawl : $(CC) $(CFLAGS) \ ../src/path.c \ ../src/fscrawl.c \ + ../src/log.c \ + ../src/log-file.c \ ../src/xalloc.c \ ../src/die.c \ ../src/strbuf.c \ diff --git a/test/t_rbtree.c b/test/t_rbtree.c index 2e98351..90eb3ec 100644 --- a/test/t_rbtree.c +++ b/test/t_rbtree.c @@ -10,7 +10,6 @@ #include #include "unit.h" #include "../src/rbtree.h" -#include "../src/debug.h" #define MAX_VAL 500 #define NODES 20