]> code.citadel.org Git - citadel.git/blobdiff - citadel/database_sleepycat.c
calculate the directories in a central manner.
[citadel.git] / citadel / database_sleepycat.c
index 1e4251bb726dd2dcc9e176dfdcab6e44858a932a..529c64cb3a6624ee06694f909cf93307039c52b3 100644 (file)
 
 /*****************************************************************************/
 
-#ifdef DLL_EXPORT
-#define IN_LIBCIT
-#endif
-
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
@@ -255,6 +251,15 @@ static void cdb_cull_logs(void)
        }
 }
 
+/*
+ * Manually initiate log file cull.
+ */
+void cmd_cull(char *argbuf) {
+       if (CtdlAccessCheck(ac_internal)) return;
+       cdb_cull_logs();
+       cprintf("%d Database log file cull completed.\n", CIT_OK);
+}
+
 
 /*
  * Request a checkpoint of the database.
@@ -282,7 +287,9 @@ static void cdb_checkpoint(void)
        }
 
        /* After a successful checkpoint, we can cull the unused logs */
-       cdb_cull_logs();
+       if (config.c_auto_cull) {
+               cdb_cull_logs();
+       }
 }
 
 
@@ -327,9 +334,7 @@ void open_databases(void)
        struct dirent *d;
        char filename[PATH_MAX];
 
-
-       getcwd(dbdirname, sizeof dbdirname);
-       strcat(dbdirname, "/data");
+       strcat(dbdirname,ctdl_data_dir);
 
        lprintf(CTDL_DEBUG, "cdb_*: open_databases() starting\n");
        lprintf(CTDL_DEBUG, "Compiled db: %s\n", DB_VERSION_STRING);
@@ -447,6 +452,8 @@ void open_databases(void)
        }
 
        lprintf(CTDL_DEBUG, "cdb_*: open_databases() finished\n");
+
+       CtdlRegisterProtoHook(cmd_cull, "CULL", "Cull database logs");
 }
 
 
@@ -762,12 +769,18 @@ struct cdbdata *cdb_fetch(int cdb, void *key, int keylen)
 
 
 /*
- * Free a cdbdata item (ok, this is really no big deal, but we might need to do
- * more complex stuff with other database managers in the future).
+ * Free a cdbdata item.
+ *
+ * Note that we only free the 'ptr' portion if it is not NULL.  This allows
+ * other code to assume ownership of that memory simply by storing the
+ * pointer elsewhere and then setting 'ptr' to NULL.  cdb_free() will then
+ * avoid freeing it.
  */
 void cdb_free(struct cdbdata *cdb)
 {
-       free(cdb->ptr);
+       if (cdb->ptr) {
+               free(cdb->ptr);
+       }
        free(cdb);
 }