4 * This function reads the citadel.config file. It should be called at
5 * the beginning of EVERY Citadel program.
19 #include "serv_extensions.h"
25 * get_config() is called during the initialization of any program which
26 * directly accesses Citadel data files. It verifies the system's integrity
27 * and reads citadel.config into memory.
29 void get_config(void) {
33 if (chdir(home_specified ? ctdl_home_directory : CTDLDIR) != 0) {
35 "This program could not be started.\n"
36 "Unable to change directory to %s\n"
38 (home_specified ? ctdl_home_directory : CTDLDIR),
42 cfp = fopen(file_citadel_config, "rb");
44 fprintf(stderr, "This program could not be started.\n"
51 fread((char *) &config, sizeof(struct config), 1, cfp);
52 if (fstat(fileno(cfp), &st)) {
53 perror(file_citadel_config);
57 if (st.st_uid != CTDLUID || st.st_mode != (S_IFREG | S_IRUSR | S_IWUSR)) {
58 fprintf(stderr, "check the permissions on %s\n", file_citadel_config);
59 // fprintf(stderr, "check the permissions on citadel.config\n");
65 if (config.c_setup_level < REV_MIN) {
66 fprintf(stderr, "config: Your data files are out of date. ");
67 fprintf(stderr, "Run setup to update them.\n");
69 " This program requires level %d.%02d\n",
70 (REV_LEVEL / 100), (REV_LEVEL % 100));
72 " Data files are currently at %d.%02d\n",
73 (config.c_setup_level / 100),
74 (config.c_setup_level % 100));
78 /* Default maximum message length is 10 megabytes. This is site
79 * configurable. Also check to make sure the limit has not been
80 * set below 8192 bytes.
82 if (config.c_maxmsglen <= 0)
83 config.c_maxmsglen = 10485760;
84 if (config.c_maxmsglen < 8192)
85 config.c_maxmsglen = 8192;
87 /* Default lower and upper limits on number of worker threads */
89 if (config.c_min_workers < 3) /* no less than 3 */
90 config.c_min_workers = 5;
92 if (config.c_max_workers == 0) /* default maximum */
93 config.c_max_workers = 256;
95 if (config.c_max_workers < config.c_min_workers) /* max >= min */
96 config.c_max_workers = config.c_min_workers;
98 /* Networking more than once every five minutes just isn't sane */
99 if (config.c_net_freq == 0L)
100 config.c_net_freq = 3600L; /* once per hour default */
101 if (config.c_net_freq < 300L)
102 config.c_net_freq = 300L;
107 * Occasionally, we will need to write the config file, because some operations
108 * change site-wide parameters.
110 void put_config(void)
114 if ((cfp = fopen(file_citadel_config, "rb+")) == NULL)
115 perror(file_citadel_config);
117 fwrite((char *) &config, sizeof(struct config), 1, cfp);