From 34e4e444eb68af0d8842599d598f63d348aea4df Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 17 Jul 2026 11:05:28 -0700 Subject: [PATCH] fixes gh-153856: Add os.RWF_NOSIGNAL constant RWF_NOSIGNAL was added in Linux 6.18 to prevent pwritev2() from raising SIGPIPE when writing to disconnected pipes or sockets. --- Doc/library/os.rst | 11 +++++++++++ .../2026-07-17-14-30-00.gh-issue-153856.JEHepm.rst | 1 + Modules/clinic/posixmodule.c.h | 3 ++- Modules/posixmodule.c | 6 +++++- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-07-17-14-30-00.gh-issue-153856.JEHepm.rst diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 5858d9733c57796..be7ea26356bebe3 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1642,6 +1642,7 @@ or `the MSDN `_ on Windo - :data:`RWF_APPEND` - :data:`RWF_DONTCACHE` - :data:`RWF_ATOMIC` + - :data:`RWF_NOSIGNAL` Return the total number of bytes actually written. @@ -1691,6 +1692,16 @@ or `the MSDN `_ on Windo .. versionadded:: 3.10 +.. data:: RWF_NOSIGNAL + + Prevent pipe and socket writes from raising :const:`~signal.SIGPIPE`. + This flag is meaningful only for :func:`os.pwritev`. + + .. availability:: Linux >= 6.18. + + .. versionadded:: 3.16 + + .. function:: read(fd, n, /) Read at most *n* bytes from file descriptor *fd*. diff --git a/Misc/NEWS.d/next/Library/2026-07-17-14-30-00.gh-issue-153856.JEHepm.rst b/Misc/NEWS.d/next/Library/2026-07-17-14-30-00.gh-issue-153856.JEHepm.rst new file mode 100644 index 000000000000000..f0af3de70848339 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-17-14-30-00.gh-issue-153856.JEHepm.rst @@ -0,0 +1 @@ +Add :data:`os.RWF_NOSIGNAL` constant for Linux 6.18+. diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 1f7e414b2dfe48f..ac9b63dec9eb440 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -8801,6 +8801,7 @@ PyDoc_STRVAR(os_pwritev__doc__, "- RWF_APPEND\n" "- RWF_DONTCACHE\n" "- RWF_ATOMIC\n" +"- RWF_NOSIGNAL\n" "\n" "Using non-zero flags requires Linux 4.7 or newer."); @@ -13733,4 +13734,4 @@ os__emscripten_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py #ifndef OS__EMSCRIPTEN_LOG_METHODDEF #define OS__EMSCRIPTEN_LOG_METHODDEF #endif /* !defined(OS__EMSCRIPTEN_LOG_METHODDEF) */ -/*[clinic end generated code: output=d81494ceb6ce44ed input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d641f02a97057666 input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 36debd6fe7aa153..d6852f8b78514fc 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -12941,6 +12941,7 @@ following flags: - RWF_APPEND - RWF_DONTCACHE - RWF_ATOMIC +- RWF_NOSIGNAL Using non-zero flags requires Linux 4.7 or newer. [clinic start generated code]*/ @@ -12948,7 +12949,7 @@ Using non-zero flags requires Linux 4.7 or newer. static Py_ssize_t os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset, int flags) -/*[clinic end generated code: output=e3dd3e9d11a6a5c7 input=b2e352a22f030e9a]*/ +/*[clinic end generated code: output=e3dd3e9d11a6a5c7 input=c202f24f01fa66c9]*/ { Py_ssize_t cnt; Py_ssize_t result; @@ -18244,6 +18245,9 @@ all_ins(PyObject *m) #ifdef RWF_APPEND if (PyModule_AddIntConstant(m, "RWF_APPEND", RWF_APPEND)) return -1; #endif +#ifdef RWF_NOSIGNAL + if (PyModule_AddIntConstant(m, "RWF_NOSIGNAL", RWF_NOSIGNAL)) return -1; +#endif /* constants for splice */ #if defined(HAVE_SPLICE) && defined(__linux__)