Skip to content

Commit eb8117e

Browse files
colesburydiegorusso
authored andcommitted
pythongh-117440: Make syslog thread-safe in free-threaded builds (python#117441)
Use critical sections to protect access to the syslog module.
1 parent 65d474e commit eb8117e

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Modules/clinic/syslogmodule.c.h

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/syslogmodule.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ syslog_get_argv(void)
132132

133133

134134
/*[clinic input]
135+
@critical_section
135136
syslog.openlog
136137
137138
ident: unicode = NULL
@@ -144,7 +145,7 @@ Set logging options of subsequent syslog() calls.
144145
static PyObject *
145146
syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt,
146147
long facility)
147-
/*[clinic end generated code: output=5476c12829b6eb75 input=8a987a96a586eee7]*/
148+
/*[clinic end generated code: output=5476c12829b6eb75 input=ee700b8786f81c23]*/
148149
{
149150
// Since the sys.openlog changes the process level state of syslog library,
150151
// this operation is only allowed for the main interpreter.
@@ -189,6 +190,7 @@ syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt,
189190

190191

191192
/*[clinic input]
193+
@critical_section
192194
syslog.syslog
193195
194196
[
@@ -205,7 +207,7 @@ Send the string message to the system logger.
205207
static PyObject *
206208
syslog_syslog_impl(PyObject *module, int group_left_1, int priority,
207209
const char *message)
208-
/*[clinic end generated code: output=c3dbc73445a0e078 input=ac83d92b12ea3d4e]*/
210+
/*[clinic end generated code: output=c3dbc73445a0e078 input=6588ddb0b113af8e]*/
209211
{
210212
if (PySys_Audit("syslog.syslog", "is", priority, message) < 0) {
211213
return NULL;
@@ -243,14 +245,15 @@ syslog_syslog_impl(PyObject *module, int group_left_1, int priority,
243245

244246

245247
/*[clinic input]
248+
@critical_section
246249
syslog.closelog
247250
248251
Reset the syslog module values and call the system library closelog().
249252
[clinic start generated code]*/
250253

251254
static PyObject *
252255
syslog_closelog_impl(PyObject *module)
253-
/*[clinic end generated code: output=97890a80a24b1b84 input=fb77a54d447acf07]*/
256+
/*[clinic end generated code: output=97890a80a24b1b84 input=167f489868bd5a72]*/
254257
{
255258
// Since the sys.closelog changes the process level state of syslog library,
256259
// this operation is only allowed for the main interpreter.

0 commit comments

Comments
 (0)