#include <sys/wait.h>
#include <string.h>
#include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
#include "citadel.h"
#include "server.h"
#include <syslog.h>
long vu_usernum;
};
+
+struct roomref {
+ struct roomref *next;
+ long msgnum;
+};
+
+
struct PurgeList *UserPurgeList = NULL;
struct PurgeList *RoomPurgeList = NULL;
struct ValidRoom *ValidRoomList = NULL;
struct ValidUser *ValidUserList = NULL;
int messages_purged;
+struct roomref *rr = NULL;
+
extern struct CitContext *ContextList;
-void DoPurgeMessages(struct quickroom *qrbuf) {
+void DoPurgeMessages(struct quickroom *qrbuf, void *data) {
struct ExpirePolicy epbuf;
long delnum;
time_t xtime, now;
void PurgeMessages(void) {
lprintf(5, "PurgeMessages() called\n");
messages_purged = 0;
- ForEachRoom(DoPurgeMessages);
+ ForEachRoom(DoPurgeMessages, NULL);
}
-void AddValidUser(struct usersupp *usbuf) {
+void AddValidUser(struct usersupp *usbuf, void *data) {
struct ValidUser *vuptr;
vuptr = (struct ValidUser *)mallok(sizeof(struct ValidUser));
ValidUserList = vuptr;
}
-void AddValidRoom(struct quickroom *qrbuf) {
+void AddValidRoom(struct quickroom *qrbuf, void *data) {
struct ValidRoom *vrptr;
vrptr = (struct ValidRoom *)mallok(sizeof(struct ValidRoom));
ValidRoomList = vrptr;
}
-void DoPurgeRooms(struct quickroom *qrbuf) {
+void DoPurgeRooms(struct quickroom *qrbuf, void *data) {
time_t age, purge_secs;
struct PurgeList *pptr;
struct ValidUser *vuptr;
if (qrbuf->QRflags & QR_PERMANENT) return;
if (qrbuf->QRflags & QR_DIRECTORY) return;
if (qrbuf->QRflags & QR_NETWORK) return;
+ if (!strcasecmp(qrbuf->QRname, SYSCONFIGROOM)) return;
if (is_noneditable(qrbuf)) return;
/* If we don't know the modification date, be safe and don't purge */
/* Load up a table full of valid user numbers so we can delete
* user-owned rooms for users who no longer exist */
- ForEachUser(AddValidUser);
+ ForEachUser(AddValidUser, NULL);
/* Then cycle through the room file */
- ForEachRoom(DoPurgeRooms);
+ ForEachRoom(DoPurgeRooms, NULL);
/* Free the valid user list */
while (ValidUserList != NULL) {
}
-void do_user_purge(struct usersupp *us) {
+void do_user_purge(struct usersupp *us, void *data) {
int purge;
time_t now;
time_t purge_time;
lprintf(5, "PurgeUsers() called\n");
if (config.c_userpurge > 0) {
- ForEachUser(do_user_purge);
+ ForEachUser(do_user_purge, NULL);
}
transcript = mallok(256);
int RoomIsValid, UserIsValid;
/* First, load up a table full of valid room/gen combinations */
- ForEachRoom(AddValidRoom);
+ ForEachRoom(AddValidRoom, NULL);
/* Then load up a table full of valid user numbers */
- ForEachUser(AddValidUser);
+ ForEachUser(AddValidUser, NULL);
/* Now traverse through the visits, purging irrelevant records... */
cdb_rewind(CDB_VISIT);
char cmd[256];
int retval;
-
- if ((!(CC->logged_in))&&(!(CC->internal_pgm))) {
- cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
- return;
- }
-
- if ((!is_room_aide()) && (!(CC->internal_pgm)) ) {
- cprintf("%d Higher access required.\n",
- ERROR+HIGHER_ACCESS_REQUIRED);
- return;
- }
+ if (CtdlAccessCheck(ac_aide)) return;
extract(cmd, argbuf, 0);
if (!strcasecmp(cmd, "users")) {
}
}
+/*****************************************************************************/
+
+
+void do_fsck_msg(long msgnum) {
+ struct roomref *ptr;
+
+ ptr = (struct roomref *)mallok(sizeof(struct roomref));
+ ptr->next = rr;
+ ptr->msgnum = msgnum;
+ rr = ptr;
+}
+
+void do_fsck_room(struct quickroom *qrbuf, void *data)
+{
+ getroom(&CC->quickroom, qrbuf->QRname);
+ CtdlForEachMessage(MSGS_ALL, 0L, (-127), NULL, NULL, do_fsck_msg);
+}
+
+/*
+ * Check message reference counts
+ */
+void cmd_fsck(char *argbuf) {
+ long msgnum;
+ struct cdbdata *cdbmsg;
+ struct SuppMsgInfo smi;
+ struct roomref *ptr;
+ int realcount;
+
+ if (CtdlAccessCheck(ac_aide)) return;
+
+ /* Lame way of checking whether anyone else is doing this now */
+ if (rr != NULL) {
+ cprintf("%d Another FSCK is already running.\n", ERROR);
+ return;
+ }
+
+ cprintf("%d Checking message reference counts\n", LISTING_FOLLOWS);
+
+ cprintf("\nThis could take a while. Please be patient!\n\n");
+ cprintf("Gathering pointers...\n");
+ ForEachRoom(do_fsck_room, NULL);
+
+ get_control();
+ cprintf("Checking message base...\n");
+ for (msgnum = 0L; msgnum <= CitControl.MMhighest; ++msgnum) {
+
+ cdbmsg = cdb_fetch(CDB_MSGMAIN, &msgnum, sizeof(long));
+ if (cdbmsg != NULL) {
+ cdb_free(cdbmsg);
+ cprintf("Message %7ld ", msgnum);
+
+ GetSuppMsgInfo(&smi, msgnum);
+ cprintf("refcount=%-2d ", smi.smi_refcount);
+
+ realcount = 0;
+ for (ptr = rr; ptr != NULL; ptr = ptr->next) {
+ if (ptr->msgnum == msgnum) ++realcount;
+ }
+ cprintf("realcount=%-2d\n", realcount);
+
+ if ( (smi.smi_refcount != realcount)
+ || (realcount == 0) ) {
+ smi.smi_refcount = realcount;
+ PutSuppMsgInfo(&smi);
+ AdjRefCount(msgnum, 0); /* deletes if needed */
+ }
+
+ }
+
+ }
+
+ cprintf("Freeing memory...\n");
+ while (rr != NULL) {
+ ptr = rr->next;
+ phree(rr);
+ rr = ptr;
+ }
+
+ cprintf("Done!\n");
+ cprintf("000\n");
+
+}
+
+
+
+/*****************************************************************************/
char *Dynamic_Module_Init(void)
{
CtdlRegisterProtoHook(cmd_expi, "EXPI", "Expire old system objects");
+ CtdlRegisterProtoHook(cmd_fsck, "FSCK", "Check message ref counts");
return "$Id$";
}