gh-106118: Add O_CLOEXEC preprocessor guard (#106120)

This commit is contained in:
Erlend E. Aasland 2023-06-28 13:11:32 +02:00 committed by GitHub
parent bbf722dcd3
commit 6c60684bf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -0,0 +1,2 @@
Fix compilation for platforms without :data:`!O_CLOEXEC`. The issue was
introduced with Python 3.12b1 in :gh:`103295`. Patch by Erlend Aasland.

View File

@ -2277,7 +2277,10 @@ PyAPI_FUNC(int) PyUnstable_PerfMapState_Init(void) {
char filename[100];
pid_t pid = getpid();
// Use nofollow flag to prevent symlink attacks.
int flags = O_WRONLY | O_CREAT | O_APPEND | O_NOFOLLOW | O_CLOEXEC;
int flags = O_WRONLY | O_CREAT | O_APPEND | O_NOFOLLOW;
#ifdef O_CLOEXEC
flags |= O_CLOEXEC;
#endif
snprintf(filename, sizeof(filename) - 1, "/tmp/perf-%jd.map",
(intmax_t)pid);
int fd = open(filename, flags, 0600);