Skip to content

Commit 6c60684

Browse files
gh-106118: Add O_CLOEXEC preprocessor guard (#106120)
1 parent bbf722d commit 6c60684

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix compilation for platforms without :data:`!O_CLOEXEC`. The issue was
2+
introduced with Python 3.12b1 in :gh:`103295`. Patch by Erlend Aasland.

Python/sysmodule.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2277,7 +2277,10 @@ PyAPI_FUNC(int) PyUnstable_PerfMapState_Init(void) {
22772277
char filename[100];
22782278
pid_t pid = getpid();
22792279
// Use nofollow flag to prevent symlink attacks.
2280-
int flags = O_WRONLY | O_CREAT | O_APPEND | O_NOFOLLOW | O_CLOEXEC;
2280+
int flags = O_WRONLY | O_CREAT | O_APPEND | O_NOFOLLOW;
2281+
#ifdef O_CLOEXEC
2282+
flags |= O_CLOEXEC;
2283+
#endif
22812284
snprintf(filename, sizeof(filename) - 1, "/tmp/perf-%jd.map",
22822285
(intmax_t)pid);
22832286
int fd = open(filename, flags, 0600);

0 commit comments

Comments
 (0)