summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-05-08 21:52:55 (GMT)
committerGuido van Rossum <guido@python.org>1998-05-08 21:52:55 (GMT)
commitae94cf292ba0317ac70a5eca3004a2fa5bcaad80 (patch)
tree39936eaa390bdf3b9765c0757930f60991e89b78 /Modules
parent27c225e82651088466df607084ea2363373228f0 (diff)
downloadcpython-ae94cf292ba0317ac70a5eca3004a2fa5bcaad80.zip
cpython-ae94cf292ba0317ac70a5eca3004a2fa5bcaad80.tar.gz
cpython-ae94cf292ba0317ac70a5eca3004a2fa5bcaad80.tar.bz2
Fix by Sean Reifschneider:
- When facility not specified to syslog() method, use default from openlog() (This is how it was claimed to work in the documentation) - Potential resource leak of o_ident, now cleaned up in closelog() - Minor comment accuracy fix.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/syslogmodule.c63
1 files changed, 38 insertions, 25 deletions
diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c
index 1dd5a97..96de3ac 100644
--- a/Modules/syslogmodule.c
+++ b/Modules/syslogmodule.c
@@ -26,6 +26,12 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Revision history:
+1998/04/28 (Sean Reifschneider)
+ - When facility not specified to syslog() method, use default from openlog()
+ (This is how it was claimed to work in the documentation)
+ - Potential resource leak of o_ident, now cleaned up in closelog()
+ - Minor comment accuracy fix.
+
95/06/29 (Steve Clift)
- Changed arg parsing to use PyArg_ParseTuple.
- Added PyErr_Clear() call(s) where needed.
@@ -42,6 +48,10 @@ Revision history:
#include <syslog.h>
+/* only one instance, only one syslog, so globals should be ok */
+static PyObject *S_ident_o = NULL; /* identifier, held by openlog() */
+
+
static PyObject *
syslog_openlog(self, args)
PyObject * self;
@@ -50,20 +60,19 @@ syslog_openlog(self, args)
long logopt = 0;
long facility = LOG_USER;
- static PyObject *ident_o = NULL;
- Py_XDECREF(ident_o);
+ Py_XDECREF(S_ident_o);
if (!PyArg_ParseTuple(args,
"S|ll;ident string [, logoption [, facility]]",
- &ident_o, &logopt, &facility))
+ &S_ident_o, &logopt, &facility))
return NULL;
/* This is needed because openlog() does NOT make a copy
* and syslog() later uses it.. cannot trash it.
*/
- Py_INCREF(ident_o);
+ Py_INCREF(S_ident_o);
- openlog(PyString_AsString(ident_o), logopt, facility);
+ openlog(PyString_AsString(S_ident_o), logopt, facility);
Py_INCREF(Py_None);
return Py_None;
@@ -76,7 +85,7 @@ syslog_syslog(self, args)
PyObject * args;
{
char *message;
- int priority = LOG_INFO | LOG_USER;
+ int priority = LOG_INFO;
if (!PyArg_ParseTuple(args, "is;[priority,] message string",
&priority, &message)) {
@@ -85,6 +94,7 @@ syslog_syslog(self, args)
&message))
return NULL;
}
+
syslog(priority, "%s", message);
Py_INCREF(Py_None);
return Py_None;
@@ -98,6 +108,8 @@ syslog_closelog(self, args)
if (!PyArg_ParseTuple(args, ""))
return NULL;
closelog();
+ Py_XDECREF(S_ident_o);
+ S_ident_o = NULL;
Py_INCREF(Py_None);
return Py_None;
}
@@ -153,7 +165,7 @@ static PyMethodDef syslog_methods[] = {
{NULL, NULL, 0}
};
-/* Initialization function for the module */
+/* helper function for initialization function */
static void
ins(d, s, x)
@@ -168,6 +180,7 @@ ins(d, s, x)
}
}
+/* Initialization function for the module */
void
initsyslog()
@@ -205,25 +218,7 @@ initsyslog()
ins(d, "LOG_MAIL", LOG_MAIL);
ins(d, "LOG_DAEMON", LOG_DAEMON);
ins(d, "LOG_AUTH", LOG_AUTH);
-#ifdef LOG_SYSLOG
- ins(d, "LOG_SYSLOG", LOG_SYSLOG);
-#endif
ins(d, "LOG_LPR", LOG_LPR);
-#ifdef LOG_NEWS
- ins(d, "LOG_NEWS", LOG_NEWS);
-#else
- ins(d, "LOG_NEWS", LOG_MAIL);
-#endif
-#ifdef LOG_UUCP
- ins(d, "LOG_UUCP", LOG_UUCP);
-#else
- ins(d, "LOG_UUCP", LOG_MAIL);
-#endif
-#ifdef LOG_CRON
- ins(d, "LOG_CRON", LOG_CRON);
-#else
- ins(d, "LOG_CRON", LOG_DAEMON);
-#endif
ins(d, "LOG_LOCAL0", LOG_LOCAL0);
ins(d, "LOG_LOCAL1", LOG_LOCAL1);
ins(d, "LOG_LOCAL2", LOG_LOCAL2);
@@ -233,6 +228,24 @@ initsyslog()
ins(d, "LOG_LOCAL6", LOG_LOCAL6);
ins(d, "LOG_LOCAL7", LOG_LOCAL7);
+#ifndef LOG_SYSLOG
+#define LOG_SYSLOG LOG_DAEMON
+#endif
+#ifndef LOG_NEWS
+#define LOG_NEWS LOG_MAIL
+#endif
+#ifndef LOG_UUCP
+#define LOG_UUCP LOG_MAIL
+#endif
+#ifndef LOG_CRON
+#define LOG_CRON LOG_DAEMON
+#endif
+
+ ins(d, "LOG_SYSLOG", LOG_SYSLOG);
+ ins(d, "LOG_CRON", LOG_CRON);
+ ins(d, "LOG_UUCP", LOG_UUCP);
+ ins(d, "LOG_NEWS", LOG_NEWS);
+
/* Check for errors */
if (PyErr_Occurred())
Py_FatalError("can't initialize module syslog");