summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2016-04-29 12:45:58 +0200
committerLinus Nordberg <linus@nordu.net>2016-04-29 12:45:58 +0200
commitce461321ef514cc0b21e44e415eb05ad2122036b (patch)
treedd1121fea3b9e5a995b757e06feda2e67bc617e9
parent41dfffcc1572073c3d1d201a0a19dd2c4ca1bb4a (diff)
Turn a bunch of outcommented fprintf's into dprintf's.
Also, rename dprintf 'level' to 'category' and add DEBUG_REBUILD.
-rw-r--r--c_src/permdb.c21
-rw-r--r--c_src/util.h7
2 files changed, 15 insertions, 13 deletions
diff --git a/c_src/permdb.c b/c_src/permdb.c
index 66b9813..2b14d0b 100644
--- a/c_src/permdb.c
+++ b/c_src/permdb.c
@@ -176,7 +176,7 @@ indexfile_add_header(buffered_file *file)
void
datafile_add_header(buffered_file *file)
{
- //fprintf(stderr, "adding header to %s\n", bf_name(file));
+ dprintf(WRITE, (stderr, "adding header to %s\n", bf_name(file)));
bf_add(file, &data_file_cookie, sizeof(data_file_cookie));
bf_add_be32(file, 4096);
bf_add_be32(file, 2);
@@ -206,9 +206,10 @@ struct commit_info {
int
validate_checksum(struct commit_info *commit, buffered_file *file)
{
- /*fprintf(stderr,
- "validate_checksum: read from file: length %llu start %llu\n",
- commit->length, commit->start);*/
+ dprintf(READ,
+ (stderr,
+ "validate_checksum: read from file: length %llu start %llu\n",
+ commit->length, commit->start));
unsigned char *checksumdata = bf_read(file, commit->start,
commit->length, NULL);
@@ -236,7 +237,7 @@ validate_checksum(struct commit_info *commit, buffered_file *file)
int
verify_index_commit(buffered_file *file, node_offset offset)
{
- //fprintf(stderr, "verifying index file: commit verification\n");
+ dprintf(READ, (stderr, "verifying index file: commit verification\n"));
offset -= INDEX_COMMIT_TRAILER_SIZE;
unsigned char *data =
bf_read(file, offset, INDEX_COMMIT_TRAILER_SIZE, NULL);
@@ -260,7 +261,7 @@ verify_index_commit(buffered_file *file, node_offset offset)
int
indexfile_verify_file(buffered_file *file)
{
- //fprintf(stderr, "verifying index file\n");
+ dprintf(READ, (stderr, "verifying index file\n"));
unsigned char *header = bf_read(file, 0, sizeof(index_file_cookie), NULL);
if (memcmp(header, &index_file_cookie, sizeof(index_file_cookie)) != 0) {
free(header);
@@ -292,12 +293,12 @@ datafile_verify_file(buffered_file *file)
node_offset offset = bf_lastcommit(file);
- //fprintf(stderr, "verifying commit: %llu\n", offset);
+ dprintf(READ, (stderr, "verifying commit: %llu\n", offset));
struct commit_info *data_commit =
read_data_commit_backward(file, &offset);
if (data_commit == NULL || validate_checksum(data_commit, file) < 0) {
- //fprintf(stderr, "commit broken: %llu\n", offset);
+ dprintf(READ, (stderr, "commit broken: %llu\n", offset));
free(data_commit);
return -1;
}
@@ -327,8 +328,8 @@ read_data_commit(buffered_file *file, node_offset *offset)
}
*offset += sizeof(uint32_t);
struct commit_info *commit = malloc(sizeof(struct commit_info));
- //fprintf(stderr, "read commit: %llu\n", *offset);
- //print_hex(data, sizeof(uint32_t) + SHA256_DIGEST_SIZE);
+ dprintf(READ, (stderr, "read commit: %llu\n", *offset));
+ dprinthex(READ, data, sizeof(uint32_t) + SHA256_DIGEST_SIZE);
commit->length = read_be32(data);
commit->start = *offset - commit->length;
memcpy(&commit->checksum, data + sizeof(uint32_t), SHA256_DIGEST_SIZE);
diff --git a/c_src/util.h b/c_src/util.h
index f08f2c3..9c2b9d6 100644
--- a/c_src/util.h
+++ b/c_src/util.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, NORDUnet A/S.
+ * Copyright (c) 2016, NORDUnet A/S.
* See LICENSE for licensing information.
*/
@@ -9,10 +9,11 @@
#define DEBUG_CACHE 0
#define DEBUG_WRITE 0
#define DEBUG_READ 0
+#define DEBUG_REBUILD 0
#define DEBUG_PORT 0
-#define dprintf(level,args) do { if (DEBUG_ ## level) { fprintf args; } } while (0)
-#define dprinthex(level,data,size) do { if (DEBUG_ ## level) { print_hex(data, size); } } while (0)
+#define dprintf(category,args) do { if (DEBUG_ ## category) { fprintf args; } } while (0)
+#define dprinthex(category,data,size) do { if (DEBUG_ ## category) { print_hex(data, size); } } while (0)
void
set_error(char **error, const char * __restrict, ...) __attribute__ ((__format__ (__printf__, 2, 3)));