-void *purge_databases(void *args)
-{
- int retval;
- static time_t last_purge = 0;
- time_t now;
- struct tm tm;
-
- 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;
- }
-
-
- lprintf(CTDL_INFO, "Auto-purger: starting.\n");
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeUsers();
- lprintf(CTDL_NOTICE, "Purged %d users.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- PurgeMessages();
- lprintf(CTDL_NOTICE, "Expired %d messages.\n", messages_purged);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeRooms();
- lprintf(CTDL_NOTICE, "Expired %d rooms.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeVisits();
- lprintf(CTDL_NOTICE, "Purged %d visits.\n", retval);
- }
-
- if (!CtdlThreadCheckStop())
- {
- retval = PurgeUseTable();
- lprintf(CTDL_NOTICE, "Purged %d entries from the use table.\n", retval);
- }