From: Joel Rosdahl Date: Tue, 25 Feb 2020 21:02:50 +0000 (+0100) Subject: Fix empty .ccache-log in debug mode without log_file set X-Git-Tag: v4.0~582 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e0f5063b159de97ca9cc3dae8dbab67628ccb33d;p=thirdparty%2Fccache.git Fix empty .ccache-log in debug mode without log_file set Regression in dcf6ab3f349a33974b31ce2e7c06a2085149ab4a. --- diff --git a/src/logging.cpp b/src/logging.cpp index 3ef5c785b..e1c7fcdd4 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -63,39 +63,30 @@ static size_t debug_log_size; #define DEBUG_LOG_BUFFER_MARGIN 1024 // Initialize logging. Call only once. -bool +void init_log(const Config& config) { - logfile_path = config.log_file(); - - if (logfile_path.empty()) { - return false; - } - if (config.debug()) { debug_log_buffer_capacity = DEBUG_LOG_BUFFER_MARGIN; debug_log_buffer = static_cast(x_malloc(debug_log_buffer_capacity)); debug_log_size = 0; } - if (config.log_file().empty()) { - return config.debug(); - } + #ifdef HAVE_SYSLOG if (config.log_file() == "syslog") { use_syslog = true; openlog("ccache", LOG_PID, LOG_USER); - return true; + return; // Don't open logfile } #endif + + logfile_path = config.log_file(); logfile = fopen(logfile_path.c_str(), "a"); - if (logfile) { #ifndef _WIN32 + if (logfile) { set_cloexec_flag(fileno(logfile)); -#endif - return true; - } else { - return false; } +#endif } static void diff --git a/src/logging.hpp b/src/logging.hpp index a07c53920..80bddf64b 100644 --- a/src/logging.hpp +++ b/src/logging.hpp @@ -24,7 +24,7 @@ class Config; -bool init_log(const Config& config); +void init_log(const Config& config); 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); diff --git a/test/suites/base.bash b/test/suites/base.bash index e625b34df..1c0b132dc 100644 --- a/test/suites/base.bash +++ b/test/suites/base.bash @@ -296,6 +296,24 @@ base_tests() { expect_stat 'cache miss' 2 expect_stat 'files in cache' 1 + # ------------------------------------------------------------------------- + TEST "CCACHE_DEBUG" + + unset CCACHE_LOGFILE + unset CCACHE_NODIRECT + CCACHE_DEBUG=1 $CCACHE_COMPILE -c test1.c + if ! grep -q Result: test1.o.ccache-log; then + test_failed "Unexpected data in .ccache-log" + fi + if ! grep -q "PREPROCESSOR MODE" test1.o.ccache-input-text; then + test_failed "Unexpected data in .ccache-input-text" + fi + for ext in c p d; do + if ! [ -f test1.o.ccache-input-$ext ]; then + test_failed ".ccache-input-$ext missing" + fi + done + # ------------------------------------------------------------------------- TEST "CCACHE_DISABLE"