]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-98178: syslog() is not thread-safe on macOS (#98213)
authorVictor Stinner <vstinner@python.org>
Thu, 13 Oct 2022 11:34:55 +0000 (13:34 +0200)
committerGitHub <noreply@github.com>
Thu, 13 Oct 2022 11:34:55 +0000 (13:34 +0200)
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.

Misc/NEWS.d/next/Library/2022-10-12-10-00-40.gh-issue-98178.hspH51.rst [new file with mode: 0644]
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 (file)
index 0000000..833a6e6
--- /dev/null
@@ -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.
index b6296ed0a69aa55c5a65fc2f22b183c650335f9b..5137d01c6887c664d6bd9a6652c533a95ff89979 100644 (file)
@@ -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;
 }