summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-04-07 14:58:08 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-06-12 12:22:17 -0400
commitc1c509759130967fa201636850337599b6ec3c75 (patch)
treef2b627f5c988080ed03b691a953193d68dfd0ef2 /src
parent0a11b516c439c645d90583a661db0380d9696617 (diff)
downloadbfs-c1c509759130967fa201636850337599b6ec3c75.tar.xz
stat: Make syscall support checks thread-safe
Diffstat (limited to 'src')
-rw-r--r--src/stat.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/stat.c b/src/stat.c
index 3f70e6c..e3e5aaa 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: 0BSD
#include "stat.h"
+#include "atomic.h"
#include "bfstd.h"
#include "config.h"
#include "diag.h"
@@ -248,14 +249,14 @@ static int bfs_statx_impl(int at_fd, const char *at_path, int at_flags, struct b
*/
static int bfs_stat_explicit(int at_fd, const char *at_path, int at_flags, int x_flags, struct bfs_stat *buf) {
#if BFS_STATX
- static bool has_statx = true;
+ static atomic bool has_statx = true;
- if (has_statx) {
+ if (load(&has_statx, relaxed)) {
int ret = bfs_statx_impl(at_fd, at_path, at_flags | x_flags, buf);
// EPERM is commonly returned in a seccomp() sandbox that does
// not allow statx()
if (ret != 0 && (errno == ENOSYS || errno == EPERM)) {
- has_statx = false;
+ store(&has_statx, false, relaxed);
} else {
return ret;
}
@@ -305,12 +306,12 @@ int bfs_stat(int at_fd, const char *at_path, enum bfs_stat_flags flags, struct b
// Check __GNU__ to work around https://lists.gnu.org/archive/html/bug-hurd/2021-12/msg00001.html
#if defined(AT_EMPTY_PATH) && !__GNU__
- static bool has_at_ep = true;
- if (has_at_ep) {
+ static atomic bool has_at_ep = true;
+ if (load(&has_at_ep, relaxed)) {
at_flags |= AT_EMPTY_PATH;
int ret = bfs_stat_explicit(at_fd, "", at_flags, x_flags, buf);
if (ret != 0 && errno == EINVAL) {
- has_at_ep = false;
+ store(&has_at_ep, false, relaxed);
} else {
return ret;
}