From 876509ae8b95f76adebdfa1f2380d75a49f9871d Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sun, 13 Nov 2022 14:43:35 +0100 Subject: fix: Use $XDG_RUNTIME_DIR/ccache-tmp as the default temporary directory See discussion in #1221. --- cmake/GenerateConfigurationFile.cmake | 1 - cmake/config.h.in | 3 --- doc/MANUAL.adoc | 3 ++- src/Config.cpp | 7 ++++--- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cmake/GenerateConfigurationFile.cmake b/cmake/GenerateConfigurationFile.cmake index 20be4eac..858567b9 100644 --- a/cmake/GenerateConfigurationFile.cmake +++ b/cmake/GenerateConfigurationFile.cmake @@ -26,7 +26,6 @@ endforeach() include(CheckFunctionExists) set(functions asctime_r - geteuid getopt_long getpwuid posix_fallocate diff --git a/cmake/config.h.in b/cmake/config.h.in index 28ea3c2a..1537119b 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -76,9 +76,6 @@ // Define if your compiler supports AVX2. #cmakedefine HAVE_AVX2 -// Define if you have the "geteuid" function. -#cmakedefine HAVE_GETEUID - // Define if you have the "getopt_long" function. #cmakedefine HAVE_GETOPT_LONG diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index b9a202ca..48328fa8 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -1036,7 +1036,8 @@ NOTE: Lines in the stats log starting with a hash sign (`#`) are comments. *temporary_dir* (*CCACHE_TEMPDIR*):: This option specifies where ccache will put temporary files. The default is - `/run/user//ccache-tmp` if `/run/user/` exists, otherwise + `$XDG_RUNTIME_DIR/ccache-tmp` (typically `/run/user//ccache-tmp`) if + `XDG_RUNTIME_DIR` is set and the directory exists, otherwise `/tmp`. + NOTE: In previous versions of ccache, *CCACHE_TEMPDIR* had to be on the same diff --git a/src/Config.cpp b/src/Config.cpp index 5755c1b6..75a1358d 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -1114,9 +1114,10 @@ std::string Config::default_temporary_dir() const { static const std::string run_user_tmp_dir = [] { -#ifdef HAVE_GETEUID - if (Stat::stat("/run").is_directory()) { - auto dir = FMT("/run/user/{}/ccache-tmp", geteuid()); +#ifndef _WIN32 + const char* const xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"); + if (xdg_runtime_dir && Stat::stat(xdg_runtime_dir).is_directory()) { + auto dir = FMT("{}/ccache-tmp", xdg_runtime_dir); if (Util::create_dir(dir) && access(dir.c_str(), W_OK) == 0) { return dir; } -- cgit v1.2.1