-void *purge_databases(void *args)
-{
- 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");
-
- memset(&purgerCC, 0, sizeof(struct CitContext));
- purgerCC.internal_pgm = 1;
- purgerCC.cs_pid = 0;
- pthread_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)) {
- 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);
- }