Debian Codegraph @

Modules/clinic/syslogmodule.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9 #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
10 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
11
12 PyDoc_STRVAR(syslog_openlog__doc__,
13 "openlog($module, /, ident=<unrepresentable>, logoption=0,\n"
14 " facility=LOG_USER)\n"
15 "--\n"
16 "\n"
17 "Set logging options of subsequent syslog() calls.");
18
19 #define SYSLOG_OPENLOG_METHODDEF \
20 {"openlog", _PyCFunction_CAST(syslog_openlog), METH_FASTCALL|METH_KEYWORDS, syslog_openlog__doc__},
21
22 static PyObject *
23 syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt,
24 long facility);
25
26 static PyObject *
27 syslog_openlog(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
28 {
29 PyObject *return_value = NULL;
30 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
31
32 #define NUM_KEYWORDS 3
33 static struct {
34 PyGC_Head _this_is_not_used;
35 PyObject_VAR_HEAD
36 Py_hash_t ob_hash;
37 PyObject *ob_item[NUM_KEYWORDS];
38 } _kwtuple = {
39 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
40 .ob_hash = -1,
41 .ob_item = { &_Py_ID(ident), &_Py_ID(logoption), &_Py_ID(facility), },
42 };
43 #undef NUM_KEYWORDS
44 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
45
46 #else // !Py_BUILD_CORE
47 # define KWTUPLE NULL
48 #endif // !Py_BUILD_CORE
49
50 static const char * const _keywords[] = {"ident", "logoption", "facility", NULL};
51 static _PyArg_Parser _parser = {
52 .keywords = _keywords,
53 .fname = "openlog",
54 .kwtuple = KWTUPLE,
55 };
56 #undef KWTUPLE
57 PyObject *argsbuf[3];
58 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
59 PyObject *ident = NULL;
60 long logopt = 0;
61 long facility = LOG_USER;
62
63 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
64 /*minpos*/ 0, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
65 if (!args) {
66 goto exit;
67 }
68 if (!noptargs) {
69 goto skip_optional_pos;
70 }
71 if (args[0]) {
72 if (!PyUnicode_Check(args[0])) {
73 _PyArg_BadArgument("openlog", "argument 'ident'", "str", args[0]);
74 goto exit;
75 }
76 ident = args[0];
77 if (!--noptargs) {
78 goto skip_optional_pos;
79 }
80 }
81 if (args[1]) {
82 logopt = PyLong_AsLong(args[1]);
83 if (logopt == -1 && PyErr_Occurred()) {
84 goto exit;
85 }
86 if (!--noptargs) {
87 goto skip_optional_pos;
88 }
89 }
90 facility = PyLong_AsLong(args[2]);
91 if (facility == -1 && PyErr_Occurred()) {
92 goto exit;
93 }
94 skip_optional_pos:
95 Py_BEGIN_CRITICAL_SECTION(module);
96 return_value = syslog_openlog_impl(module, ident, logopt, facility);
97 Py_END_CRITICAL_SECTION();
98
99 exit:
100 return return_value;
101 }
102
103 PyDoc_STRVAR(syslog_syslog__doc__,
104 "syslog([priority=LOG_INFO,] message)\n"
105 "Send the string message to the system logger.");
106
107 #define SYSLOG_SYSLOG_METHODDEF \
108 {"syslog", (PyCFunction)syslog_syslog, METH_VARARGS, syslog_syslog__doc__},
109
110 static PyObject *
111 syslog_syslog_impl(PyObject *module, int group_left_1, int priority,
112 const char *message);
113
114 static PyObject *
115 syslog_syslog(PyObject *module, PyObject *args)
116 {
117 PyObject *return_value = NULL;
118 int group_left_1 = 0;
119 int priority = LOG_INFO;
120 const char *message;
121
122 switch (PyTuple_GET_SIZE(args)) {
123 case 1:
124 if (!PyArg_ParseTuple(args, "s:syslog", &message)) {
125 goto exit;
126 }
127 break;
128 case 2:
129 if (!PyArg_ParseTuple(args, "is:syslog", &priority, &message)) {
130 goto exit;
131 }
132 group_left_1 = 1;
133 break;
134 default:
135 PyErr_SetString(PyExc_TypeError, "syslog.syslog requires 1 to 2 arguments");
136 goto exit;
137 }
138 Py_BEGIN_CRITICAL_SECTION(module);
139 return_value = syslog_syslog_impl(module, group_left_1, priority, message);
140 Py_END_CRITICAL_SECTION();
141
142 exit:
143 return return_value;
144 }
145
146 PyDoc_STRVAR(syslog_closelog__doc__,
147 "closelog($module, /)\n"
148 "--\n"
149 "\n"
150 "Reset the syslog module values and call the system library closelog().");
151
152 #define SYSLOG_CLOSELOG_METHODDEF \
153 {"closelog", (PyCFunction)syslog_closelog, METH_NOARGS, syslog_closelog__doc__},
154
155 static PyObject *
156 syslog_closelog_impl(PyObject *module);
157
158 static PyObject *
159 syslog_closelog(PyObject *module, PyObject *Py_UNUSED(ignored))
160 {
161 PyObject *return_value = NULL;
162
163 Py_BEGIN_CRITICAL_SECTION(module);
164 return_value = syslog_closelog_impl(module);
165 Py_END_CRITICAL_SECTION();
166
167 return return_value;
168 }
169
170 PyDoc_STRVAR(syslog_setlogmask__doc__,
171 "setlogmask($module, maskpri, /)\n"
172 "--\n"
173 "\n"
174 "Set the priority mask to maskpri and return the previous mask value.");
175
176 #define SYSLOG_SETLOGMASK_METHODDEF \
177 {"setlogmask", (PyCFunction)syslog_setlogmask, METH_O, syslog_setlogmask__doc__},
178
179 static long
180 syslog_setlogmask_impl(PyObject *module, long maskpri);
181
182 static PyObject *
183 syslog_setlogmask(PyObject *module, PyObject *arg)
184 {
185 PyObject *return_value = NULL;
186 long maskpri;
187 long _return_value;
188
189 maskpri = PyLong_AsLong(arg);
190 if (maskpri == -1 && PyErr_Occurred()) {
191 goto exit;
192 }
193 _return_value = syslog_setlogmask_impl(module, maskpri);
194 if ((_return_value == -1) && PyErr_Occurred()) {
195 goto exit;
196 }
197 return_value = PyLong_FromLong(_return_value);
198
199 exit:
200 return return_value;
201 }
202
203 PyDoc_STRVAR(syslog_LOG_MASK__doc__,
204 "LOG_MASK($module, pri, /)\n"
205 "--\n"
206 "\n"
207 "Calculates the mask for the individual priority pri.");
208
209 #define SYSLOG_LOG_MASK_METHODDEF \
210 {"LOG_MASK", (PyCFunction)syslog_LOG_MASK, METH_O, syslog_LOG_MASK__doc__},
211
212 static long
213 syslog_LOG_MASK_impl(PyObject *module, long pri);
214
215 static PyObject *
216 syslog_LOG_MASK(PyObject *module, PyObject *arg)
217 {
218 PyObject *return_value = NULL;
219 long pri;
220 long _return_value;
221
222 pri = PyLong_AsLong(arg);
223 if (pri == -1 && PyErr_Occurred()) {
224 goto exit;
225 }
226 _return_value = syslog_LOG_MASK_impl(module, pri);
227 if ((_return_value == -1) && PyErr_Occurred()) {
228 goto exit;
229 }
230 return_value = PyLong_FromLong(_return_value);
231
232 exit:
233 return return_value;
234 }
235
236 PyDoc_STRVAR(syslog_LOG_UPTO__doc__,
237 "LOG_UPTO($module, pri, /)\n"
238 "--\n"
239 "\n"
240 "Calculates the mask for all priorities up to and including pri.");
241
242 #define SYSLOG_LOG_UPTO_METHODDEF \
243 {"LOG_UPTO", (PyCFunction)syslog_LOG_UPTO, METH_O, syslog_LOG_UPTO__doc__},
244
245 static long
246 syslog_LOG_UPTO_impl(PyObject *module, long pri);
247
248 static PyObject *
249 syslog_LOG_UPTO(PyObject *module, PyObject *arg)
250 {
251 PyObject *return_value = NULL;
252 long pri;
253 long _return_value;
254
255 pri = PyLong_AsLong(arg);
256 if (pri == -1 && PyErr_Occurred()) {
257 goto exit;
258 }
259 _return_value = syslog_LOG_UPTO_impl(module, pri);
260 if ((_return_value == -1) && PyErr_Occurred()) {
261 goto exit;
262 }
263 return_value = PyLong_FromLong(_return_value);
264
265 exit:
266 return return_value;
267 }
268 /*[clinic end generated code: output=f92ac9948fa6131e input=a9049054013a1b77]*/