Skip to content

Commit

Permalink
pythongh-106118: Add O_CLOEXEC preprocessor guard (python#106120)
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed Jun 28, 2023
1 parent bbf722d commit 6c60684
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 4 additions & 1 deletion Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6c60684

Please sign in to comment.