diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-04-07 14:57:15 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-06-12 12:22:17 -0400 |
commit | 0a11b516c439c645d90583a661db0380d9696617 (patch) | |
tree | 664c28294f810008f04d76e95ac4c06b6f12151f /src | |
parent | a7136999f9a4a04ed7ac6f83de37c34bac01ade1 (diff) | |
download | bfs-0a11b516c439c645d90583a661db0380d9696617.tar.xz |
fsade: Make syscall support checks thread-safe
Diffstat (limited to 'src')
-rw-r--r-- | src/fsade.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/fsade.c b/src/fsade.c index ca3a99c..c401426 100644 --- a/src/fsade.c +++ b/src/fsade.c @@ -2,6 +2,7 @@ // SPDX-License-Identifier: 0BSD #include "fsade.h" +#include "atomic.h" #include "config.h" #include "bfstd.h" #include "bftw.h" @@ -34,11 +35,10 @@ * emulate something similar if /proc/self/fd is available. */ static const char *fake_at(const struct BFTW *ftwbuf) { - static bool proc_works = true; - static bool proc_checked = false; + static atomic int proc_works = -1; char *path = NULL; - if (!proc_works || ftwbuf->at_fd == AT_FDCWD) { + if (ftwbuf->at_fd == AT_FDCWD || load(&proc_works, relaxed) == 0) { goto fail; } @@ -47,11 +47,12 @@ static const char *fake_at(const struct BFTW *ftwbuf) { goto fail; } - if (!proc_checked) { - proc_checked = true; + if (load(&proc_works, relaxed) < 0) { if (xfaccessat(AT_FDCWD, path, F_OK) != 0) { - proc_works = false; + store(&proc_works, 0, relaxed); goto fail; + } else { + store(&proc_works, 1, relaxed); } } |