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