[Python-checkins] gh-98178: syslog() is not thread-safe on macOS (#98213)

ambv webhook-mailer at python.org
Thu Oct 13 07:35:40 EDT 2022


https://github.com/python/cpython/commit/d4b91663857e85eab1f309cacec4d27b5f6657ec
commit: d4b91663857e85eab1f309cacec4d27b5f6657ec
branch: main
author: Victor Stinner <vstinner at python.org>
committer: ambv <lukasz at langa.pl>
date: 2022-10-13T13:34:55+02:00
summary:

gh-98178: syslog() is not thread-safe on macOS (#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.

files:
A Misc/NEWS.d/next/Library/2022-10-12-10-00-40.gh-issue-98178.hspH51.rst
M Modules/syslogmodule.c

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 000000000000..833a6e6bb3f7
--- /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 b6296ed0a69a..5137d01c6887 100644
--- a/Modules/syslogmodule.c
+++ b/Modules/syslogmodule.c
@@ -207,9 +207,14 @@ syslog_syslog_impl(PyObject *module, int group_left_1, int priority,
      */
     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;
 }



More information about the Python-checkins mailing list