Skip to content

Commit c766242

Browse files
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 d4b9166) Co-authored-by: Victor Stinner <[email protected]>
1 parent a0c1152 commit c766242

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(PyObject * self, PyObject * args)
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)