summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-10-13 11:34:55 (GMT)
committerGitHub <noreply@github.com>2022-10-13 11:34:55 (GMT)
commitd4b91663857e85eab1f309cacec4d27b5f6657ec (patch)
treeb3a245e050cb27b44e787f47411b2132f0b99823 /Modules
parent4414586172a7b22ce5b7508c68401e6dc2ac49cc (diff)
downloadcpython-d4b91663857e85eab1f309cacec4d27b5f6657ec.zip
cpython-d4b91663857e85eab1f309cacec4d27b5f6657ec.tar.gz
cpython-d4b91663857e85eab1f309cacec4d27b5f6657ec.tar.bz2
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.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/syslogmodule.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c
index b6296ed..5137d01 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;
}