[Python-checkins] gh-106118: Add O_CLOEXEC preprocessor guard (#106120)

erlend-aasland webhook-mailer at python.org
Wed Jun 28 07:11:36 EDT 2023


https://github.com/python/cpython/commit/6c60684bf5d34fae27a2f6a142ff794b38cefe1b
commit: 6c60684bf5d34fae27a2f6a142ff794b38cefe1b
branch: main
author: Erlend E. Aasland <erlend at python.org>
committer: erlend-aasland <erlend.aasland at protonmail.com>
date: 2023-06-28T13:11:32+02:00
summary:

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

files:
A Misc/NEWS.d/next/Build/2023-06-26-21-56-29.gh-issue-106118.0cCfhl.rst
M Python/sysmodule.c

diff --git a/Misc/NEWS.d/next/Build/2023-06-26-21-56-29.gh-issue-106118.0cCfhl.rst b/Misc/NEWS.d/next/Build/2023-06-26-21-56-29.gh-issue-106118.0cCfhl.rst
new file mode 100644
index 0000000000000..f93cae5d03b53
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2023-06-26-21-56-29.gh-issue-106118.0cCfhl.rst
@@ -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.
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 3284e14e7742d..0cd8974d19713 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -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);



More information about the Python-checkins mailing list