Skip to content

Commit d4b9166

Browse files
authored
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.
1 parent 4414586 commit d4b9166

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
On macOS, fix a crash in :func:`syslog.syslog` in multi-threaded applications.
2+
On macOS, the libc ``syslog()`` function is not thread-safe, so
3+
:func:`syslog.syslog` no longer releases the GIL to call it. Patch by Victor
4+
Stinner.

Modules/syslogmodule.c

+5
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,14 @@ syslog_syslog_impl(PyObject *module, int group_left_1, int priority,
207207
*/
208208
PyObject *ident = S_ident_o;
209209
Py_XINCREF(ident);
210+
#ifdef __APPLE__
211+
// gh-98178: On macOS, libc syslog() is not thread-safe
212+
syslog(priority, "%s", message);
213+
#else
210214
Py_BEGIN_ALLOW_THREADS;
211215
syslog(priority, "%s", message);
212216
Py_END_ALLOW_THREADS;
217+
#endif
213218
Py_XDECREF(ident);
214219
Py_RETURN_NONE;
215220
}

0 commit comments

Comments
 (0)