]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Treat unreadable conf file like missing instead of a fatal error
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 6 Feb 2018 20:49:55 +0000 (21:49 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 6 Feb 2018 21:02:54 +0000 (22:02 +0100)
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.)

NEWS.txt
ccache.c
util.c

index cbe191576252a7a31c3ba0e8736740a15b927700..32bf48a3e035b70e3b29889a10200a6207799eec 100644 (file)
--- 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.
index c1d51da5a2752301e0c830a13ee35a6421deb4f5..80d9916b5efb0f1bd4cbb6ffb56b9f282331e7fc 100644 (file)
--- 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 26109007503bf9e069c51c04696a8e7b95a81345..b89a33e8aba3c90312b44f8f9064241914fe9e59 100644 (file)
--- 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)