summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2018-02-06 21:49:55 +0100
committerJoel Rosdahl <joel@rosdahl.net>2018-02-06 22:02:54 +0100
commita5b2c09dc01aff31ca64a81f3615ceaf7d2c159a (patch)
treee7d531de32cce9387416466b0ff036ba8a034d46
parent67fdd3b53c19476d33a9f74acdf02046293437ab (diff)
downloadccache-a5b2c09dc01aff31ca64a81f3615ceaf7d2c159a.tar.gz
Treat unreadable conf file like missing instead of a fatal error
This reverts 0b18af47 and implements a better solution. The major reason is to keep ccache transparent, i.e. to still have the following behavior: * If ccache returns exit code == 0, then any produced stderr comes from the compiler and only from the compiler. * If ccache returns exit code != 0, then ccache may print error messages of its own. The reason is that autoconf configure scripts have been known to fail tests if the compiler emits anything to stderr even if the produced result actually works. (And printing to stdout is also a no-no.)
-rw-r--r--NEWS.txt5
-rw-r--r--ccache.c15
-rw-r--r--util.c13
3 files changed, 11 insertions, 22 deletions
diff --git a/NEWS.txt b/NEWS.txt
index cbe19157..32bf48a3 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -13,8 +13,6 @@ New features and enhancements
- Added support for caching `.su` files generated by GCC flag `-fstack-usage`.
-- Configuration errors are now treated as warnings instead of fatal errors.
-
- ccache should now work with distcc's ``pump'' wrapper.
- The optional unifier is no longer disabled when the direct mode is enabled.
@@ -35,6 +33,9 @@ New features and enhancements
extension is non-standard. This should make it easier to use EDG-based
compilers (e.g. GHS) which don't understand `-MQ`.
+- ccache now treats an unreadable configuration file just like a missing
+ configuration file.
+
- Documented more pitfalls with enabling `hard_links` (`CCACHE_HARDLINK`).
- Documented caveats related to colored warnings from compilers.
diff --git a/ccache.c b/ccache.c
index c1d51da5..80d9916b 100644
--- a/ccache.c
+++ b/ccache.c
@@ -3122,17 +3122,17 @@ initialize(void)
conf = conf_create();
char *errmsg;
- struct stat st;
char *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) {
- warn("%s", errmsg);
+ if (access(secondary_config_path, R_OK) == 0) {
+ // We could read the file but it contained errors.
+ fatal("%s", errmsg);
}
- // Missing config file in SYSCONFDIR is OK.
+ // A missing config file in SYSCONFDIR is OK.
free(errmsg);
}
@@ -3152,14 +3152,15 @@ initialize(void)
bool should_create_initial_config = false;
if (!conf_read(conf, primary_config_path, &errmsg)) {
- if (stat(primary_config_path, &st) == 0) {
- warn("%s", errmsg);
+ if (access(primary_config_path, R_OK) == 0) {
+ // We could read the file but it contained errors.
+ fatal("%s", errmsg);
}
should_create_initial_config = true;
}
if (!conf_update_from_environment(conf, &errmsg)) {
- warn("%s", errmsg);
+ fatal("%s", errmsg);
}
if (conf->disable) {
diff --git a/util.c b/util.c
index 26109007..b89a33e8 100644
--- a/util.c
+++ b/util.c
@@ -183,19 +183,6 @@ fatal(const char *format, ...)
x_exit(1);
}
-void
-warn(const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- char msg[1000];
- vsnprintf(msg, sizeof(msg), format, ap);
- va_end(ap);
-
- cc_log("WARNING: %s", msg);
- fprintf(stderr, "ccache: warning: %s\n", msg);
-}
-
// Copy all data from fd_in to fd_out, decompressing data from fd_in if needed.
void
copy_fd(int fd_in, int fd_out)