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 d4b9166385)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2022-10-13 04:59:23 -07:00 committed by GitHub
parent 0a67f82eb1
commit c7761bbc32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -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.

View File

@ -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;
}