diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-10-13 12:05:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-13 12:05:18 (GMT) |
commit | c7662420d62e04eefd99d7cdbcc74f72e68f3a6a (patch) | |
tree | a4e1a6f318ef9bb2a918dcce6936df76734a334e | |
parent | a0c11529f32cae213795f3e160808cccd2752e38 (diff) | |
download | cpython-c7662420d62e04eefd99d7cdbcc74f72e68f3a6a.zip cpython-c7662420d62e04eefd99d7cdbcc74f72e68f3a6a.tar.gz cpython-c7662420d62e04eefd99d7cdbcc74f72e68f3a6a.tar.bz2 |
gh-98178: syslog() is not thread-safe on macOS (GH-98213)
On macOS, fix a crash in syslog.syslog() in multi-threaded
applications. On macOS, the libc syslog() function is not
thread-safe, so syslog.syslog() no longer releases the GIL to call
it.
(cherry picked from commit d4b91663857e85eab1f309cacec4d27b5f6657ec)
Co-authored-by: Victor Stinner <vstinner@python.org>
-rw-r--r-- | Misc/NEWS.d/next/Library/2022-10-12-10-00-40.gh-issue-98178.hspH51.rst | 4 | ||||
-rw-r--r-- | Modules/syslogmodule.c | 5 |
2 files changed, 9 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Library/2022-10-12-10-00-40.gh-issue-98178.hspH51.rst b/Misc/NEWS.d/next/Library/2022-10-12-10-00-40.gh-issue-98178.hspH51.rst new file mode 100644 index 0000000..833a6e6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-10-12-10-00-40.gh-issue-98178.hspH51.rst @@ -0,0 +1,4 @@ +On macOS, fix a crash in :func:`syslog.syslog` in multi-threaded applications. +On macOS, the libc ``syslog()`` function is not thread-safe, so +:func:`syslog.syslog` no longer releases the GIL to call it. Patch by Victor +Stinner. diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c index bfa2ca2..8adbe21 100644 --- a/Modules/syslogmodule.c +++ b/Modules/syslogmodule.c @@ -207,9 +207,14 @@ syslog_syslog(PyObject * self, PyObject * args) */ PyObject *ident = S_ident_o; Py_XINCREF(ident); +#ifdef __APPLE__ + // gh-98178: On macOS, libc syslog() is not thread-safe + syslog(priority, "%s", message); +#else Py_BEGIN_ALLOW_THREADS; syslog(priority, "%s", message); Py_END_ALLOW_THREADS; +#endif Py_XDECREF(ident); Py_RETURN_NONE; } |