annotate Modules/syslogmodule.c @ 58689:514b56efd89a 3.1

Merged revisions 77962 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r77962 | r.david.murray | 2010-02-04 11:41:57 -0500 (Thu, 04 Feb 2010) | 17 lines Merged revisions 77943,77959-77960 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77943 | r.david.murray | 2010-02-03 08:36:23 -0500 (Wed, 03 Feb 2010) | 2 lines Explicitly mention the default value for formatdate's usegmt parameter. ........ r77959 | nick.coghlan | 2010-02-04 07:43:58 -0500 (Thu, 04 Feb 2010) | 1 line Issue 6760: Clarify args handling for subprocess.Popen. Patch by Chris Rebert ........ r77960 | r.david.murray | 2010-02-04 11:33:31 -0500 (Thu, 04 Feb 2010) | 2 lines Add Chris Rebert to ACKS for issue 6760 Popen doc improvements. ........ ................
author R. David Murray <rdmurray@bitdance.com>
date Thu, 04 Feb 2010 16:44:31 +0000
parents 85b67fb5672b
children f197407bdba2 562967881dc5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
2 Copyright 1994 by Lance Ellinghouse,
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
3 Cathedral City, California Republic, United States of America.
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
11 supporting documentation, and that the name of Lance Ellinghouse
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
12 not be used in advertising or publicity pertaining to distribution
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
13 of the software without specific, written prior permission.
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
15 LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
17 FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE BE LIABLE FOR ANY SPECIAL,
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
18 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
19 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
20 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
21 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 ******************************************************************/
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
25 /******************************************************************
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
26
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
27 Revision history:
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
28
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
29 1998/04/28 (Sean Reifschneider)
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
30 - When facility not specified to syslog() method, use default from openlog()
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
31 (This is how it was claimed to work in the documentation)
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
32 - Potential resource leak of o_ident, now cleaned up in closelog()
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
33 - Minor comment accuracy fix.
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
34
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
35 95/06/29 (Steve Clift)
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
36 - Changed arg parsing to use PyArg_ParseTuple.
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
37 - Added PyErr_Clear() call(s) where needed.
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
38 - Fix core dumps if user message contains format specifiers.
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 13502
diff changeset
39 - Change openlog arg defaults to match normal syslog behavior.
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
40 - Plug memory leak in openlog().
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
41 - Fix setlogmask() to return previous mask value.
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
42
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
43 ******************************************************************/
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
44
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 /* syslog module */
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
2123
fd5ab7e828fc cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents: 1855
diff changeset
47 #include "Python.h"
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 #include <syslog.h>
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
51 /* only one instance, only one syslog, so globals should be ok */
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
52 static PyObject *S_ident_o = NULL; /* identifier, held by openlog() */
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
53
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
54
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
55 static PyObject *
13502
7348cceee8fa ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 11882
diff changeset
56 syslog_openlog(PyObject * self, PyObject * args)
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 {
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
58 long logopt = 0;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
59 long facility = LOG_USER;
34177
e89b1a240ff7 Backport fixes for bugs #1086555 and #1085744.
Raymond Hettinger <python@rcn.com>
parents: 24471
diff changeset
60 PyObject *new_S_ident_o;
42810
776b8bd68b30 Use unicode and add a "test" for syslog
Neal Norwitz <nnorwitz@gmail.com>
parents: 38669
diff changeset
61 const char *ident;
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
62
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
63 if (!PyArg_ParseTuple(args,
42810
776b8bd68b30 Use unicode and add a "test" for syslog
Neal Norwitz <nnorwitz@gmail.com>
parents: 38669
diff changeset
64 "U|ll;ident string [, logoption [, facility]]",
34177
e89b1a240ff7 Backport fixes for bugs #1086555 and #1085744.
Raymond Hettinger <python@rcn.com>
parents: 24471
diff changeset
65 &new_S_ident_o, &logopt, &facility))
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
66 return NULL;
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
67
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
68 /* This is needed because openlog() does NOT make a copy
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
69 * and syslog() later uses it.. cannot trash it.
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
70 */
34177
e89b1a240ff7 Backport fixes for bugs #1086555 and #1085744.
Raymond Hettinger <python@rcn.com>
parents: 24471
diff changeset
71 Py_XDECREF(S_ident_o);
e89b1a240ff7 Backport fixes for bugs #1086555 and #1085744.
Raymond Hettinger <python@rcn.com>
parents: 24471
diff changeset
72 S_ident_o = new_S_ident_o;
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
73 Py_INCREF(S_ident_o);
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
74
48660
85b67fb5672b Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents: 47580
diff changeset
75 ident = _PyUnicode_AsString(S_ident_o);
42810
776b8bd68b30 Use unicode and add a "test" for syslog
Neal Norwitz <nnorwitz@gmail.com>
parents: 38669
diff changeset
76 if (ident == NULL)
776b8bd68b30 Use unicode and add a "test" for syslog
Neal Norwitz <nnorwitz@gmail.com>
parents: 38669
diff changeset
77 return NULL;
776b8bd68b30 Use unicode and add a "test" for syslog
Neal Norwitz <nnorwitz@gmail.com>
parents: 38669
diff changeset
78 openlog(ident, logopt, facility);
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
79
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
80 Py_INCREF(Py_None);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
81 return Py_None;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 }
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
84
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
85 static PyObject *
13502
7348cceee8fa ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 11882
diff changeset
86 syslog_syslog(PyObject * self, PyObject * args)
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 {
42810
776b8bd68b30 Use unicode and add a "test" for syslog
Neal Norwitz <nnorwitz@gmail.com>
parents: 38669
diff changeset
88 PyObject *message_object;
776b8bd68b30 Use unicode and add a "test" for syslog
Neal Norwitz <nnorwitz@gmail.com>
parents: 38669
diff changeset
89 const char *message;
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
90 int priority = LOG_INFO;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91
42810
776b8bd68b30 Use unicode and add a "test" for syslog
Neal Norwitz <nnorwitz@gmail.com>
parents: 38669
diff changeset
92 if (!PyArg_ParseTuple(args, "iU;[priority,] message string",
42811
2c2e905894a3 Whoops, not sure how I screwed up the name. Now builds and passes the test.
Neal Norwitz <nnorwitz@gmail.com>
parents: 42810
diff changeset
93 &priority, &message_object)) {
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
94 PyErr_Clear();
42810
776b8bd68b30 Use unicode and add a "test" for syslog
Neal Norwitz <nnorwitz@gmail.com>
parents: 38669
diff changeset
95 if (!PyArg_ParseTuple(args, "U;[priority,] message string",
42811
2c2e905894a3 Whoops, not sure how I screwed up the name. Now builds and passes the test.
Neal Norwitz <nnorwitz@gmail.com>
parents: 42810
diff changeset
96 &message_object))
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
97 return NULL;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
98 }
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
99
48660
85b67fb5672b Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents: 47580
diff changeset
100 message = _PyUnicode_AsString(message_object);
42810
776b8bd68b30 Use unicode and add a "test" for syslog
Neal Norwitz <nnorwitz@gmail.com>
parents: 38669
diff changeset
101 if (message == NULL)
776b8bd68b30 Use unicode and add a "test" for syslog
Neal Norwitz <nnorwitz@gmail.com>
parents: 38669
diff changeset
102 return NULL;
45471
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
103 Py_BEGIN_ALLOW_THREADS;
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
104 syslog(priority, "%s", message);
45471
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
105 Py_END_ALLOW_THREADS;
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44099
diff changeset
106 Py_RETURN_NONE;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 }
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
109 static PyObject *
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
110 syslog_closelog(PyObject *self, PyObject *unused)
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 {
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 closelog();
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
113 Py_XDECREF(S_ident_o);
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
114 S_ident_o = NULL;
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
115 Py_INCREF(Py_None);
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
116 return Py_None;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 }
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
119 static PyObject *
13502
7348cceee8fa ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 11882
diff changeset
120 syslog_setlogmask(PyObject *self, PyObject *args)
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 {
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
122 long maskpri, omaskpri;
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
123
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
124 if (!PyArg_ParseTuple(args, "l;mask for priority", &maskpri))
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
125 return NULL;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
126 omaskpri = setlogmask(maskpri);
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 42811
diff changeset
127 return PyLong_FromLong(omaskpri);
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 }
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
130 static PyObject *
13502
7348cceee8fa ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 11882
diff changeset
131 syslog_log_mask(PyObject *self, PyObject *args)
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 {
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
133 long mask;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
134 long pri;
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
135 if (!PyArg_ParseTuple(args, "l:LOG_MASK", &pri))
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
136 return NULL;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
137 mask = LOG_MASK(pri);
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 42811
diff changeset
138 return PyLong_FromLong(mask);
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 }
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
141 static PyObject *
13502
7348cceee8fa ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 11882
diff changeset
142 syslog_log_upto(PyObject *self, PyObject *args)
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 {
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
144 long mask;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
145 long pri;
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
146 if (!PyArg_ParseTuple(args, "l:LOG_UPTO", &pri))
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
147 return NULL;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
148 mask = LOG_UPTO(pri);
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 42811
diff changeset
149 return PyLong_FromLong(mask);
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 }
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
151
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 /* List of functions defined in the module */
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
154 static PyMethodDef syslog_methods[] = {
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
155 {"openlog", syslog_openlog, METH_VARARGS},
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
156 {"closelog", syslog_closelog, METH_NOARGS},
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
157 {"syslog", syslog_syslog, METH_VARARGS},
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
158 {"setlogmask", syslog_setlogmask, METH_VARARGS},
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
159 {"LOG_MASK", syslog_log_mask, METH_VARARGS},
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
160 {"LOG_UPTO", syslog_log_upto, METH_VARARGS},
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
161 {NULL, NULL, 0}
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 };
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
164 /* Initialization function for the module */
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
165
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
166
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
167 static struct PyModuleDef syslogmodule = {
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
168 PyModuleDef_HEAD_INIT,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
169 "syslog",
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
170 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
171 -1,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
172 syslog_methods,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
173 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
174 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
175 NULL,
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
176 NULL
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
177 };
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
178
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 22729
diff changeset
179 PyMODINIT_FUNC
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
180 PyInit_syslog(void)
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 {
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
182 PyObject *m;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
183
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 /* Create the module and add the functions */
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
185 m = PyModule_Create(&syslogmodule);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 34177
diff changeset
186 if (m == NULL)
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
187 return NULL;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
188
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 /* Add some symbolic constants to the module */
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
190
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
191 /* Priorities */
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
192 PyModule_AddIntConstant(m, "LOG_EMERG", LOG_EMERG);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
193 PyModule_AddIntConstant(m, "LOG_ALERT", LOG_ALERT);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
194 PyModule_AddIntConstant(m, "LOG_CRIT", LOG_CRIT);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
195 PyModule_AddIntConstant(m, "LOG_ERR", LOG_ERR);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
196 PyModule_AddIntConstant(m, "LOG_WARNING", LOG_WARNING);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
197 PyModule_AddIntConstant(m, "LOG_NOTICE", LOG_NOTICE);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
198 PyModule_AddIntConstant(m, "LOG_INFO", LOG_INFO);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
199 PyModule_AddIntConstant(m, "LOG_DEBUG", LOG_DEBUG);
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
200
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
201 /* openlog() option flags */
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
202 PyModule_AddIntConstant(m, "LOG_PID", LOG_PID);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
203 PyModule_AddIntConstant(m, "LOG_CONS", LOG_CONS);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
204 PyModule_AddIntConstant(m, "LOG_NDELAY", LOG_NDELAY);
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8286
diff changeset
205 #ifdef LOG_NOWAIT
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
206 PyModule_AddIntConstant(m, "LOG_NOWAIT", LOG_NOWAIT);
8823
f2a4a2b60860 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 8286
diff changeset
207 #endif
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
208 #ifdef LOG_PERROR
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
209 PyModule_AddIntConstant(m, "LOG_PERROR", LOG_PERROR);
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
210 #endif
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
211
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
212 /* Facilities */
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
213 PyModule_AddIntConstant(m, "LOG_KERN", LOG_KERN);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
214 PyModule_AddIntConstant(m, "LOG_USER", LOG_USER);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
215 PyModule_AddIntConstant(m, "LOG_MAIL", LOG_MAIL);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
216 PyModule_AddIntConstant(m, "LOG_DAEMON", LOG_DAEMON);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
217 PyModule_AddIntConstant(m, "LOG_AUTH", LOG_AUTH);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
218 PyModule_AddIntConstant(m, "LOG_LPR", LOG_LPR);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
219 PyModule_AddIntConstant(m, "LOG_LOCAL0", LOG_LOCAL0);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
220 PyModule_AddIntConstant(m, "LOG_LOCAL1", LOG_LOCAL1);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
221 PyModule_AddIntConstant(m, "LOG_LOCAL2", LOG_LOCAL2);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
222 PyModule_AddIntConstant(m, "LOG_LOCAL3", LOG_LOCAL3);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
223 PyModule_AddIntConstant(m, "LOG_LOCAL4", LOG_LOCAL4);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
224 PyModule_AddIntConstant(m, "LOG_LOCAL5", LOG_LOCAL5);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
225 PyModule_AddIntConstant(m, "LOG_LOCAL6", LOG_LOCAL6);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
226 PyModule_AddIntConstant(m, "LOG_LOCAL7", LOG_LOCAL7);
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
227
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
228 #ifndef LOG_SYSLOG
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
229 #define LOG_SYSLOG LOG_DAEMON
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
230 #endif
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
231 #ifndef LOG_NEWS
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
232 #define LOG_NEWS LOG_MAIL
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
233 #endif
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
234 #ifndef LOG_UUCP
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
235 #define LOG_UUCP LOG_MAIL
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
236 #endif
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
237 #ifndef LOG_CRON
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
238 #define LOG_CRON LOG_DAEMON
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
239 #endif
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
240
22729
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
241 PyModule_AddIntConstant(m, "LOG_SYSLOG", LOG_SYSLOG);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
242 PyModule_AddIntConstant(m, "LOG_CRON", LOG_CRON);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
243 PyModule_AddIntConstant(m, "LOG_UUCP", LOG_UUCP);
cdff3c7c1a76 Use the PyModule_Add*() APIs instead of manipulating the module dict
Fred Drake <fdrake@acm.org>
parents: 14346
diff changeset
244 PyModule_AddIntConstant(m, "LOG_NEWS", LOG_NEWS);
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
245 return m;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 }