summaryrefslogtreecommitdiffstats
path: root/Python/fileutils.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-06-17 17:23:40 (GMT)
committerGitHub <noreply@github.com>2024-06-17 17:23:40 (GMT)
commit460cc9e14e221c53c0038a847bfd411fe184ebf3 (patch)
treedc99ada57806c0fd62be952bffb7484e8c08d7e5 /Python/fileutils.c
parentd9b4316374ac27ec38ca8c829ff3fc2367ebd095 (diff)
downloadcpython-460cc9e14e221c53c0038a847bfd411fe184ebf3.zip
cpython-460cc9e14e221c53c0038a847bfd411fe184ebf3.tar.gz
cpython-460cc9e14e221c53c0038a847bfd411fe184ebf3.tar.bz2
gh-117657: Fix TSan reported data race on ioctl_works (#120175)
Diffstat (limited to 'Python/fileutils.c')
-rw-r--r--Python/fileutils.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index e6a5391..c9ae1b3 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -1502,7 +1502,7 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
#else
#if defined(HAVE_SYS_IOCTL_H) && defined(FIOCLEX) && defined(FIONCLEX)
- if (ioctl_works != 0 && raise != 0) {
+ if (raise != 0 && _Py_atomic_load_int_relaxed(&ioctl_works) != 0) {
/* fast-path: ioctl() only requires one syscall */
/* caveat: raise=0 is an indicator that we must be async-signal-safe
* thus avoid using ioctl() so we skip the fast-path. */
@@ -1512,7 +1512,9 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
request = FIOCLEX;
err = ioctl(fd, request, NULL);
if (!err) {
- ioctl_works = 1;
+ if (_Py_atomic_load_int_relaxed(&ioctl_works) == -1) {
+ _Py_atomic_store_int_relaxed(&ioctl_works, 1);
+ }
return 0;
}
@@ -1539,7 +1541,7 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
with EACCES. While FIOCLEX is safe operation it may be
unavailable because ioctl was denied altogether.
This can be the case on Android. */
- ioctl_works = 0;
+ _Py_atomic_store_int_relaxed(&ioctl_works, 0);
}
/* fallback to fcntl() if ioctl() does not work */
}