Properly initialize data_size for empty data segment
[blerg.git] / database / database.c
index c8b9b58..52ebe8c 100644 (file)
@@ -57,16 +57,16 @@ int blerg_remap_data(struct blerg *blerg) {
        if (blerg->data != NULL)
                munmap(blerg->data, blerg->data_size);
        fstat(blerg->data_fd, &st);
-       if (st.st_size == 0) {
+       blerg->data_size = st.st_size;
+       if (blerg->data_size == 0) {
                /* Can't map an empty data file. */
                return 1;
        }
-       blerg->data = (char *) mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, blerg->data_fd, 0);
+       blerg->data = (char *) mmap(NULL, blerg->data_size, PROT_READ, MAP_SHARED, blerg->data_fd, 0);
        if (blerg->data == MAP_FAILED) {
                perror("Could not remap data");
                return 0;
        }
-       blerg->data_size = st.st_size;
        return 1;
 }
 
@@ -283,9 +283,11 @@ int blerg_store(struct blerg *blerg, const char *data, int len) {
        flock(blerg->data_fd, LOCK_UN);
        flock(blerg->index_fd, LOCK_UN);
 
-       /* Now do those dirty microblogging deeds */
-       tag_scan(blerg->name, data, len, record);
-       subscription_notify(blerg->name, record);
+       if (!blerg_get_mute(blerg)) {
+               /* Now do those dirty microblogging deeds */
+               tag_scan(blerg->name, data, len, record);
+               subscription_notify(blerg->name, record);
+       }
 
        return record;
 }
@@ -368,3 +370,18 @@ uint64_t blerg_get_subscription_mark(struct blerg *blerg) {
        CHECK_VALID_BLERG(0)
        return blerg->meta->subscription_mark;
 }
+
+int blerg_set_mute(struct blerg *blerg, int v) {
+       CHECK_VALID_BLERG(0)
+       if (v) {
+               blerg->meta->status |= BLERGMETA_MUTED;
+       } else {
+               blerg->meta->status &= ~BLERGMETA_MUTED;
+       }
+       return 1;
+}
+
+int blerg_get_mute(struct blerg *blerg) {
+       CHECK_VALID_BLERG(0)
+       return (blerg->meta->status & BLERGMETA_MUTED) > 0;
+}