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
10
11 PyDoc_STRVAR(syslog_openlog__doc__,
12 "openlog($module, /, ident=<unrepresentable>, logoption=0,\n"
13 " facility=LOG_USER)\n"
14 "--\n"
15 "\n"
16 "Set logging options of subsequent syslog() calls.");
17
18 #define SYSLOG_OPENLOG_METHODDEF \
19 {"openlog", _PyCFunction_CAST(syslog_openlog), METH_FASTCALL|METH_KEYWORDS, syslog_openlog__doc__},
20
21 static PyObject *
22 syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt,
23 long facility);
24
25 static PyObject *
26 syslog_openlog(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
27 {
28 PyObject *return_value = NULL;
29 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
30
31 #define NUM_KEYWORDS 3
32 static struct {
33 PyGC_Head _this_is_not_used;
34 PyObject_VAR_HEAD
35 PyObject *ob_item[NUM_KEYWORDS];
36 } _kwtuple = {
37 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
38 .ob_item = { &_Py_ID(ident), &_Py_ID(logoption), &_Py_ID(facility), },
39 };
40 #undef NUM_KEYWORDS
41 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
42
43 #else // !Py_BUILD_CORE
44 # define KWTUPLE NULL
45 #endif // !Py_BUILD_CORE
46
47 static const char * const _keywords[] = {"ident", "logoption", "facility", NULL};
48 static _PyArg_Parser _parser = {
49 .keywords = _keywords,
50 .fname = "openlog",
51 .kwtuple = KWTUPLE,
52 };
53 #undef KWTUPLE
54 PyObject *argsbuf[3];
55 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
56 PyObject *ident = NULL;
57 long logopt = 0;
58 long facility = LOG_USER;
59
60 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 3, 0, argsbuf);
61 if (!args) {
62 goto exit;
63 }
64 if (!noptargs) {
65 goto skip_optional_pos;
66 }
67 if (args[0]) {
68 if (!PyUnicode_Check(args[0])) {
69 _PyArg_BadArgument("openlog", "argument 'ident'", "str", args[0]);
70 goto exit;
71 }
72 if (PyUnicode_READY(args[0]) == -1) {
73 goto exit;
74 }
75 ident = args[0];
76 if (!--noptargs) {
77 goto skip_optional_pos;
78 }
79 }
80 if (args[1]) {
81 logopt = PyLong_AsLong(args[1]);
82 if (logopt == -1 && PyErr_Occurred()) {
83 goto exit;
84 }
85 if (!--noptargs) {
86 goto skip_optional_pos;
87 }
88 }
89 facility = PyLong_AsLong(args[2]);
90 if (facility == -1 && PyErr_Occurred()) {
91 goto exit;
92 }
93 skip_optional_pos:
94 return_value = syslog_openlog_impl(module, ident, logopt, facility);
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 *
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 return_value = syslog_syslog_impl(module, group_left_1, priority, message);
136
137 exit:
138 return return_value;
139 }
140
141 PyDoc_STRVAR(syslog_closelog__doc__,
142 "closelog($module, /)\n"
143 "--\n"
144 "\n"
145 "Reset the syslog module values and call the system library closelog().");
146
147 #define SYSLOG_CLOSELOG_METHODDEF \
148 {"closelog", (PyCFunction)syslog_closelog, METH_NOARGS, syslog_closelog__doc__},
149
150 static PyObject *
151 syslog_closelog_impl(PyObject *module);
152
153 static PyObject *
154 syslog_closelog(PyObject *module, PyObject *Py_UNUSED(ignored))
155 {
156 return syslog_closelog_impl(module);
157 }
158
159 PyDoc_STRVAR(syslog_setlogmask__doc__,
160 "setlogmask($module, maskpri, /)\n"
161 "--\n"
162 "\n"
163 "Set the priority mask to maskpri and return the previous mask value.");
164
165 #define SYSLOG_SETLOGMASK_METHODDEF \
166 {"setlogmask", (PyCFunction)syslog_setlogmask, METH_O, syslog_setlogmask__doc__},
167
168 static long
169 syslog_setlogmask_impl(PyObject *module, long maskpri);
170
171 static PyObject *
172 syslog_setlogmask(PyObject *module, PyObject *arg)
173 {
174 PyObject *return_value = NULL;
175 long maskpri;
176 long _return_value;
177
178 maskpri = PyLong_AsLong(arg);
179 if (maskpri == -1 && PyErr_Occurred()) {
180 goto exit;
181 }
182 _return_value = syslog_setlogmask_impl(module, maskpri);
183 if ((_return_value == -1) && PyErr_Occurred()) {
184 goto exit;
185 }
186 return_value = PyLong_FromLong(_return_value);
187
188 exit:
189 return return_value;
190 }
191
192 PyDoc_STRVAR(syslog_LOG_MASK__doc__,
193 "LOG_MASK($module, pri, /)\n"
194 "--\n"
195 "\n"
196 "Calculates the mask for the individual priority pri.");
197
198 #define SYSLOG_LOG_MASK_METHODDEF \
199 {"LOG_MASK", (PyCFunction)syslog_LOG_MASK, METH_O, syslog_LOG_MASK__doc__},
200
201 static long
202 syslog_LOG_MASK_impl(PyObject *module, long pri);
203
204 static PyObject *
205 syslog_LOG_MASK(PyObject *module, PyObject *arg)
206 {
207 PyObject *return_value = NULL;
208 long pri;
209 long _return_value;
210
211 pri = PyLong_AsLong(arg);
212 if (pri == -1 && PyErr_Occurred()) {
213 goto exit;
214 }
215 _return_value = syslog_LOG_MASK_impl(module, pri);
216 if ((_return_value == -1) && PyErr_Occurred()) {
217 goto exit;
218 }
219 return_value = PyLong_FromLong(_return_value);
220
221 exit:
222 return return_value;
223 }
224
225 PyDoc_STRVAR(syslog_LOG_UPTO__doc__,
226 "LOG_UPTO($module, pri, /)\n"
227 "--\n"
228 "\n"
229 "Calculates the mask for all priorities up to and including pri.");
230
231 #define SYSLOG_LOG_UPTO_METHODDEF \
232 {"LOG_UPTO", (PyCFunction)syslog_LOG_UPTO, METH_O, syslog_LOG_UPTO__doc__},
233
234 static long
235 syslog_LOG_UPTO_impl(PyObject *module, long pri);
236
237 static PyObject *
238 syslog_LOG_UPTO(PyObject *module, PyObject *arg)
239 {
240 PyObject *return_value = NULL;
241 long pri;
242 long _return_value;
243
244 pri = PyLong_AsLong(arg);
245 if (pri == -1 && PyErr_Occurred()) {
246 goto exit;
247 }
248 _return_value = syslog_LOG_UPTO_impl(module, pri);
249 if ((_return_value == -1) && PyErr_Occurred()) {
250 goto exit;
251 }
252 return_value = PyLong_FromLong(_return_value);
253
254 exit:
255 return return_value;
256 }
257 /*[clinic end generated code: output=3b1bdb16565b8fda input=a9049054013a1b77]*/