- int retval;
- static time_t last_purge = 0;
- time_t now;
- struct tm tm;
- struct CitContext purgerCC;
-
- CtdlLogPrintf(CTDL_DEBUG, "Auto-purger_thread() initializing\n");
-
- CtdlFillSystemContext(&purgerCC, "purger");
- citthread_setspecific(MyConKey, (void *)&purgerCC );
-
- while (!CtdlThreadCheckStop()) {
- /* Do the auto-purge if the current hour equals the purge hour,
- * but not if the operation has already been performed in the
- * last twelve hours. This is usually enough granularity.
- */
- now = time(NULL);
- localtime_r(&now, &tm);
- if (
- ((tm.tm_hour != config.c_purge_hour) || ((now - last_purge) < 43200))
- && (force_purge_now == 0)
- ) {
- CtdlThreadSleep(60);
- continue;
- }
-
-
- CtdlLogPrintf(CTDL_INFO, "Auto-purger: starting.\n");
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeUsers();
- CtdlLogPrintf(CTDL_NOTICE, "Purged %d users.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- PurgeMessages();
- CtdlLogPrintf(CTDL_NOTICE, "Expired %d messages.\n", messages_purged);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeRooms();
- CtdlLogPrintf(CTDL_NOTICE, "Expired %d rooms.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeVisits();
- CtdlLogPrintf(CTDL_NOTICE, "Purged %d visits.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeUseTable();
- CtdlLogPrintf(CTDL_NOTICE, "Purged %d entries from the use table.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeEuidIndexTable();
- CtdlLogPrintf(CTDL_NOTICE, "Purged %d entries from the EUID index.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeStaleOpenIDassociations();
- CtdlLogPrintf(CTDL_NOTICE, "Purged %d stale OpenID associations.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = TDAP_ProcessAdjRefCountQueue();
- CtdlLogPrintf(CTDL_NOTICE, "Processed %d message reference count adjustments.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- CtdlLogPrintf(CTDL_INFO, "Auto-purger: finished.\n");
- last_purge = now; /* So we don't do it again soon */
- force_purge_now = 0;
- }
- else
- CtdlLogPrintf(CTDL_INFO, "Auto-purger: STOPPED.\n");
-
- }
- return NULL;
-}
-/*****************************************************************************/
-
-
-/* The FSCK command has been removed because people were misusing it */
-
-#if 0
-
-void do_fsck_msg(long msgnum, void *userdata) {
- struct ctdlroomref *ptr;
-
- ptr = (struct ctdlroomref *)malloc(sizeof(struct ctdlroomref));
- ptr->next = rr;
- ptr->msgnum = msgnum;
- rr = ptr;
-}
-
-void do_fsck_room(struct ctdlroom *qrbuf, void *data)
-{
- getroom(&CC->room, qrbuf->QRname);
- CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, do_fsck_msg, NULL);
-}
-
-/*
- * Check message reference counts
- */
-void cmd_fsck(char *argbuf) {
- long msgnum;
- struct cdbdata *cdbmsg;
- struct MetaData smi;
- struct ctdlroomref *ptr;
- int realcount;
-
- if (CtdlAccessCheck(ac_aide)) return;