4 * This function reads the citadel.config file. It should be called at
5 * the beginning of EVERY Citadel program.
21 char bbs_home_directory[PATH_MAX] = BBSDIR;
22 int home_specified = 0;
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 ? bbs_home_directory : BBSDIR) != 0) {
35 "This program could not be started.\n"
36 "Unable to change directory to %s\n"
38 (home_specified ? bbs_home_directory : BBSDIR),
42 cfp = fopen("citadel.config", "rb");
44 fprintf(stderr, "This program could not be started.\n"
45 "Unable to open %s/citadel.config\n"
47 (home_specified ? bbs_home_directory : BBSDIR),
51 fread((char *) &config, sizeof(struct config), 1, cfp);
52 if (fstat(fileno(cfp), &st)) {
53 perror("citadel.config");
56 if (st.st_uid != BBSUID || st.st_mode != (S_IFREG | S_IRUSR | S_IWUSR)) {
57 fprintf(stderr, "check the permissions on citadel.config\n");
62 if (config.c_setup_level < REV_MIN) {
63 fprintf(stderr, "config: Your data files are out of date. ");
64 fprintf(stderr, "Run setup to update them.\n");
66 " This program requires level %d.%02d\n",
67 (REV_LEVEL / 100), (REV_LEVEL % 100));
69 " Data files are currently at %d.%02d\n",
70 (config.c_setup_level / 100),
71 (config.c_setup_level % 100));
75 /* Default maximum message length is 'unlimited' (max int)
76 * and the minimum is 8192
78 if (config.c_maxmsglen <= 0)
79 config.c_maxmsglen = INT_MAX;
80 if (config.c_maxmsglen < 8192)
81 config.c_maxmsglen = 8192;
83 /* Default lower and upper limits on number of worker threads */
85 if (config.c_min_workers < 3) /* no less than 3 */
86 config.c_min_workers = 5;
88 if (config.c_max_workers == 0) /* default maximum */
89 config.c_max_workers = 256;
91 if (config.c_max_workers < config.c_min_workers) /* max >= min */
92 config.c_max_workers = config.c_min_workers;
97 * Occasionally, we will need to write the config file, because some operations
98 * change site-wide parameters.
100 void put_config(void)
104 if ((cfp = fopen("citadel.config", "rb+")) == NULL)
105 perror("citadel.config");
107 fwrite((char *) &config, sizeof(struct config), 1, cfp);