Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address code review
  • Loading branch information
corona10 committed Nov 17, 2022
commit fb81c1eb81f2a2de720285ee5c90d92ec5d94963
14 changes: 4 additions & 10 deletions Modules/syslogmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,7 @@ static char S_log_open = 0;
static inline int
is_main_interpreter(void)
{
Comment thread
corona10 marked this conversation as resolved.
PyInterpreterState *main_interp = PyInterpreterState_Main();
PyThreadState *tstate = PyThreadState_GET();
PyInterpreterState *current_interp = PyThreadState_GetInterpreter(tstate);
if (current_interp == main_interp) {
return 1;
}
return 0;
return (PyInterpreterState_Get() == PyInterpreterState_Main());
}

static PyObject *
Expand Down Expand Up @@ -150,7 +144,7 @@ syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt,
// Since the sys.openlog changes the process level state of syslog library,
// this operation is only allowed for the main interpreter.
if (!is_main_interpreter()) {
PyErr_SetString(PyExc_RuntimeError, "subinterpreter can not use syslog.openlog");
PyErr_SetString(PyExc_RuntimeError, "subinterpreter can't use syslog.openlog()");
return NULL;
}

Expand Down Expand Up @@ -215,7 +209,7 @@ syslog_syslog_impl(PyObject *module, int group_left_1, int priority,
/* if log is not opened, open it now */
if (!S_log_open) {
if (!is_main_interpreter()) {
PyErr_SetString(PyExc_RuntimeError, "subinterpreter can't use syslog.syslog "
PyErr_SetString(PyExc_RuntimeError, "subinterpreter can't use syslog.syslog() "
"until the syslog is opened by the main interpreter");
return NULL;
}
Expand Down Expand Up @@ -257,7 +251,7 @@ syslog_closelog_impl(PyObject *module)
// Since the sys.closelog changes the process level state of syslog library,
// this operation is only allowed for the main interpreter.
if (!is_main_interpreter()) {
PyErr_SetString(PyExc_RuntimeError, "sunbinterpreter can not use syslog.closelog");
PyErr_SetString(PyExc_RuntimeError, "sunbinterpreter can't use syslog.closelog()");
return NULL;
}

Expand Down