Skip to content

Commit

Permalink
pythongh-98178: syslog() is not thread-safe on macOS (python#98213)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vstinner authored Oct 13, 2022
1 parent 4414586 commit d4b9166
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions Modules/syslogmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit d4b9166

Please sign in to comment.