Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4fd26979
Commit
4fd26979
authored
Oct 11, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes by Steve Clift
parent
7a578a67
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
80 deletions
+92
-80
Modules/syslogmodule.c
Modules/syslogmodule.c
+92
-80
No files found.
Modules/syslogmodule.c
View file @
4fd26979
...
@@ -22,6 +22,20 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
...
@@ -22,6 +22,20 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
******************************************************************/
/******************************************************************
Revision history:
95/06/29 (Steve Clift)
- Changed arg parsing to use PyArg_ParseTuple.
- Added PyErr_Clear() call(s) where needed.
- Fix core dumps if user message contains format specifiers.
- Change openlog arg defaults to match normal syslog behaviour.
- Plug memory leak in openlog().
- Fix setlogmask() to return previous mask value.
******************************************************************/
/* syslog module */
/* syslog module */
#include "Python.h"
#include "Python.h"
...
@@ -33,18 +47,21 @@ syslog_openlog(self, args)
...
@@ -33,18 +47,21 @@ syslog_openlog(self, args)
PyObject
*
self
;
PyObject
*
self
;
PyObject
*
args
;
PyObject
*
args
;
{
{
char
*
ident
=
""
;
long
logopt
=
0
;
PyObject
*
ident_o
;
long
logopt
=
LOG_PID
;
long
facility
=
LOG_USER
;
long
facility
=
LOG_USER
;
if
(
!
PyArg_Parse
(
args
,
"(Sll);ident string, logoption, facility"
,
&
ident_o
,
&
logopt
,
&
facility
))
if
(
!
PyArg_Parse
(
args
,
"(Sl);ident string, logoption"
,
&
ident_o
,
&
logopt
))
static
PyObject
*
ident_o
=
NULL
;
if
(
!
PyArg_Parse
(
args
,
"S;ident string"
,
&
ident_o
))
Py_XDECREF
(
ident_o
);
if
(
!
PyArg_ParseTuple
(
args
,
"S|ll;ident string [, logoption [, facility]]"
,
&
ident_o
,
&
logopt
,
&
facility
))
{
return
NULL
;
return
NULL
;
}
Py_INCREF
(
ident_o
);
/* This is needed because openlog() does NOT make a copy
Py_INCREF
(
ident_o
);
/* This is needed because openlog() does NOT make a copy
and syslog() later uses it.. cannot trash it. */
and syslog() later uses it.. cannot trash it. */
ident
=
PyString_AsString
(
ident_o
);
openlog
(
ident
,
logopt
,
facility
);
openlog
(
PyString_AsString
(
ident_o
),
logopt
,
facility
);
Py_INCREF
(
Py_None
);
Py_INCREF
(
Py_None
);
return
Py_None
;
return
Py_None
;
}
}
...
@@ -54,13 +71,17 @@ syslog_syslog(self, args)
...
@@ -54,13 +71,17 @@ syslog_syslog(self, args)
PyObject
*
self
;
PyObject
*
self
;
PyObject
*
args
;
PyObject
*
args
;
{
{
int
priority
=
LOG_INFO
;
char
*
message
,
*
s
;
char
*
message
;
int
priority
=
LOG_INFO
|
LOG_USER
;
if
(
!
PyArg_Parse
(
args
,
"(is);priority, message string"
,
&
priority
,
&
message
))
if
(
!
PyArg_ParseTuple
(
args
,
"is;[priority,] message string"
,
if
(
!
PyArg_Parse
(
args
,
"s;message string"
,
&
message
))
&
priority
,
&
message
))
{
PyErr_Clear
();
if
(
!
PyArg_ParseTuple
(
args
,
"s;[priority,] message string"
,
&
message
))
{
return
NULL
;
return
NULL
;
syslog
(
priority
,
message
);
}
}
syslog
(
priority
,
"%s"
,
message
);
Py_INCREF
(
Py_None
);
Py_INCREF
(
Py_None
);
return
Py_None
;
return
Py_None
;
}
}
...
@@ -70,7 +91,7 @@ syslog_closelog(self, args)
...
@@ -70,7 +91,7 @@ syslog_closelog(self, args)
PyObject
*
self
;
PyObject
*
self
;
PyObject
*
args
;
PyObject
*
args
;
{
{
if
(
!
PyArg_
NoArgs
(
args
))
if
(
!
PyArg_
ParseTuple
(
args
,
""
))
return
NULL
;
return
NULL
;
closelog
();
closelog
();
Py_INCREF
(
Py_None
);
Py_INCREF
(
Py_None
);
...
@@ -82,12 +103,12 @@ syslog_setlogmask(self, args)
...
@@ -82,12 +103,12 @@ syslog_setlogmask(self, args)
PyObject
*
self
;
PyObject
*
self
;
PyObject
*
args
;
PyObject
*
args
;
{
{
long
maskpri
;
long
maskpri
,
omaskpri
;
if
(
!
PyArg_Parse
(
args
,
"l;mask for priority"
,
&
maskpri
))
if
(
!
PyArg_ParseTuple
(
args
,
"l;mask for priority"
,
&
maskpri
))
return
NULL
;
return
NULL
;
setlogmask
(
maskpri
);
omaskpri
=
setlogmask
(
maskpri
);
Py_INCREF
(
Py_None
);
return
PyInt_FromLong
(
omaskpri
);
return
Py_None
;
}
}
static
PyObject
*
static
PyObject
*
...
@@ -97,7 +118,7 @@ syslog_log_mask(self, args)
...
@@ -97,7 +118,7 @@ syslog_log_mask(self, args)
{
{
long
mask
;
long
mask
;
long
pri
;
long
pri
;
if
(
!
PyArg_Parse
(
args
,
"l"
,
&
pri
))
if
(
!
PyArg_Parse
Tuple
(
args
,
"l"
,
&
pri
))
return
NULL
;
return
NULL
;
mask
=
LOG_MASK
(
pri
);
mask
=
LOG_MASK
(
pri
);
return
PyInt_FromLong
(
mask
);
return
PyInt_FromLong
(
mask
);
...
@@ -110,7 +131,7 @@ syslog_log_upto(self, args)
...
@@ -110,7 +131,7 @@ syslog_log_upto(self, args)
{
{
long
mask
;
long
mask
;
long
pri
;
long
pri
;
if
(
!
PyArg_Parse
(
args
,
"l"
,
&
pri
))
if
(
!
PyArg_Parse
Tuple
(
args
,
"l"
,
&
pri
))
return
NULL
;
return
NULL
;
mask
=
LOG_UPTO
(
pri
);
mask
=
LOG_UPTO
(
pri
);
return
PyInt_FromLong
(
mask
);
return
PyInt_FromLong
(
mask
);
...
@@ -119,77 +140,68 @@ syslog_log_upto(self, args)
...
@@ -119,77 +140,68 @@ syslog_log_upto(self, args)
/* List of functions defined in the module */
/* List of functions defined in the module */
static
PyMethodDef
syslog_methods
[]
=
{
static
PyMethodDef
syslog_methods
[]
=
{
{
"openlog"
,
(
PyCFunction
)
syslog_openlog
},
{
"openlog"
,
syslog_openlog
,
METH_VARARGS
},
{
"closelog"
,
(
PyCFunction
)
syslog_closelog
},
{
"closelog"
,
syslog_closelog
,
METH_VARARGS
},
{
"syslog"
,
(
PyCFunction
)
syslog_syslog
},
{
"syslog"
,
syslog_syslog
,
METH_VARARGS
},
{
"setlogmask"
,
(
PyCFunction
)
syslog_setlogmask
},
{
"setlogmask"
,
syslog_setlogmask
,
METH_VARARGS
},
{
"LOG_MASK"
,
(
PyCFunction
)
syslog_log_mask
},
{
"LOG_MASK"
,
syslog_log_mask
,
METH_VARARGS
},
{
"LOG_UPTO"
,
(
PyCFunction
)
syslog_log_upto
},
{
"LOG_UPTO"
,
syslog_log_upto
,
METH_VARARGS
},
{
NULL
,
NULL
}
/* sentinel */
{
NULL
,
NULL
,
0
}
};
};
/* Initialization function for the module */
/* Initialization function for the module */
#define DICT_SET_INT(d, s, x) \
PyDict_SetItemString(d, s, PyInt_FromLong((long) (x)))
void
void
initsyslog
()
initsyslog
()
{
{
PyObject
*
m
,
*
d
,
*
x
;
PyObject
*
m
,
*
d
;
/* Create the module and add the functions */
/* Create the module and add the functions */
m
=
Py_InitModule
(
"syslog"
,
syslog_methods
);
m
=
Py_InitModule
(
"syslog"
,
syslog_methods
);
/* Add some symbolic constants to the module */
/* Add some symbolic constants to the module */
d
=
PyModule_GetDict
(
m
);
d
=
PyModule_GetDict
(
m
);
x
=
PyInt_FromLong
(
LOG_EMERG
);
PyDict_SetItemString
(
d
,
"LOG_EMERG"
,
x
);
/* Priorities */
x
=
PyInt_FromLong
(
LOG_ALERT
);
DICT_SET_INT
(
d
,
"LOG_EMERG"
,
LOG_EMERG
);
PyDict_SetItemString
(
d
,
"LOG_ALERT"
,
x
);
DICT_SET_INT
(
d
,
"LOG_ALERT"
,
LOG_ALERT
);
x
=
PyInt_FromLong
(
LOG_CRIT
);
DICT_SET_INT
(
d
,
"LOG_CRIT"
,
LOG_CRIT
);
PyDict_SetItemString
(
d
,
"LOG_CRIT"
,
x
);
DICT_SET_INT
(
d
,
"LOG_ERR"
,
LOG_ERR
);
x
=
PyInt_FromLong
(
LOG_ERR
);
DICT_SET_INT
(
d
,
"LOG_WARNING"
,
LOG_WARNING
);
PyDict_SetItemString
(
d
,
"LOG_ERR"
,
x
);
DICT_SET_INT
(
d
,
"LOG_NOTICE"
,
LOG_NOTICE
);
x
=
PyInt_FromLong
(
LOG_WARNING
);
DICT_SET_INT
(
d
,
"LOG_INFO"
,
LOG_INFO
);
PyDict_SetItemString
(
d
,
"LOG_WARNING"
,
x
);
DICT_SET_INT
(
d
,
"LOG_DEBUG"
,
LOG_DEBUG
);
x
=
PyInt_FromLong
(
LOG_NOTICE
);
PyDict_SetItemString
(
d
,
"LOG_NOTICE"
,
x
);
/* openlog() option flags */
x
=
PyInt_FromLong
(
LOG_INFO
);
DICT_SET_INT
(
d
,
"LOG_PID"
,
LOG_PID
);
PyDict_SetItemString
(
d
,
"LOG_INFO"
,
x
);
DICT_SET_INT
(
d
,
"LOG_CONS"
,
LOG_CONS
);
x
=
PyInt_FromLong
(
LOG_DEBUG
);
DICT_SET_INT
(
d
,
"LOG_NDELAY"
,
LOG_NDELAY
);
PyDict_SetItemString
(
d
,
"LOG_DEBUG"
,
x
);
DICT_SET_INT
(
d
,
"LOG_NOWAIT"
,
LOG_NOWAIT
);
x
=
PyInt_FromLong
(
LOG_PID
);
#ifdef LOG_PERROR
PyDict_SetItemString
(
d
,
"LOG_PID"
,
x
);
DICT_SET_INT
(
d
,
"LOG_PERROR"
,
LOG_PERROR
);
x
=
PyInt_FromLong
(
LOG_CONS
);
#endif
PyDict_SetItemString
(
d
,
"LOG_CONS"
,
x
);
x
=
PyInt_FromLong
(
LOG_NDELAY
);
/* Facilities */
PyDict_SetItemString
(
d
,
"LOG_NDELAY"
,
x
);
DICT_SET_INT
(
d
,
"LOG_KERN"
,
LOG_KERN
);
x
=
PyInt_FromLong
(
LOG_NOWAIT
);
DICT_SET_INT
(
d
,
"LOG_USER"
,
LOG_USER
);
PyDict_SetItemString
(
d
,
"LOG_NOWAIT"
,
x
);
DICT_SET_INT
(
d
,
"LOG_MAIL"
,
LOG_MAIL
);
x
=
PyInt_FromLong
(
LOG_KERN
);
DICT_SET_INT
(
d
,
"LOG_DAEMON"
,
LOG_DAEMON
);
PyDict_SetItemString
(
d
,
"LOG_KERN"
,
x
);
DICT_SET_INT
(
d
,
"LOG_AUTH"
,
LOG_AUTH
);
x
=
PyInt_FromLong
(
LOG_USER
);
DICT_SET_INT
(
d
,
"LOG_LPR"
,
LOG_LPR
);
PyDict_SetItemString
(
d
,
"LOG_USER"
,
x
);
DICT_SET_INT
(
d
,
"LOG_NEWS"
,
LOG_NEWS
);
x
=
PyInt_FromLong
(
LOG_MAIL
);
DICT_SET_INT
(
d
,
"LOG_UUCP"
,
LOG_UUCP
);
PyDict_SetItemString
(
d
,
"LOG_MAIL"
,
x
);
DICT_SET_INT
(
d
,
"LOG_CRON"
,
LOG_CRON
);
x
=
PyInt_FromLong
(
LOG_DAEMON
);
DICT_SET_INT
(
d
,
"LOG_LOCAL0"
,
LOG_LOCAL0
);
PyDict_SetItemString
(
d
,
"LOG_DAEMON"
,
x
);
DICT_SET_INT
(
d
,
"LOG_LOCAL1"
,
LOG_LOCAL1
);
x
=
PyInt_FromLong
(
LOG_LPR
);
DICT_SET_INT
(
d
,
"LOG_LOCAL2"
,
LOG_LOCAL2
);
PyDict_SetItemString
(
d
,
"LOG_LPR"
,
x
);
DICT_SET_INT
(
d
,
"LOG_LOCAL3"
,
LOG_LOCAL3
);
x
=
PyInt_FromLong
(
LOG_LOCAL0
);
DICT_SET_INT
(
d
,
"LOG_LOCAL4"
,
LOG_LOCAL4
);
PyDict_SetItemString
(
d
,
"LOG_LOCAL0"
,
x
);
DICT_SET_INT
(
d
,
"LOG_LOCAL5"
,
LOG_LOCAL5
);
x
=
PyInt_FromLong
(
LOG_LOCAL1
);
DICT_SET_INT
(
d
,
"LOG_LOCAL6"
,
LOG_LOCAL6
);
PyDict_SetItemString
(
d
,
"LOG_LOCAL1"
,
x
);
DICT_SET_INT
(
d
,
"LOG_LOCAL7"
,
LOG_LOCAL7
);
x
=
PyInt_FromLong
(
LOG_LOCAL2
);
PyDict_SetItemString
(
d
,
"LOG_LOCAL2"
,
x
);
x
=
PyInt_FromLong
(
LOG_LOCAL3
);
PyDict_SetItemString
(
d
,
"LOG_LOCAL3"
,
x
);
x
=
PyInt_FromLong
(
LOG_LOCAL4
);
PyDict_SetItemString
(
d
,
"LOG_LOCAL4"
,
x
);
x
=
PyInt_FromLong
(
LOG_LOCAL5
);
PyDict_SetItemString
(
d
,
"LOG_LOCAL5"
,
x
);
x
=
PyInt_FromLong
(
LOG_LOCAL6
);
PyDict_SetItemString
(
d
,
"LOG_LOCAL6"
,
x
);
x
=
PyInt_FromLong
(
LOG_LOCAL7
);
PyDict_SetItemString
(
d
,
"LOG_LOCAL7"
,
x
);
/* Check for errors */
/* Check for errors */
if
(
PyErr_Occurred
())
if
(
PyErr_Occurred
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment