* control.c: better performance and reliability in [get|put]_control()
+Thu Jun 24 11:13:23 EDT 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
+ * added server command line option "-f" to defrag databases on startup
+ * control.c: better performance and reliability in [get|put]_control()
+
Mon Jun 21 00:04:15 EDT 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
* netproc.c: started writing a vortex checker. Not finished.
Mon Jun 21 00:04:15 EDT 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
* netproc.c: started writing a vortex checker. Not finished.
struct CitContext *ContextList = NULL;
int ScheduledShutdown = 0;
struct CitContext *ContextList = NULL;
int ScheduledShutdown = 0;
/*
* Various things that need to be initialized at startup
/*
* Various things that need to be initialized at startup
lprintf(7, "Opening databases\n");
open_databases();
lprintf(7, "Opening databases\n");
open_databases();
+ if (do_defrag)
+ defrag_databases();
+
lprintf(7, "Checking floor reference counts\n");
check_ref_counts();
lprintf(7, "Checking floor reference counts\n");
check_ref_counts();
void *CtdlGetUserData(unsigned long requested_sym);
void CtdlAllocUserData(unsigned long requested_sym, size_t num_bytes);
int CtdlGetDynamicSymbol(void);
void *CtdlGetUserData(unsigned long requested_sym);
void CtdlAllocUserData(unsigned long requested_sym, size_t num_bytes);
int CtdlGetDynamicSymbol(void);
struct CitControl CitControl;
struct config config;
struct CitControl CitControl;
struct config config;
+FILE *control_fp = NULL;
/*
* get_control - read the control record into memory.
*/
void get_control(void) {
/*
* get_control - read the control record into memory.
*/
void get_control(void) {
/* Zero it out. If the control record on disk is missing or short,
* the system functions with all control record fields initialized
* to zero.
*/
memset(&CitControl, 0, sizeof(struct CitControl));
/* Zero it out. If the control record on disk is missing or short,
* the system functions with all control record fields initialized
* to zero.
*/
memset(&CitControl, 0, sizeof(struct CitControl));
- fp = fopen("citadel.control", "rb");
- if (fp == NULL) return;
+ if (control_fp == NULL)
+ control_fp = fopen("citadel.control", "rb+");
+ if (control_fp == NULL) return;
- fread(&CitControl, sizeof(struct CitControl), 1, fp);
- fclose(fp);
+ rewind(control_fp);
+ fread(&CitControl, sizeof(struct CitControl), 1, control_fp);
}
/*
* put_control - write the control record to disk.
*/
void put_control(void) {
}
/*
* put_control - write the control record to disk.
*/
void put_control(void) {
- fp = fopen("citadel.control", "wb");
- if (fp != NULL) {
- fwrite(&CitControl, sizeof(struct CitControl), 1, fp);
- fclose(fp);
+ if (control_fp != NULL) {
+ rewind(control_fp);
+ fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp);
+ fflush(control_fp);
void close_databases(void) {
int a;
void close_databases(void) {
int a;
- /* Hmm... we should decide when would be a good time to defrag.
- * Server shutdowns might be an opportune time.
- defrag_databases();
- */
-
begin_critical_section(S_DATABASE);
for (a=0; a<MAXCDB; ++a) {
lprintf(7, "Closing database %d\n", a);
begin_critical_section(S_DATABASE);
for (a=0; a<MAXCDB; ++a) {
lprintf(7, "Closing database %d\n", a);
program is the main Citadel server. Before we cover the recommended method of
starting the server, let's examine its usage options:
program is the main Citadel server. Before we cover the recommended method of
starting the server, let's examine its usage options:
- citserver [-hHomeDir] [-xDebugLevel] [-tTraceFile] [-d]
+ citserver [-hHomeDir] [-xDebugLevel] [-tTraceFile] [-d] [-f]
The options are as follows:
The options are as follows:
not recommended, because this won't allow the server to automatically restart
when it is shut down).
not recommended, because this won't allow the server to automatically restart
when it is shut down).
+ -f - Defragment all the databases upon startup. This isn't
+normally necessary due to the nature of the data stored in Citadel, but the
+option is provided in case you need it.
+
The preferred method of starting the Citadel server is to place an entry in
your /etc/inittab file. This will conveniently bring the server up when your
The preferred method of starting the Citadel server is to place an entry in
your /etc/inittab file. This will conveniently bring the server up when your
int num_msgs;
long *msglist;
long highest_msg = 0L;
int num_msgs;
long *msglist;
long highest_msg = 0L;
+
+ lprintf(9, "AddMessageToRoom(%s, %ld)\n", whichroom->QRname, newmsgid);
cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
if (cdbfr == NULL) {
msglist = NULL;
cdbfr = cdb_fetch(CDB_MSGLISTS, &whichroom->QRnumber, sizeof(long));
if (cdbfr == NULL) {
msglist = NULL;
}
else {
msglist = mallok(cdbfr->len);
}
else {
msglist = mallok(cdbfr->len);
+ if (msglist==NULL) lprintf(3, "ERROR malloc msglist!\n");
num_msgs = cdbfr->len / sizeof(long);
memcpy(msglist, cdbfr->ptr, cdbfr->len);
cdb_free(cdbfr);
num_msgs = cdbfr->len / sizeof(long);
memcpy(msglist, cdbfr->ptr, cdbfr->len);
cdb_free(cdbfr);
+ else if (!strncmp(argv[a], "-f", 2)) {
+ do_defrag = 1;
+ }
+
/* -r tells the server not to drop root permissions. don't use
* this unless you know what you're doing. this should be
* removed in the next release if it proves unnecessary. */
/* -r tells the server not to drop root permissions. don't use
* this unless you know what you're doing. this should be
* removed in the next release if it proves unnecessary. */
/* any other parameter makes it crash and burn */
else {
/* any other parameter makes it crash and burn */
else {
- lprintf(1, "citserver: usage: ");
- lprintf(1, "citserver [-tTraceFile]");
- lprintf(1, " [-d] [-xLogLevel] [-hHomeDir]\n");
+ lprintf(1, "citserver: usage: "
+ "citserver [-tTraceFile] [-d] [-f]"
+ " [-xLogLevel] [-hHomeDir]\n");