Skip to content

Commit

Permalink
Create a lockfile in $XDG_RUNTIME_DIR instead of $HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Oct 22, 2023
1 parent 5c49557 commit 39cdf61
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions elf/jobs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ template <typename E>
void acquire_global_lock(Context<E> &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;
Expand Down

0 comments on commit 39cdf61

Please sign in to comment.