summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorJakub KulĂ­k <Kulikjak@gmail.com>2023-12-17 21:34:57 (GMT)
committerGitHub <noreply@github.com>2023-12-17 21:34:57 (GMT)
commit2b93f5224216d10f8119373e72b5c2b3984e0af6 (patch)
tree2fe266d813dedeef8a19822a0db19713a8f460e5 /Modules
parent32d87a88994c131a9f3857d01ae7c07918577a55 (diff)
downloadcpython-2b93f5224216d10f8119373e72b5c2b3984e0af6.zip
cpython-2b93f5224216d10f8119373e72b5c2b3984e0af6.tar.gz
cpython-2b93f5224216d10f8119373e72b5c2b3984e0af6.tar.bz2
gh-113117: Support posix_spawn in subprocess.Popen with close_fds=True (#113118)
Add support for `os.POSIX_SPAWN_CLOSEFROM` and `posix_spawn_file_actions_addclosefrom_np` and have the `subprocess` module use them when available. This means `posix_spawn` can now be used in the default `close_fds=True` situation on many platforms. Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 2dc5d7d..8ffe0f5 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6834,6 +6834,9 @@ enum posix_spawn_file_actions_identifier {
POSIX_SPAWN_OPEN,
POSIX_SPAWN_CLOSE,
POSIX_SPAWN_DUP2
+#ifdef HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSEFROM_NP
+ ,POSIX_SPAWN_CLOSEFROM
+#endif
};
#if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)
@@ -7074,6 +7077,24 @@ parse_file_actions(PyObject *file_actions,
}
break;
}
+#ifdef HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSEFROM_NP
+ case POSIX_SPAWN_CLOSEFROM: {
+ int fd;
+ if (!PyArg_ParseTuple(file_action, "Oi"
+ ";A closefrom file_action tuple must have 2 elements",
+ &tag_obj, &fd))
+ {
+ goto fail;
+ }
+ errno = posix_spawn_file_actions_addclosefrom_np(file_actionsp,
+ fd);
+ if (errno) {
+ posix_error();
+ goto fail;
+ }
+ break;
+ }
+#endif
default: {
PyErr_SetString(PyExc_TypeError,
"Unknown file_actions identifier");
@@ -16774,6 +16795,9 @@ all_ins(PyObject *m)
if (PyModule_AddIntConstant(m, "POSIX_SPAWN_OPEN", POSIX_SPAWN_OPEN)) return -1;
if (PyModule_AddIntConstant(m, "POSIX_SPAWN_CLOSE", POSIX_SPAWN_CLOSE)) return -1;
if (PyModule_AddIntConstant(m, "POSIX_SPAWN_DUP2", POSIX_SPAWN_DUP2)) return -1;
+#ifdef HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSEFROM_NP
+ if (PyModule_AddIntMacro(m, POSIX_SPAWN_CLOSEFROM)) return -1;
+#endif
#endif
#if defined(HAVE_SPAWNV) || defined (HAVE_RTPSPAWN)