@@ -26,6 +26,12 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26
26
27
27
Revision history:
28
28
29
+ 1998/04/28 (Sean Reifschneider)
30
+ - When facility not specified to syslog() method, use default from openlog()
31
+ (This is how it was claimed to work in the documentation)
32
+ - Potential resource leak of o_ident, now cleaned up in closelog()
33
+ - Minor comment accuracy fix.
34
+
29
35
95/06/29 (Steve Clift)
30
36
- Changed arg parsing to use PyArg_ParseTuple.
31
37
- Added PyErr_Clear() call(s) where needed.
@@ -42,6 +48,10 @@ Revision history:
42
48
43
49
#include <syslog.h>
44
50
51
+ /* only one instance, only one syslog, so globals should be ok */
52
+ static PyObject * S_ident_o = NULL ; /* identifier, held by openlog() */
53
+
54
+
45
55
static PyObject *
46
56
syslog_openlog (self , args )
47
57
PyObject * self ;
@@ -50,20 +60,19 @@ syslog_openlog(self, args)
50
60
long logopt = 0 ;
51
61
long facility = LOG_USER ;
52
62
53
- static PyObject * ident_o = NULL ;
54
63
55
- Py_XDECREF (ident_o );
64
+ Py_XDECREF (S_ident_o );
56
65
if (!PyArg_ParseTuple (args ,
57
66
"S|ll;ident string [, logoption [, facility]]" ,
58
- & ident_o , & logopt , & facility ))
67
+ & S_ident_o , & logopt , & facility ))
59
68
return NULL ;
60
69
61
70
/* This is needed because openlog() does NOT make a copy
62
71
* and syslog() later uses it.. cannot trash it.
63
72
*/
64
- Py_INCREF (ident_o );
73
+ Py_INCREF (S_ident_o );
65
74
66
- openlog (PyString_AsString (ident_o ), logopt , facility );
75
+ openlog (PyString_AsString (S_ident_o ), logopt , facility );
67
76
68
77
Py_INCREF (Py_None );
69
78
return Py_None ;
@@ -76,7 +85,7 @@ syslog_syslog(self, args)
76
85
PyObject * args ;
77
86
{
78
87
char * message ;
79
- int priority = LOG_INFO | LOG_USER ;
88
+ int priority = LOG_INFO ;
80
89
81
90
if (!PyArg_ParseTuple (args , "is;[priority,] message string" ,
82
91
& priority , & message )) {
@@ -85,6 +94,7 @@ syslog_syslog(self, args)
85
94
& message ))
86
95
return NULL ;
87
96
}
97
+
88
98
syslog (priority , "%s" , message );
89
99
Py_INCREF (Py_None );
90
100
return Py_None ;
@@ -98,6 +108,8 @@ syslog_closelog(self, args)
98
108
if (!PyArg_ParseTuple (args , "" ))
99
109
return NULL ;
100
110
closelog ();
111
+ Py_XDECREF (S_ident_o );
112
+ S_ident_o = NULL ;
101
113
Py_INCREF (Py_None );
102
114
return Py_None ;
103
115
}
@@ -153,7 +165,7 @@ static PyMethodDef syslog_methods[] = {
153
165
{NULL , NULL , 0 }
154
166
};
155
167
156
- /* Initialization function for the module */
168
+ /* helper function for initialization function */
157
169
158
170
static void
159
171
ins (d , s , x )
@@ -168,6 +180,7 @@ ins(d, s, x)
168
180
}
169
181
}
170
182
183
+ /* Initialization function for the module */
171
184
172
185
void
173
186
initsyslog ()
@@ -205,25 +218,7 @@ initsyslog()
205
218
ins (d , "LOG_MAIL" , LOG_MAIL );
206
219
ins (d , "LOG_DAEMON" , LOG_DAEMON );
207
220
ins (d , "LOG_AUTH" , LOG_AUTH );
208
- #ifdef LOG_SYSLOG
209
- ins (d , "LOG_SYSLOG" , LOG_SYSLOG );
210
- #endif
211
221
ins (d , "LOG_LPR" , LOG_LPR );
212
- #ifdef LOG_NEWS
213
- ins (d , "LOG_NEWS" , LOG_NEWS );
214
- #else
215
- ins (d , "LOG_NEWS" , LOG_MAIL );
216
- #endif
217
- #ifdef LOG_UUCP
218
- ins (d , "LOG_UUCP" , LOG_UUCP );
219
- #else
220
- ins (d , "LOG_UUCP" , LOG_MAIL );
221
- #endif
222
- #ifdef LOG_CRON
223
- ins (d , "LOG_CRON" , LOG_CRON );
224
- #else
225
- ins (d , "LOG_CRON" , LOG_DAEMON );
226
- #endif
227
222
ins (d , "LOG_LOCAL0" , LOG_LOCAL0 );
228
223
ins (d , "LOG_LOCAL1" , LOG_LOCAL1 );
229
224
ins (d , "LOG_LOCAL2" , LOG_LOCAL2 );
@@ -233,6 +228,24 @@ initsyslog()
233
228
ins (d , "LOG_LOCAL6" , LOG_LOCAL6 );
234
229
ins (d , "LOG_LOCAL7" , LOG_LOCAL7 );
235
230
231
+ #ifndef LOG_SYSLOG
232
+ #define LOG_SYSLOG LOG_DAEMON
233
+ #endif
234
+ #ifndef LOG_NEWS
235
+ #define LOG_NEWS LOG_MAIL
236
+ #endif
237
+ #ifndef LOG_UUCP
238
+ #define LOG_UUCP LOG_MAIL
239
+ #endif
240
+ #ifndef LOG_CRON
241
+ #define LOG_CRON LOG_DAEMON
242
+ #endif
243
+
244
+ ins (d , "LOG_SYSLOG" , LOG_SYSLOG );
245
+ ins (d , "LOG_CRON" , LOG_CRON );
246
+ ins (d , "LOG_UUCP" , LOG_UUCP );
247
+ ins (d , "LOG_NEWS" , LOG_NEWS );
248
+
236
249
/* Check for errors */
237
250
if (PyErr_Occurred ())
238
251
Py_FatalError ("can't initialize module syslog" );
0 commit comments