From: Joel Rosdahl Date: Tue, 6 Feb 2018 20:49:55 +0000 (+0100) Subject: Treat unreadable conf file like missing instead of a fatal error X-Git-Tag: v3.4~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5b2c09dc01aff31ca64a81f3615ceaf7d2c159a;p=thirdparty%2Fccache.git 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.) --- diff --git a/NEWS.txt b/NEWS.txt index cbe191576..32bf48a3e 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 c1d51da5a..80d9916b5 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 261090075..b89a33e8a 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)