diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index d70cf2e7c96..f7fe428cee1 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -182,8 +182,7 @@ disk_cache_create(const char *gpu_name, const char *driver_id, uint8_t cache_version = CACHE_VERSION; size_t cv_size = sizeof(cache_version); - /* If running as a users other than the real user disable cache */ - if (geteuid() != getuid()) + if (!disk_cache_enabled()) return NULL; /* A ralloc context for transient data during this invocation. */ @@ -191,10 +190,6 @@ disk_cache_create(const char *gpu_name, const char *driver_id, if (local == NULL) goto fail; - /* At user request, disable shader cache entirely. */ - if (env_var_as_boolean("MESA_GLSL_CACHE_DISABLE", false)) - goto fail; - cache = rzalloc(NULL, struct disk_cache); if (cache == NULL) goto fail; diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c index 516245b7e08..37a8d56db4c 100644 --- a/src/util/disk_cache_os.c +++ b/src/util/disk_cache_os.c @@ -38,6 +38,7 @@ #include #include +#include "util/debug.h" #include "util/disk_cache.h" #include "util/disk_cache_os.h" #include "util/ralloc.h" @@ -171,6 +172,20 @@ disk_cache_generate_cache_dir(void *mem_ctx) return path; } + +bool +disk_cache_enabled() +{ + /* If running as a users other than the real user disable cache */ + if (geteuid() != getuid()) + return false; + + /* At user request, disable shader cache entirely. */ + if (env_var_as_boolean("MESA_GLSL_CACHE_DISABLE", false)) + return false; + + return true; +} #endif #endif /* ENABLE_SHADER_CACHE */ diff --git a/src/util/disk_cache_os.h b/src/util/disk_cache_os.h index 0b7755fbacd..f64ac8509f4 100644 --- a/src/util/disk_cache_os.h +++ b/src/util/disk_cache_os.h @@ -33,6 +33,9 @@ char * disk_cache_generate_cache_dir(void *mem_ctx); +bool +disk_cache_enabled(void); + #endif #endif /* DISK_CACHE_OS_H */