]> code.citadel.org Git - citadel.git/blobdiff - citadel/control.c
* added server command line option "-f" to defrag databases on startup
[citadel.git] / citadel / control.c
index e69b42a413e48d22258eff681aac96d86b4905b7..c4868210a01ab6559352b01b6f916d2c69dfac3f 100644 (file)
@@ -7,6 +7,7 @@
  *
  */
 
+#include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -17,7 +18,9 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
+#ifdef HAVE_PTHREAD_H
 #include <pthread.h>
+#endif
 #include <syslog.h>
 #include "citadel.h"
 #include "server.h"
 
 struct CitControl CitControl;
 struct config config;
+FILE *control_fp = NULL;
 
 /*
  * get_control  -  read the control record into memory.
  */
 void get_control(void) {
-       FILE *fp;
 
        /* 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) {
-       FILE *fp;
 
-       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);
                }
        }
 
@@ -146,6 +149,7 @@ void cmd_conf(char *argbuf) {
                cprintf("%d\n", config.c_userpurge);
                cprintf("%d\n", config.c_roompurge);
                cprintf("%s\n", config.c_logpages);
+               cprintf("%d\n", config.c_createax);
                cprintf("000\n");
                }
 
@@ -204,6 +208,12 @@ void cmd_conf(char *argbuf) {
                        case 18: strncpy(config.c_logpages,
                                        buf, ROOMNAMELEN);
                                break;
+                       case 19: config.c_createax = atoi(buf);
+                               if (config.c_createax < 1)
+                                       config.c_createax = 1;
+                               if (config.c_createax > 6)
+                                       config.c_createax = 6;
+                               break;
                                }
                    ++a;
                    }