/* Global configuration data. */
struct conf *conf = NULL;
+/* Where to write configuration changes. */
+char *primary_config_path = NULL;
+
/* current working directory taken from $PWD, or getcwd() if $PWD is bad */
char *current_working_dir = NULL;
char *errmsg;
char *p;
struct stat st;
+ bool should_create_initial_config = false;
conf_free(conf);
conf = conf_create();
p = getenv("CCACHE_CONFIG_PATH");
if (p) {
- if (!conf_read(conf, p, &errmsg)) {
- fatal("%s", errmsg);
- }
+ primary_config_path = x_strdup(p);
} else {
char *sysconf_config_path;
- char *cachedir_config_path;
sysconf_config_path = format("%s/ccache.conf", TO_STRING(SYSCONFDIR));
if (!conf_read(conf, sysconf_config_path, &errmsg)) {
conf->cache_dir = strdup(p);
}
- cachedir_config_path = format("%s/ccache.conf", conf->cache_dir);
- if (!conf_read(conf, cachedir_config_path, &errmsg)) {
- if (stat(cachedir_config_path, &st) == 0) {
- fatal("%s", errmsg);
- }
- create_initial_config_file(cachedir_config_path);
+ 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);
}
- free(cachedir_config_path);
+ should_create_initial_config = true;
}
if (!conf_update_from_environment(conf, &errmsg)) {
fatal("%s", errmsg);
}
+ 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_reset(void)
{
conf_free(conf); conf = NULL;
+ free(primary_config_path); primary_config_path = NULL;
free(current_working_dir); current_working_dir = NULL;
free(input_file); input_file = NULL;
free(output_obj); output_obj = NULL;