Fixing obscure syslog corner-case when sys.argv = None, syslog() would call
openlog() for every logged message.
This commit is contained in:
parent
fc69af1562
commit
ca2e61276e
|
@ -56,6 +56,7 @@ Revision history:
|
||||||
|
|
||||||
/* only one instance, only one syslog, so globals should be ok */
|
/* only one instance, only one syslog, so globals should be ok */
|
||||||
static PyObject *S_ident_o = NULL; /* identifier, held by openlog() */
|
static PyObject *S_ident_o = NULL; /* identifier, held by openlog() */
|
||||||
|
static char S_log_open = 0;
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -133,6 +134,7 @@ syslog_openlog(PyObject * self, PyObject * args, PyObject *kwds)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
openlog(S_ident_o ? PyString_AsString(S_ident_o) : NULL, logopt, facility);
|
openlog(S_ident_o ? PyString_AsString(S_ident_o) : NULL, logopt, facility);
|
||||||
|
S_log_open = 1;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
|
@ -153,8 +155,8 @@ syslog_syslog(PyObject * self, PyObject * args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* call openlog if no current identifier */
|
/* if log is not opened, open it now */
|
||||||
if (!S_ident_o) {
|
if (!S_log_open) {
|
||||||
PyObject *openargs;
|
PyObject *openargs;
|
||||||
|
|
||||||
/* Continue even if PyTuple_New fails, because openlog(3) is optional.
|
/* Continue even if PyTuple_New fails, because openlog(3) is optional.
|
||||||
|
@ -178,9 +180,12 @@ syslog_syslog(PyObject * self, PyObject * args)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
syslog_closelog(PyObject *self, PyObject *unused)
|
syslog_closelog(PyObject *self, PyObject *unused)
|
||||||
{
|
{
|
||||||
|
if (S_log_open) {
|
||||||
closelog();
|
closelog();
|
||||||
Py_XDECREF(S_ident_o);
|
Py_XDECREF(S_ident_o);
|
||||||
S_ident_o = NULL;
|
S_ident_o = NULL;
|
||||||
|
S_log_open = 0;
|
||||||
|
}
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue