Skip to content

Commit

Permalink
Fix syslog race condition on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
colesbury committed Jun 16, 2023
1 parent 73524ae commit ef5bac9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
5 changes: 0 additions & 5 deletions Include/internal/pycore_critical_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@
#ifndef Py_INTERNAL_CRITICAL_SECTION_H
#define Py_INTERNAL_CRITICAL_SECTION_H

#include "pycore_pystate.h"
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif

/*
* Implementation of Python critical sections.
*
Expand Down
16 changes: 14 additions & 2 deletions Modules/clinic/syslogmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions Modules/syslogmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Revision history:
/* syslog module */

#include "Python.h"
#include "pycore_critical_section.h"
#include "osdefs.h" // SEP

#include <syslog.h>
Expand Down Expand Up @@ -127,7 +128,7 @@ syslog_get_argv(void)


/*[clinic input]
syslog.openlog
syslog.openlog @ mutex
ident: unicode = NULL
logoption as logopt: long = 0
Expand All @@ -139,7 +140,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=351888102dbc10b5]*/
{
// Since the sys.openlog changes the process level state of syslog library,
// this operation is only allowed for the main interpreter.
Expand Down Expand Up @@ -184,7 +185,7 @@ syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt,


/*[clinic input]
syslog.syslog
syslog.syslog @ mutex
[
priority: int(c_default="LOG_INFO") = LOG_INFO
Expand All @@ -200,7 +201,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=750638de4ab849ef]*/
{
if (PySys_Audit("syslog.syslog", "is", priority, message) < 0) {
return NULL;
Expand Down Expand Up @@ -238,14 +239,14 @@ syslog_syslog_impl(PyObject *module, int group_left_1, int priority,


/*[clinic input]
syslog.closelog
syslog.closelog @ mutex
Reset the syslog module values and call the system library closelog().
[clinic start generated code]*/

static PyObject *
syslog_closelog_impl(PyObject *module)
/*[clinic end generated code: output=97890a80a24b1b84 input=fb77a54d447acf07]*/
/*[clinic end generated code: output=97890a80a24b1b84 input=d037857842da63f3]*/
{
// Since the sys.closelog changes the process level state of syslog library,
// this operation is only allowed for the main interpreter.
Expand All @@ -266,7 +267,7 @@ syslog_closelog_impl(PyObject *module)
}

/*[clinic input]
syslog.setlogmask -> long
syslog.setlogmask @ mutex -> long
maskpri: long
/
Expand All @@ -276,7 +277,7 @@ Set the priority mask to maskpri and return the previous mask value.

static long
syslog_setlogmask_impl(PyObject *module, long maskpri)
/*[clinic end generated code: output=d6ed163917b434bf input=adff2c2b76c7629c]*/
/*[clinic end generated code: output=d6ed163917b434bf input=f384903bb51cc188]*/
{
if (PySys_Audit("syslog.setlogmask", "l", maskpri) < 0) {
return -1;
Expand Down

0 comments on commit ef5bac9

Please sign in to comment.