return result;
}
+static void
+create_initial_config_file(struct conf *conf, const char *path)
+{
+ unsigned max_files;
+ uint64_t max_size;
+ char *stats_dir;
+ FILE *f;
+ struct stat st;
+
+ if (create_parent_dirs(path) != 0) {
+ return;
+ }
+
+ stats_dir = format("%s/0", conf->cache_dir);
+ if (stat(stats_dir, &st) == 0) {
+ stats_get_obsolete_limits(stats_dir, &max_files, &max_size);
+ /* STATS_MAXFILES and STATS_MAXSIZE was stored for each top directory. */
+ max_files *= 16;
+ max_size *= 16;
+ } else {
+ max_files = 0;
+ max_size = conf->max_size;
+ }
+ free(stats_dir);
+
+ f = fopen(path, "w");
+ if (!f) {
+ return;
+ }
+ if (max_files != 0) {
+ fprintf(f, "max_files = %u\n", max_files);
+ conf->max_files = max_files;
+ }
+ if (max_size != 0) {
+ char *size = format_parsable_size_with_suffix(max_size);
+ fprintf(f, "max_size = %s\n", size);
+ free(size);
+ conf->max_size = max_size;
+ }
+ fclose(f);
+}
+
+/*
+ * Read config file(s), populate variables, create configuration file in cache
+ * directory if missing, etc.
+ */
+static void
+initialize(void)
+{
+ char *errmsg;
+ char *p;
+ struct stat st;
+ bool should_create_initial_config = false;
+
+ conf_free(conf);
+ conf = conf_create();
+
+ p = getenv("CCACHE_CONFIGPATH");
+ if (p) {
+ primary_config_path = x_strdup(p);
+ } else {
+ secondary_config_path = format("%s/ccache.conf", TO_STRING(SYSCONFDIR));
+ if (!conf_read(conf, secondary_config_path, &errmsg)) {
+ if (stat(secondary_config_path, &st) == 0) {
+ fatal("%s", errmsg);
+ }
+ /* Missing config file in SYSCONFDIR is OK. */
+ free(errmsg);
+ }
+
+ if ((p = getenv("CCACHE_DIR"))) {
+ free(conf->cache_dir);
+ conf->cache_dir = strdup(p);
+ }
+
+ primary_config_path = format("%s/ccache.conf", conf->cache_dir);
+ }
+
+ if (!conf_read(conf, primary_config_path, &errmsg)) {
+ if (stat(primary_config_path, &st) == 0) {
+ fatal("%s", errmsg);
+ }
+ should_create_initial_config = true;
+ }
+
+ if (!conf_update_from_environment(conf, &errmsg)) {
+ fatal("%s", errmsg);
+ }
+
++ if (conf->disable) {
++ should_create_initial_config = false;
++ }
++
+ if (should_create_initial_config) {
+ create_initial_config_file(conf, primary_config_path);
+ }
+
+ exitfn_init();
+ exitfn_add_nullary(stats_flush);
+ exitfn_add_nullary(clean_up_tmp_files);
+
+ cc_log("=== CCACHE %s STARTED =========================================",
+ CCACHE_VERSION);
+
+ if (conf->umask != UINT_MAX) {
+ umask(conf->umask);
+ }
+
+ current_working_dir = get_cwd();
+}
+
/* Reset the global state. Used by the test suite. */
void
cc_reset(void)
checkstat 'no input file' 1
testname="CCACHE_DISABLE"
+ mv $CCACHE_DIR $CCACHE_DIR.saved
++ saved_config_path=$CCACHE_CONFIGPATH
++ unset CCACHE_CONFIGPATH
CCACHE_DISABLE=1 $CCACHE_COMPILE -c test1.c 2> /dev/null
+ if [ -d $CCACHE_DIR ]; then
+ test_failed "$CCACHE_DIR created dispite CCACHE_DISABLE being set"
+ fi
++ CCACHE_CONFIGPATH=$saved_config_path
+ mv $CCACHE_DIR.saved $CCACHE_DIR
checkstat 'cache hit (preprocessed)' 3
$CCACHE_COMPILE -c test1.c
checkstat 'cache hit (preprocessed)' 4