From 0b18af47f602757e27c08297eb88d4ed63b9e30e Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Wed, 8 Feb 2017 21:42:21 +0100 Subject: [PATCH] Treat configuration errors as warnings instead of fatal errors --- NEWS.txt | 2 ++ ccache.c | 6 +++--- ccache.h | 1 + util.c | 15 ++++++++++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index 49ac7609f..c4994afc4 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -12,6 +12,8 @@ New features and improvements - Added support for caching `.su` files generated by GCC flag `-fstack-usage`. +- Configuration errors are now treated as warnings instead of fatal errors. + ccache 3.3.3 ------------ diff --git a/ccache.c b/ccache.c index 44378cca3..84e27490c 100644 --- a/ccache.c +++ b/ccache.c @@ -3105,7 +3105,7 @@ initialize(void) 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); + warn("%s", errmsg); } // Missing config file in SYSCONFDIR is OK. free(errmsg); @@ -3128,13 +3128,13 @@ initialize(void) bool should_create_initial_config = false; if (!conf_read(conf, primary_config_path, &errmsg)) { if (stat(primary_config_path, &st) == 0) { - fatal("%s", errmsg); + warn("%s", errmsg); } should_create_initial_config = true; } if (!conf_update_from_environment(conf, &errmsg)) { - fatal("%s", errmsg); + warn("%s", errmsg); } if (conf->disable) { diff --git a/ccache.h b/ccache.h index cf7d0ff7a..d8030966a 100644 --- a/ccache.h +++ b/ccache.h @@ -126,6 +126,7 @@ void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2); void cc_bulklog(const char *format, ...) ATTR_FORMAT(printf, 1, 2); void cc_log_argv(const char *prefix, char **argv); void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2) ATTR_NORETURN; +void warn(const char *format, ...) ATTR_FORMAT(printf, 1, 2); void copy_fd(int fd_in, int fd_out); int copy_file(const char *src, const char *dest, int compress_level); diff --git a/util.c b/util.c index 6122c8436..e3889b653 100644 --- a/util.c +++ b/util.c @@ -1,5 +1,5 @@ // Copyright (C) 2002 Andrew Tridgell -// Copyright (C) 2009-2016 Joel Rosdahl +// Copyright (C) 2009-2017 Joel Rosdahl // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free @@ -187,6 +187,19 @@ 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) -- 2.47.2