annotate Modules/syslogmodule.c @ 11239:577ea261bdf2 legacy-trunk

Find the help.txt file relative to __file__ or ".", not in sys.path. (Suggested by Moshe Zadka, but implemented differently.) Add <<python-docs>> event which, on Unix, brings up Netscape pointing to http://www.python.doc/current/ (a local copy would be nice but its location can't be predicted). Windows solution TBD.
author Guido van Rossum <guido@python.org>
date Thu, 26 Aug 1999 23:06:05 +0000
parents 38023a425e48
children dc65c5f6ad7c
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.
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
39 - Change openlog arg defaults to match normal syslog behaviour.
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 *
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 syslog_openlog(self, args)
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
57 PyObject * self;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
58 PyObject * args;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 {
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
60 long logopt = 0;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
61 long facility = LOG_USER;
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
62
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
63
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
64 Py_XDECREF(S_ident_o);
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
65 if (!PyArg_ParseTuple(args,
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
66 "S|ll;ident string [, logoption [, facility]]",
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
67 &S_ident_o, &logopt, &facility))
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
68 return NULL;
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
69
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
70 /* 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
71 * 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
72 */
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
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
75 openlog(PyString_AsString(S_ident_o), logopt, facility);
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
76
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
77 Py_INCREF(Py_None);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
78 return Py_None;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 }
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
81
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
82 static PyObject *
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 syslog_syslog(self, args)
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
84 PyObject * self;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
85 PyObject * args;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 {
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
87 char *message;
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
88 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
89
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
90 if (!PyArg_ParseTuple(args, "is;[priority,] message string",
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
91 &priority, &message)) {
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
92 PyErr_Clear();
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
93 if (!PyArg_ParseTuple(args, "s;[priority,] message string",
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
94 &message))
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
95 return NULL;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
96 }
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
97
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
98 syslog(priority, "%s", message);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
99 Py_INCREF(Py_None);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
100 return Py_None;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 }
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
103 static PyObject *
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 syslog_closelog(self, args)
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
105 PyObject * self;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
106 PyObject * args;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 {
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
108 if (!PyArg_ParseTuple(args, ""))
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 return NULL;
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 closelog();
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
111 Py_XDECREF(S_ident_o);
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
112 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
113 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
114 return Py_None;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 }
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
117 static PyObject *
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 syslog_setlogmask(self, args)
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
119 PyObject * self;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
120 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);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
127 return PyInt_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 *
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 syslog_log_mask(self, args)
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
132 PyObject * self;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
133 PyObject * args;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 {
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
135 long mask;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
136 long pri;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
137 if (!PyArg_ParseTuple(args, "l", &pri))
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
138 return NULL;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
139 mask = LOG_MASK(pri);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
140 return PyInt_FromLong(mask);
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 }
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
143 static PyObject *
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 syslog_log_upto(self, args)
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
145 PyObject * self;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
146 PyObject * args;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 {
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
148 long mask;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
149 long pri;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
150 if (!PyArg_ParseTuple(args, "l", &pri))
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
151 return NULL;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
152 mask = LOG_UPTO(pri);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
153 return PyInt_FromLong(mask);
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 }
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 /* 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
157
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
158 static PyMethodDef syslog_methods[] = {
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
159 {"openlog", syslog_openlog, METH_VARARGS},
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
160 {"closelog", syslog_closelog, METH_VARARGS},
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
161 {"syslog", syslog_syslog, METH_VARARGS},
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
162 {"setlogmask", syslog_setlogmask, METH_VARARGS},
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
163 {"LOG_MASK", syslog_log_mask, METH_VARARGS},
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
164 {"LOG_UPTO", syslog_log_upto, METH_VARARGS},
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
165 {NULL, NULL, 0}
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 };
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
167
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
168 /* helper function for initialization function */
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169
4981
994376af9064 (puremodule.c): New module which exports the Purify and Quantify C API
Barry Warsaw <barry@python.org>
parents: 4921
diff changeset
170 static void
994376af9064 (puremodule.c): New module which exports the Purify and Quantify C API
Barry Warsaw <barry@python.org>
parents: 4921
diff changeset
171 ins(d, s, x)
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
172 PyObject *d;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
173 char *s;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
174 long x;
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
175 {
4981
994376af9064 (puremodule.c): New module which exports the Purify and Quantify C API
Barry Warsaw <barry@python.org>
parents: 4921
diff changeset
176 PyObject *v = PyInt_FromLong(x);
994376af9064 (puremodule.c): New module which exports the Purify and Quantify C API
Barry Warsaw <barry@python.org>
parents: 4921
diff changeset
177 if (v) {
994376af9064 (puremodule.c): New module which exports the Purify and Quantify C API
Barry Warsaw <barry@python.org>
parents: 4921
diff changeset
178 PyDict_SetItemString(d, s, v);
994376af9064 (puremodule.c): New module which exports the Purify and Quantify C API
Barry Warsaw <barry@python.org>
parents: 4921
diff changeset
179 Py_DECREF(v);
994376af9064 (puremodule.c): New module which exports the Purify and Quantify C API
Barry Warsaw <barry@python.org>
parents: 4921
diff changeset
180 }
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
181 }
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
182
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
183 /* Initialization function for the module */
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
184
9588
38023a425e48 Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents: 8823
diff changeset
185 DL_EXPORT(void)
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 initsyslog()
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 {
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
188 PyObject *m, *d;
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
189
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 /* Create the module and add the functions */
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
191 m = Py_InitModule("syslog", syslog_methods);
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
192
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 /* Add some symbolic constants to the module */
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
194 d = PyModule_GetDict(m);
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
195
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
196 /* Priorities */
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
197 ins(d, "LOG_EMERG", LOG_EMERG);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
198 ins(d, "LOG_ALERT", LOG_ALERT);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
199 ins(d, "LOG_CRIT", LOG_CRIT);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
200 ins(d, "LOG_ERR", LOG_ERR);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
201 ins(d, "LOG_WARNING", LOG_WARNING);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
202 ins(d, "LOG_NOTICE", LOG_NOTICE);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
203 ins(d, "LOG_INFO", LOG_INFO);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
204 ins(d, "LOG_DEBUG", LOG_DEBUG);
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
205
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
206 /* openlog() option flags */
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
207 ins(d, "LOG_PID", LOG_PID);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
208 ins(d, "LOG_CONS", LOG_CONS);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
209 ins(d, "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
210 #ifdef LOG_NOWAIT
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
211 ins(d, "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
212 #endif
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
213 #ifdef LOG_PERROR
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
214 ins(d, "LOG_PERROR", LOG_PERROR);
3197
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
215 #endif
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
216
5d16ecae8ee7 changes by Steve Clift
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
217 /* Facilities */
4921
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
218 ins(d, "LOG_KERN", LOG_KERN);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
219 ins(d, "LOG_USER", LOG_USER);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
220 ins(d, "LOG_MAIL", LOG_MAIL);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
221 ins(d, "LOG_DAEMON", LOG_DAEMON);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
222 ins(d, "LOG_AUTH", LOG_AUTH);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
223 ins(d, "LOG_LPR", LOG_LPR);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
224 ins(d, "LOG_LOCAL0", LOG_LOCAL0);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
225 ins(d, "LOG_LOCAL1", LOG_LOCAL1);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
226 ins(d, "LOG_LOCAL2", LOG_LOCAL2);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
227 ins(d, "LOG_LOCAL3", LOG_LOCAL3);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
228 ins(d, "LOG_LOCAL4", LOG_LOCAL4);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
229 ins(d, "LOG_LOCAL5", LOG_LOCAL5);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
230 ins(d, "LOG_LOCAL6", LOG_LOCAL6);
558abac7598d Formatting changes, plus memory management in initsyslog()
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
231 ins(d, "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
232
8286
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
233 #ifndef LOG_SYSLOG
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
234 #define LOG_SYSLOG LOG_DAEMON
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
235 #endif
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
236 #ifndef LOG_NEWS
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
237 #define LOG_NEWS LOG_MAIL
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
238 #endif
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
239 #ifndef LOG_UUCP
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
240 #define LOG_UUCP LOG_MAIL
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
241 #endif
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
242 #ifndef LOG_CRON
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
243 #define LOG_CRON LOG_DAEMON
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
244 #endif
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
245
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
246 ins(d, "LOG_SYSLOG", LOG_SYSLOG);
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
247 ins(d, "LOG_CRON", LOG_CRON);
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
248 ins(d, "LOG_UUCP", LOG_UUCP);
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
249 ins(d, "LOG_NEWS", LOG_NEWS);
4c88cc62e9e9 Fix by Sean Reifschneider:
Guido van Rossum <guido@python.org>
parents: 7115
diff changeset
250
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 /* Check for errors */
1855
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
252 if (PyErr_Occurred())
9dbdb83d4178 Lance has converted his modules to the new naming conventions, and
Guido van Rossum <guido@python.org>
parents: 1737
diff changeset
253 Py_FatalError("can't initialize module syslog");
1737
ee2f88a4f9e2 Added some names to Setup.in, and added syslogmodule.c.
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 }