Archived
1
0
Fork 0

removed debug.h in favor for log.h

This commit is contained in:
Henrik Hautakoski 2010-11-21 16:38:04 +01:00
parent 8ad0243c31
commit f156e8906c
9 changed files with 28 additions and 74 deletions

View file

@ -19,7 +19,6 @@
#include <time.h>
#include <mongo/mongo.h>
#include <ini/iniparser.h>
#include "../debug.h"
#include "../path.h"
#include "../database.h"

View file

@ -1,41 +0,0 @@
/* debug.h - debugging macros and definitions
*
* Copyright (C) 2010 Henrik Hautakoski <henrik@fiktivkod.org>
*
* 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 <stdio.h>
#include <stdlib.h>
#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 */

View file

@ -9,13 +9,14 @@
*/
#include <unistd.h>
#include <string.h>
#include <malloc.h>
#include <stdio.h>
#include <errno.h>
#include <dirent.h>
#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;
}

View file

@ -10,6 +10,8 @@
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
@ -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];

View file

@ -17,7 +17,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "debug.h"
#include "strbuf.h"
#include "path.h"

View file

@ -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 <malloc.h>
#include <string.h>
#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;

View file

@ -12,7 +12,6 @@
#include <string.h>
#include "xalloc.h"
#include "strbuf.h"
#include "debug.h"
#define CHNK_SIZE 128

View file

@ -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 \

View file

@ -10,7 +10,6 @@
#include <stdlib.h>
#include "unit.h"
#include "../src/rbtree.h"
#include "../src/debug.h"
#define MAX_VAL 500
#define NODES 20