From 39cdf61695847f13b9c69993dd8118a8a51966fb Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sun, 22 Oct 2023 13:28:13 +0900 Subject: [PATCH] Create a lockfile in $XDG_RUNTIME_DIR instead of $HOME https://github.com/rui314/mold/issues/117 --- elf/jobs.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/elf/jobs.cc b/elf/jobs.cc index 7da3d5c3ab..12b4a6a9d4 100644 --- a/elf/jobs.cc +++ b/elf/jobs.cc @@ -25,14 +25,15 @@ template void acquire_global_lock(Context &ctx) { #ifndef _WIN32 char *jobs = getenv("MOLD_JOBS"); - if (!jobs || std::string(jobs) != "1") + if (!jobs || jobs != "1"s) return; - char *home = getenv("HOME"); - if (!home) - home = getpwuid(getuid())->pw_dir; + std::string path; + if (char *dir = getenv("XDG_RUNTIME_DIR")) + path = dir + "/mold-lock"s; + else + path = "/tmp/mold-lock-"s + getpwuid(getuid())->pw_name; - std::string path = std::string(home) + "/.mold-lock"; int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_CLOEXEC, 0600); if (fd == -1) return;