Skip to content

Commit

Permalink
Honor $TEMP and friends when generating anonymous handles (JuliaLan…
Browse files Browse the repository at this point in the history
…g#43515)

On Darwin, when generating anonymous handles, we hardcoded `/tmp` as the
beginning path, but that's bad behavior if the user has explicitly
requested (via setting `$TEMP` or `$TEMPDIR`, etc...) that we not do so.
Let's use `uv_os_tmpdir()` to put things in the correct place as much as
we can, defaulting to `/tmp` if anything goes wrong inside of libuv.
  • Loading branch information
staticfloat authored and LilithHafner committed Feb 22, 2022
1 parent cd43b3b commit 024cc72
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/cgmemmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static intptr_t get_anon_hdl(void)
if (check_fd_or_close(fd))
return fd;
# endif
char shm_name[] = "julia-codegen-0123456789-0123456789/tmp///";
char shm_name[PATH_MAX] = "julia-codegen-0123456789-0123456789/tmp///";
pid_t pid = getpid();
// `shm_open` can't be mapped exec on mac
# ifndef _OS_DARWIN_
Expand All @@ -195,8 +195,14 @@ static intptr_t get_anon_hdl(void)
return fd;
}
}
snprintf(shm_name, sizeof(shm_name),
"/tmp/julia-codegen-%d-XXXXXX", (int)pid);
size_t len = sizeof(shm_name);
if (uv_os_tmpdir(shm_name, &len) != 0) {
// Unknown error; default to `/tmp`
snprintf(shm_name, sizeof(shm_name), "/tmp");
len = 4;
}
snprintf(shm_name + len, sizeof(shm_name) - len,
"/julia-codegen-%d-XXXXXX", (int)pid);
fd = mkstemp(shm_name);
if (check_fd_or_close(fd)) {
unlink(shm_name);
Expand Down

0 comments on commit 024cc72

Please sign in to comment.