Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7f810cd

Browse files
author
Sean Reifscheider
committed
Porting commit 80458 to python 3
1 parent 40f0874 commit 7f810cd

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

Modules/syslogmodule.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Revision history:
5656

5757
/* only one instance, only one syslog, so globals should be ok */
5858
static PyObject *S_ident_o = NULL; /* identifier, held by openlog() */
59+
static char S_log_open = 0;
5960

6061

6162
static PyObject *
@@ -135,6 +136,7 @@ syslog_openlog(PyObject * self, PyObject * args, PyObject *kwds)
135136
*/
136137

137138
openlog(S_ident_o ? _PyUnicode_AsString(S_ident_o) : NULL, logopt, facility);
139+
S_log_open = 1;
138140

139141
Py_INCREF(Py_None);
140142
return Py_None;
@@ -160,8 +162,8 @@ syslog_syslog(PyObject * self, PyObject * args)
160162
if (message == NULL)
161163
return NULL;
162164

163-
/* call openlog if no current identifier */
164-
if (!S_ident_o) {
165+
/* if log is not opened, open it now */
166+
if (!S_log_open) {
165167
PyObject *openargs;
166168

167169
/* Continue even if PyTuple_New fails, because openlog(3) is optional.
@@ -184,9 +186,12 @@ syslog_syslog(PyObject * self, PyObject * args)
184186
static PyObject *
185187
syslog_closelog(PyObject *self, PyObject *unused)
186188
{
187-
closelog();
188-
Py_XDECREF(S_ident_o);
189-
S_ident_o = NULL;
189+
if (S_log_open) {
190+
closelog();
191+
Py_XDECREF(S_ident_o);
192+
S_ident_o = NULL;
193+
S_log_open = 0;
194+
}
190195
Py_INCREF(Py_None);
191196
return Py_None;
192197
}

0 commit comments

Comments
 (0)