X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fdatabase.c;h=3bab5776d90ebe522eefb34b1c751f631de98ca1;hb=42147eb1950e0c616b070a8676603b551b1d9c58;hp=3d922e11ed8375d8499fe9f1c32f4e60ee9c2ff0;hpb=f82010fd22ed343c28b9c9ddbd00d288152fa3fd;p=citadel.git diff --git a/citadel/database.c b/citadel/database.c index 3d922e11e..3bab5776d 100644 --- a/citadel/database.c +++ b/citadel/database.c @@ -89,6 +89,7 @@ void cdb_verbose_log(const DB_ENV *dbenv, const char *msg) { if (!IsEmptyStr(msg)) { syslog(LOG_DEBUG, "DB: %s", msg); + cit_backtrace(); } } @@ -97,6 +98,7 @@ void cdb_verbose_log(const DB_ENV *dbenv, const char *msg) void cdb_verbose_err(const DB_ENV *dbenv, const char *errpfx, const char *msg) { syslog(LOG_ALERT, "DB: %s", msg); + cit_backtrace(); } @@ -142,6 +144,7 @@ static void txbegin(DB_TXN ** tid) static void dbpanic(DB_ENV * env, int errval) { syslog(LOG_EMERG, "bdb(): PANIC: %s", db_strerror(errval)); + cit_backtrace(); } static void cclose(DBC * cursor) @@ -222,7 +225,7 @@ static void cdb_cull_logs(void) void cmd_cull(char *argbuf) { if (CtdlAccessCheck(ac_internal)) return; cdb_cull_logs(); - cprintf("%d Database log file cull completed.", CIT_OK); + cprintf("%d Database log file cull completed.\n", CIT_OK); } @@ -396,7 +399,7 @@ void open_databases(void) if (ret) { syslog(LOG_EMERG, "db_open[%02x]: %s\n", i, db_strerror(ret)); if (ret == ENOMEM) { - syslog(LOG_EMERG, "You may need to tune your database; please read http://www.citadel.org/doku.php/faq:troubleshooting:out_of_lock_entries for more information.\n"); + syslog(LOG_EMERG, "You may need to tune your database; please read http://www.citadel.org/doku.php?id=faq:troubleshooting:out_of_lock_entries for more information."); } syslog(LOG_EMERG, "exit code %d\n", ret); exit(CTDLEXIT_DB); @@ -542,7 +545,9 @@ int cdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen) memset(&dkey, 0, sizeof(DBT)); memset(&ddata, 0, sizeof(DBT)); dkey.size = ckeylen; + /* no, we don't care for this error. */ dkey.data = ckey; + ddata.size = cdatalen; ddata.data = cdata; @@ -682,13 +687,13 @@ static DBC *localcursor(int cdb) */ struct cdbdata *cdb_fetch(int cdb, const void *key, int keylen) { - struct cdbdata *tempcdb; DBT dkey, dret; int ret; memset(&dkey, 0, sizeof(DBT)); dkey.size = keylen; + /* no we don't care about this error. */ dkey.data = key; if (TSD->tid != NULL) { @@ -723,12 +728,15 @@ struct cdbdata *cdb_fetch(int cdb, const void *key, int keylen) if (tempcdb == NULL) { syslog(LOG_EMERG, "cdb_fetch: Cannot allocate memory for tempcdb\n"); cdb_abort(); + return NULL; /* make it easier for static analysis... */ + } + else + { + tempcdb->len = dret.size; + tempcdb->ptr = dret.data; + cdb_decompress_if_necessary(tempcdb); + return (tempcdb); } - - tempcdb->len = dret.size; - tempcdb->ptr = dret.data; - cdb_decompress_if_necessary(tempcdb); - return (tempcdb); } @@ -768,7 +776,7 @@ void cdb_rewind(int cdb) if (TSD->cursors[cdb] != NULL) { syslog(LOG_EMERG, - "cdb_rewind: must close cursor on database %d before reopening.\n", cdb); + "cdb_rewind: must close cursor on database %d before reopening.\n", cdb); cdb_abort(); /* cclose(TSD->cursors[cdb]); */ } @@ -889,7 +897,7 @@ void cdb_trunc(int cdb) } else { syslog(LOG_EMERG, "cdb_truncate(%d): %s\n", cdb, db_strerror(ret)); if (ret == ENOMEM) { - syslog(LOG_EMERG, "You may need to tune your database; please read http://www.citadel.org/doku.php/faq:troubleshooting:out_of_lock_entries for more information."); + syslog(LOG_EMERG, "You may need to tune your database; please read http://www.citadel.org/doku.php?id=faq:troubleshooting:out_of_lock_entries for more information."); } exit(CTDLEXIT_DB); } @@ -898,3 +906,84 @@ void cdb_trunc(int cdb) } } } + +int SeentDebugEnabled = 0; + +#define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (SeentDebugEnabled != 0)) +#define SEENM_syslog(LEVEL, FORMAT) \ + DBGLOG(LEVEL) syslog(LEVEL, \ + "IO[%ld]CC[%ld] SEEN[%s][%d] " FORMAT, \ + ioid, ccid, Facility, cType) + +time_t CheckIfAlreadySeen(const char *Facility, + StrBuf *guid, + time_t now, + time_t antiexpire, + eCheckType cType, + long ccid, + long ioid) +{ + struct UseTable ut; + struct cdbdata *cdbut; + + if (cType != eWrite) + { + time_t InDBTimeStamp = 0; + SEENM_syslog(LOG_DEBUG, "Loading"); + cdbut = cdb_fetch(CDB_USETABLE, SKEY(guid)); + if (cdbut != NULL) { + memcpy(&ut, cdbut->ptr, + ((cdbut->len > sizeof(struct UseTable)) ? + sizeof(struct UseTable) : cdbut->len)); + + if (ut.ut_timestamp > antiexpire) + { + SEENM_syslog(LOG_DEBUG, "Found - Not expired."); + cdb_free(cdbut); + return ut.ut_timestamp; + } + else + { + SEENM_syslog(LOG_DEBUG, "Found - Expired."); + InDBTimeStamp = ut.ut_timestamp; + cdb_free(cdbut); + } + } + else + { + SEENM_syslog(LOG_DEBUG, "not Found"); + } + + if (cType == eCheckExist) + return InDBTimeStamp; + } + + memcpy(ut.ut_msgid, SKEY(guid)); + ut.ut_timestamp = now; + + SEENM_syslog(LOG_DEBUG, "Saving"); + /* rewrite the record anyway, to update the timestamp */ + cdb_store(CDB_USETABLE, + SKEY(guid), + &ut, sizeof(struct UseTable) ); + + SEENM_syslog(LOG_DEBUG, "Done Saving"); + return 0; +} + + +void LogDebugEnableSeenEnable(const int n) +{ + SeentDebugEnabled = n; +} + +CTDL_MODULE_INIT(database) +{ + if (!threading) + { + CtdlRegisterDebugFlagHook(HKEY("SeenDebug"), LogDebugEnableSeenEnable, &SeentDebugEnabled); + } + + /* return our module id for the log */ + return "database"; +}