gh-117440: Make syslog thread-safe in free-threaded builds (#117441)

Use critical sections to protect access to the syslog module.
This commit is contained in:
Sam Gross
2024-04-02 10:44:26 -04:00
committed by GitHub
parent e569f9132b
commit 954d616b4c
2 changed files with 19 additions and 5 deletions

View File

@@ -132,6 +132,7 @@ syslog_get_argv(void)
/*[clinic input]
@critical_section
syslog.openlog
ident: unicode = NULL
@@ -144,7 +145,7 @@ Set logging options of subsequent syslog() calls.
static PyObject *
syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt,
long facility)
/*[clinic end generated code: output=5476c12829b6eb75 input=8a987a96a586eee7]*/
/*[clinic end generated code: output=5476c12829b6eb75 input=ee700b8786f81c23]*/
{
// Since the sys.openlog changes the process level state of syslog library,
// this operation is only allowed for the main interpreter.
@@ -189,6 +190,7 @@ syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt,
/*[clinic input]
@critical_section
syslog.syslog
[
@@ -205,7 +207,7 @@ Send the string message to the system logger.
static PyObject *
syslog_syslog_impl(PyObject *module, int group_left_1, int priority,
const char *message)
/*[clinic end generated code: output=c3dbc73445a0e078 input=ac83d92b12ea3d4e]*/
/*[clinic end generated code: output=c3dbc73445a0e078 input=6588ddb0b113af8e]*/
{
if (PySys_Audit("syslog.syslog", "is", priority, message) < 0) {
return NULL;
@@ -243,6 +245,7 @@ syslog_syslog_impl(PyObject *module, int group_left_1, int priority,
/*[clinic input]
@critical_section
syslog.closelog
Reset the syslog module values and call the system library closelog().
@@ -250,7 +253,7 @@ Reset the syslog module values and call the system library closelog().
static PyObject *
syslog_closelog_impl(PyObject *module)
/*[clinic end generated code: output=97890a80a24b1b84 input=fb77a54d447acf07]*/
/*[clinic end generated code: output=97890a80a24b1b84 input=167f489868bd5a72]*/
{
// Since the sys.closelog changes the process level state of syslog library,
// this operation is only allowed for the main interpreter.