/src/cpython/Modules/clinic/signalmodule.c.h
Line | Count | Source |
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_modsupport.h" // _PyArg_CheckPositional() |
10 | | |
11 | | PyDoc_STRVAR(signal_default_int_handler__doc__, |
12 | | "default_int_handler($module, signalnum, frame, /)\n" |
13 | | "--\n" |
14 | | "\n" |
15 | | "The default handler for SIGINT installed by Python.\n" |
16 | | "\n" |
17 | | "It raises KeyboardInterrupt."); |
18 | | |
19 | | #define SIGNAL_DEFAULT_INT_HANDLER_METHODDEF \ |
20 | | {"default_int_handler", _PyCFunction_CAST(signal_default_int_handler), METH_FASTCALL, signal_default_int_handler__doc__}, |
21 | | |
22 | | static PyObject * |
23 | | signal_default_int_handler_impl(PyObject *module, int signalnum, |
24 | | PyObject *frame); |
25 | | |
26 | | static PyObject * |
27 | | signal_default_int_handler(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
28 | 0 | { |
29 | 0 | PyObject *return_value = NULL; |
30 | 0 | int signalnum; |
31 | 0 | PyObject *frame; |
32 | |
|
33 | 0 | if (!_PyArg_CheckPositional("default_int_handler", nargs, 2, 2)) { |
34 | 0 | goto exit; |
35 | 0 | } |
36 | 0 | signalnum = PyLong_AsInt(args[0]); |
37 | 0 | if (signalnum == -1 && PyErr_Occurred()) { |
38 | 0 | goto exit; |
39 | 0 | } |
40 | 0 | frame = args[1]; |
41 | 0 | return_value = signal_default_int_handler_impl(module, signalnum, frame); |
42 | |
|
43 | 0 | exit: |
44 | 0 | return return_value; |
45 | 0 | } |
46 | | |
47 | | #if defined(HAVE_ALARM) |
48 | | |
49 | | PyDoc_STRVAR(signal_alarm__doc__, |
50 | | "alarm($module, seconds, /)\n" |
51 | | "--\n" |
52 | | "\n" |
53 | | "Arrange for SIGALRM to arrive after the given number of seconds."); |
54 | | |
55 | | #define SIGNAL_ALARM_METHODDEF \ |
56 | | {"alarm", (PyCFunction)signal_alarm, METH_O, signal_alarm__doc__}, |
57 | | |
58 | | static long |
59 | | signal_alarm_impl(PyObject *module, int seconds); |
60 | | |
61 | | static PyObject * |
62 | | signal_alarm(PyObject *module, PyObject *arg) |
63 | 0 | { |
64 | 0 | PyObject *return_value = NULL; |
65 | 0 | int seconds; |
66 | 0 | long _return_value; |
67 | |
|
68 | 0 | seconds = PyLong_AsInt(arg); |
69 | 0 | if (seconds == -1 && PyErr_Occurred()) { |
70 | 0 | goto exit; |
71 | 0 | } |
72 | 0 | _return_value = signal_alarm_impl(module, seconds); |
73 | 0 | if ((_return_value == -1) && PyErr_Occurred()) { |
74 | 0 | goto exit; |
75 | 0 | } |
76 | 0 | return_value = PyLong_FromLong(_return_value); |
77 | |
|
78 | 0 | exit: |
79 | 0 | return return_value; |
80 | 0 | } |
81 | | |
82 | | #endif /* defined(HAVE_ALARM) */ |
83 | | |
84 | | #if defined(HAVE_PAUSE) |
85 | | |
86 | | PyDoc_STRVAR(signal_pause__doc__, |
87 | | "pause($module, /)\n" |
88 | | "--\n" |
89 | | "\n" |
90 | | "Wait until a signal arrives."); |
91 | | |
92 | | #define SIGNAL_PAUSE_METHODDEF \ |
93 | | {"pause", (PyCFunction)signal_pause, METH_NOARGS, signal_pause__doc__}, |
94 | | |
95 | | static PyObject * |
96 | | signal_pause_impl(PyObject *module); |
97 | | |
98 | | static PyObject * |
99 | | signal_pause(PyObject *module, PyObject *Py_UNUSED(ignored)) |
100 | 0 | { |
101 | 0 | return signal_pause_impl(module); |
102 | 0 | } |
103 | | |
104 | | #endif /* defined(HAVE_PAUSE) */ |
105 | | |
106 | | PyDoc_STRVAR(signal_raise_signal__doc__, |
107 | | "raise_signal($module, signalnum, /)\n" |
108 | | "--\n" |
109 | | "\n" |
110 | | "Send a signal to the executing process."); |
111 | | |
112 | | #define SIGNAL_RAISE_SIGNAL_METHODDEF \ |
113 | | {"raise_signal", (PyCFunction)signal_raise_signal, METH_O, signal_raise_signal__doc__}, |
114 | | |
115 | | static PyObject * |
116 | | signal_raise_signal_impl(PyObject *module, int signalnum); |
117 | | |
118 | | static PyObject * |
119 | | signal_raise_signal(PyObject *module, PyObject *arg) |
120 | 0 | { |
121 | 0 | PyObject *return_value = NULL; |
122 | 0 | int signalnum; |
123 | |
|
124 | 0 | signalnum = PyLong_AsInt(arg); |
125 | 0 | if (signalnum == -1 && PyErr_Occurred()) { |
126 | 0 | goto exit; |
127 | 0 | } |
128 | 0 | return_value = signal_raise_signal_impl(module, signalnum); |
129 | |
|
130 | 0 | exit: |
131 | 0 | return return_value; |
132 | 0 | } |
133 | | |
134 | | PyDoc_STRVAR(signal_signal__doc__, |
135 | | "signal($module, signalnum, handler, /)\n" |
136 | | "--\n" |
137 | | "\n" |
138 | | "Set the action for the given signal.\n" |
139 | | "\n" |
140 | | "The action can be SIG_DFL, SIG_IGN, or a callable Python object.\n" |
141 | | "The previous action is returned. See getsignal() for possible return\n" |
142 | | "values.\n" |
143 | | "\n" |
144 | | "*** IMPORTANT NOTICE ***\n" |
145 | | "A signal handler function is called with two arguments: the first is\n" |
146 | | "the signal number, the second is the interrupted stack frame."); |
147 | | |
148 | | #define SIGNAL_SIGNAL_METHODDEF \ |
149 | | {"signal", _PyCFunction_CAST(signal_signal), METH_FASTCALL, signal_signal__doc__}, |
150 | | |
151 | | static PyObject * |
152 | | signal_signal_impl(PyObject *module, int signalnum, PyObject *handler); |
153 | | |
154 | | static PyObject * |
155 | | signal_signal(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
156 | 0 | { |
157 | 0 | PyObject *return_value = NULL; |
158 | 0 | int signalnum; |
159 | 0 | PyObject *handler; |
160 | |
|
161 | 0 | if (!_PyArg_CheckPositional("signal", nargs, 2, 2)) { |
162 | 0 | goto exit; |
163 | 0 | } |
164 | 0 | signalnum = PyLong_AsInt(args[0]); |
165 | 0 | if (signalnum == -1 && PyErr_Occurred()) { |
166 | 0 | goto exit; |
167 | 0 | } |
168 | 0 | handler = args[1]; |
169 | 0 | return_value = signal_signal_impl(module, signalnum, handler); |
170 | |
|
171 | 0 | exit: |
172 | 0 | return return_value; |
173 | 0 | } |
174 | | |
175 | | PyDoc_STRVAR(signal_getsignal__doc__, |
176 | | "getsignal($module, signalnum, /)\n" |
177 | | "--\n" |
178 | | "\n" |
179 | | "Return the current action for the given signal.\n" |
180 | | "\n" |
181 | | "The return value can be:\n" |
182 | | " SIG_IGN -- if the signal is being ignored\n" |
183 | | " SIG_DFL -- if the default action for the signal is in effect\n" |
184 | | " None -- if an unknown handler is in effect\n" |
185 | | " anything else -- the callable Python object used as a handler"); |
186 | | |
187 | | #define SIGNAL_GETSIGNAL_METHODDEF \ |
188 | | {"getsignal", (PyCFunction)signal_getsignal, METH_O, signal_getsignal__doc__}, |
189 | | |
190 | | static PyObject * |
191 | | signal_getsignal_impl(PyObject *module, int signalnum); |
192 | | |
193 | | static PyObject * |
194 | | signal_getsignal(PyObject *module, PyObject *arg) |
195 | 0 | { |
196 | 0 | PyObject *return_value = NULL; |
197 | 0 | int signalnum; |
198 | |
|
199 | 0 | signalnum = PyLong_AsInt(arg); |
200 | 0 | if (signalnum == -1 && PyErr_Occurred()) { |
201 | 0 | goto exit; |
202 | 0 | } |
203 | 0 | return_value = signal_getsignal_impl(module, signalnum); |
204 | |
|
205 | 0 | exit: |
206 | 0 | return return_value; |
207 | 0 | } |
208 | | |
209 | | PyDoc_STRVAR(signal_strsignal__doc__, |
210 | | "strsignal($module, signalnum, /)\n" |
211 | | "--\n" |
212 | | "\n" |
213 | | "Return the system description of the given signal.\n" |
214 | | "\n" |
215 | | "Returns the description of signal *signalnum*, such as \"Interrupt\"\n" |
216 | | "for :const:`SIGINT`. Returns :const:`None` if *signalnum* has no\n" |
217 | | "description. Raises :exc:`ValueError` if *signalnum* is invalid."); |
218 | | |
219 | | #define SIGNAL_STRSIGNAL_METHODDEF \ |
220 | | {"strsignal", (PyCFunction)signal_strsignal, METH_O, signal_strsignal__doc__}, |
221 | | |
222 | | static PyObject * |
223 | | signal_strsignal_impl(PyObject *module, int signalnum); |
224 | | |
225 | | static PyObject * |
226 | | signal_strsignal(PyObject *module, PyObject *arg) |
227 | 0 | { |
228 | 0 | PyObject *return_value = NULL; |
229 | 0 | int signalnum; |
230 | |
|
231 | 0 | signalnum = PyLong_AsInt(arg); |
232 | 0 | if (signalnum == -1 && PyErr_Occurred()) { |
233 | 0 | goto exit; |
234 | 0 | } |
235 | 0 | return_value = signal_strsignal_impl(module, signalnum); |
236 | |
|
237 | 0 | exit: |
238 | 0 | return return_value; |
239 | 0 | } |
240 | | |
241 | | #if defined(HAVE_SIGINTERRUPT) |
242 | | |
243 | | PyDoc_STRVAR(signal_siginterrupt__doc__, |
244 | | "siginterrupt($module, signalnum, flag, /)\n" |
245 | | "--\n" |
246 | | "\n" |
247 | | "Change system call restart behaviour.\n" |
248 | | "\n" |
249 | | "If flag is False, system calls will be restarted when interrupted by\n" |
250 | | "signal sig, else system calls will be interrupted."); |
251 | | |
252 | | #define SIGNAL_SIGINTERRUPT_METHODDEF \ |
253 | | {"siginterrupt", _PyCFunction_CAST(signal_siginterrupt), METH_FASTCALL, signal_siginterrupt__doc__}, |
254 | | |
255 | | static PyObject * |
256 | | signal_siginterrupt_impl(PyObject *module, int signalnum, int flag); |
257 | | |
258 | | static PyObject * |
259 | | signal_siginterrupt(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
260 | 0 | { |
261 | 0 | PyObject *return_value = NULL; |
262 | 0 | int signalnum; |
263 | 0 | int flag; |
264 | |
|
265 | 0 | if (!_PyArg_CheckPositional("siginterrupt", nargs, 2, 2)) { |
266 | 0 | goto exit; |
267 | 0 | } |
268 | 0 | signalnum = PyLong_AsInt(args[0]); |
269 | 0 | if (signalnum == -1 && PyErr_Occurred()) { |
270 | 0 | goto exit; |
271 | 0 | } |
272 | 0 | flag = PyLong_AsInt(args[1]); |
273 | 0 | if (flag == -1 && PyErr_Occurred()) { |
274 | 0 | goto exit; |
275 | 0 | } |
276 | 0 | return_value = signal_siginterrupt_impl(module, signalnum, flag); |
277 | |
|
278 | 0 | exit: |
279 | 0 | return return_value; |
280 | 0 | } |
281 | | |
282 | | #endif /* defined(HAVE_SIGINTERRUPT) */ |
283 | | |
284 | | PyDoc_STRVAR(signal_set_wakeup_fd__doc__, |
285 | | "set_wakeup_fd($module, fd, /, *, warn_on_full_buffer=True)\n" |
286 | | "--\n" |
287 | | "\n" |
288 | | "Sets the fd to be written to (with the signal number) when a signal comes in.\n" |
289 | | "\n" |
290 | | "A library can use this to wakeup select or poll.\n" |
291 | | "The previous fd or -1 is returned.\n" |
292 | | "\n" |
293 | | "The fd must be non-blocking."); |
294 | | |
295 | | #define SIGNAL_SET_WAKEUP_FD_METHODDEF \ |
296 | | {"set_wakeup_fd", _PyCFunction_CAST(signal_set_wakeup_fd), METH_FASTCALL|METH_KEYWORDS, signal_set_wakeup_fd__doc__}, |
297 | | |
298 | | static PyObject * |
299 | | signal_set_wakeup_fd_impl(PyObject *module, PyObject *fdobj, |
300 | | int warn_on_full_buffer); |
301 | | |
302 | | static PyObject * |
303 | | signal_set_wakeup_fd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
304 | 0 | { |
305 | 0 | PyObject *return_value = NULL; |
306 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
307 | |
|
308 | 0 | #define NUM_KEYWORDS 1 |
309 | 0 | static struct { |
310 | 0 | PyGC_Head _this_is_not_used; |
311 | 0 | PyObject_VAR_HEAD |
312 | 0 | Py_hash_t ob_hash; |
313 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
314 | 0 | } _kwtuple = { |
315 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
316 | 0 | .ob_hash = -1, |
317 | 0 | .ob_item = { &_Py_ID(warn_on_full_buffer), }, |
318 | 0 | }; |
319 | 0 | #undef NUM_KEYWORDS |
320 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
321 | |
|
322 | | #else // !Py_BUILD_CORE |
323 | | # define KWTUPLE NULL |
324 | | #endif // !Py_BUILD_CORE |
325 | |
|
326 | 0 | static const char * const _keywords[] = {"", "warn_on_full_buffer", NULL}; |
327 | 0 | static _PyArg_Parser _parser = { |
328 | 0 | .keywords = _keywords, |
329 | 0 | .fname = "set_wakeup_fd", |
330 | 0 | .kwtuple = KWTUPLE, |
331 | 0 | }; |
332 | 0 | #undef KWTUPLE |
333 | 0 | PyObject *argsbuf[2]; |
334 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
335 | 0 | PyObject *fdobj; |
336 | 0 | int warn_on_full_buffer = 1; |
337 | |
|
338 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
339 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
340 | 0 | if (!args) { |
341 | 0 | goto exit; |
342 | 0 | } |
343 | 0 | fdobj = args[0]; |
344 | 0 | if (!noptargs) { |
345 | 0 | goto skip_optional_kwonly; |
346 | 0 | } |
347 | 0 | warn_on_full_buffer = PyObject_IsTrue(args[1]); |
348 | 0 | if (warn_on_full_buffer < 0) { |
349 | 0 | goto exit; |
350 | 0 | } |
351 | 0 | skip_optional_kwonly: |
352 | 0 | return_value = signal_set_wakeup_fd_impl(module, fdobj, warn_on_full_buffer); |
353 | |
|
354 | 0 | exit: |
355 | 0 | return return_value; |
356 | 0 | } |
357 | | |
358 | | #if defined(HAVE_SETITIMER) |
359 | | |
360 | | PyDoc_STRVAR(signal_setitimer__doc__, |
361 | | "setitimer($module, which, seconds, interval=0.0, /)\n" |
362 | | "--\n" |
363 | | "\n" |
364 | | "Sets given itimer (one of ITIMER_REAL, ITIMER_VIRTUAL or ITIMER_PROF).\n" |
365 | | "\n" |
366 | | "The timer will fire after value seconds and after that every interval\n" |
367 | | "seconds. The itimer can be cleared by setting seconds to zero.\n" |
368 | | "\n" |
369 | | "Returns old values as a tuple: (delay, interval)."); |
370 | | |
371 | | #define SIGNAL_SETITIMER_METHODDEF \ |
372 | | {"setitimer", _PyCFunction_CAST(signal_setitimer), METH_FASTCALL, signal_setitimer__doc__}, |
373 | | |
374 | | static PyObject * |
375 | | signal_setitimer_impl(PyObject *module, int which, PyObject *seconds, |
376 | | PyObject *interval); |
377 | | |
378 | | static PyObject * |
379 | | signal_setitimer(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
380 | 0 | { |
381 | 0 | PyObject *return_value = NULL; |
382 | 0 | int which; |
383 | 0 | PyObject *seconds; |
384 | 0 | PyObject *interval = NULL; |
385 | |
|
386 | 0 | if (!_PyArg_CheckPositional("setitimer", nargs, 2, 3)) { |
387 | 0 | goto exit; |
388 | 0 | } |
389 | 0 | which = PyLong_AsInt(args[0]); |
390 | 0 | if (which == -1 && PyErr_Occurred()) { |
391 | 0 | goto exit; |
392 | 0 | } |
393 | 0 | seconds = args[1]; |
394 | 0 | if (nargs < 3) { |
395 | 0 | goto skip_optional; |
396 | 0 | } |
397 | 0 | interval = args[2]; |
398 | 0 | skip_optional: |
399 | 0 | return_value = signal_setitimer_impl(module, which, seconds, interval); |
400 | |
|
401 | 0 | exit: |
402 | 0 | return return_value; |
403 | 0 | } |
404 | | |
405 | | #endif /* defined(HAVE_SETITIMER) */ |
406 | | |
407 | | #if defined(HAVE_GETITIMER) |
408 | | |
409 | | PyDoc_STRVAR(signal_getitimer__doc__, |
410 | | "getitimer($module, which, /)\n" |
411 | | "--\n" |
412 | | "\n" |
413 | | "Returns current value of given itimer."); |
414 | | |
415 | | #define SIGNAL_GETITIMER_METHODDEF \ |
416 | | {"getitimer", (PyCFunction)signal_getitimer, METH_O, signal_getitimer__doc__}, |
417 | | |
418 | | static PyObject * |
419 | | signal_getitimer_impl(PyObject *module, int which); |
420 | | |
421 | | static PyObject * |
422 | | signal_getitimer(PyObject *module, PyObject *arg) |
423 | 0 | { |
424 | 0 | PyObject *return_value = NULL; |
425 | 0 | int which; |
426 | |
|
427 | 0 | which = PyLong_AsInt(arg); |
428 | 0 | if (which == -1 && PyErr_Occurred()) { |
429 | 0 | goto exit; |
430 | 0 | } |
431 | 0 | return_value = signal_getitimer_impl(module, which); |
432 | |
|
433 | 0 | exit: |
434 | 0 | return return_value; |
435 | 0 | } |
436 | | |
437 | | #endif /* defined(HAVE_GETITIMER) */ |
438 | | |
439 | | #if defined(HAVE_SIGSET_T) && defined(PYPTHREAD_SIGMASK) |
440 | | |
441 | | PyDoc_STRVAR(signal_pthread_sigmask__doc__, |
442 | | "pthread_sigmask($module, how, mask, /)\n" |
443 | | "--\n" |
444 | | "\n" |
445 | | "Fetch and/or change the signal mask of the calling thread."); |
446 | | |
447 | | #define SIGNAL_PTHREAD_SIGMASK_METHODDEF \ |
448 | | {"pthread_sigmask", _PyCFunction_CAST(signal_pthread_sigmask), METH_FASTCALL, signal_pthread_sigmask__doc__}, |
449 | | |
450 | | static PyObject * |
451 | | signal_pthread_sigmask_impl(PyObject *module, int how, sigset_t mask); |
452 | | |
453 | | static PyObject * |
454 | | signal_pthread_sigmask(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
455 | 0 | { |
456 | 0 | PyObject *return_value = NULL; |
457 | 0 | int how; |
458 | 0 | sigset_t mask; |
459 | |
|
460 | 0 | if (!_PyArg_CheckPositional("pthread_sigmask", nargs, 2, 2)) { |
461 | 0 | goto exit; |
462 | 0 | } |
463 | 0 | how = PyLong_AsInt(args[0]); |
464 | 0 | if (how == -1 && PyErr_Occurred()) { |
465 | 0 | goto exit; |
466 | 0 | } |
467 | 0 | if (!_Py_Sigset_Converter(args[1], &mask)) { |
468 | 0 | goto exit; |
469 | 0 | } |
470 | 0 | return_value = signal_pthread_sigmask_impl(module, how, mask); |
471 | |
|
472 | 0 | exit: |
473 | 0 | return return_value; |
474 | 0 | } |
475 | | |
476 | | #endif /* defined(HAVE_SIGSET_T) && defined(PYPTHREAD_SIGMASK) */ |
477 | | |
478 | | #if defined(HAVE_SIGSET_T) && defined(HAVE_SIGPENDING) |
479 | | |
480 | | PyDoc_STRVAR(signal_sigpending__doc__, |
481 | | "sigpending($module, /)\n" |
482 | | "--\n" |
483 | | "\n" |
484 | | "Examine pending signals.\n" |
485 | | "\n" |
486 | | "Returns a set of signal numbers that are pending for delivery to\n" |
487 | | "the calling thread."); |
488 | | |
489 | | #define SIGNAL_SIGPENDING_METHODDEF \ |
490 | | {"sigpending", (PyCFunction)signal_sigpending, METH_NOARGS, signal_sigpending__doc__}, |
491 | | |
492 | | static PyObject * |
493 | | signal_sigpending_impl(PyObject *module); |
494 | | |
495 | | static PyObject * |
496 | | signal_sigpending(PyObject *module, PyObject *Py_UNUSED(ignored)) |
497 | 0 | { |
498 | 0 | return signal_sigpending_impl(module); |
499 | 0 | } |
500 | | |
501 | | #endif /* defined(HAVE_SIGSET_T) && defined(HAVE_SIGPENDING) */ |
502 | | |
503 | | #if defined(HAVE_SIGSET_T) && defined(HAVE_SIGWAIT) |
504 | | |
505 | | PyDoc_STRVAR(signal_sigwait__doc__, |
506 | | "sigwait($module, sigset, /)\n" |
507 | | "--\n" |
508 | | "\n" |
509 | | "Wait for a signal.\n" |
510 | | "\n" |
511 | | "Suspend execution of the calling thread until the delivery of one of the\n" |
512 | | "signals specified in the signal set sigset. The function accepts the\n" |
513 | | "signal and returns the signal number."); |
514 | | |
515 | | #define SIGNAL_SIGWAIT_METHODDEF \ |
516 | | {"sigwait", (PyCFunction)signal_sigwait, METH_O, signal_sigwait__doc__}, |
517 | | |
518 | | static PyObject * |
519 | | signal_sigwait_impl(PyObject *module, sigset_t sigset); |
520 | | |
521 | | static PyObject * |
522 | | signal_sigwait(PyObject *module, PyObject *arg) |
523 | 0 | { |
524 | 0 | PyObject *return_value = NULL; |
525 | 0 | sigset_t sigset; |
526 | |
|
527 | 0 | if (!_Py_Sigset_Converter(arg, &sigset)) { |
528 | 0 | goto exit; |
529 | 0 | } |
530 | 0 | return_value = signal_sigwait_impl(module, sigset); |
531 | |
|
532 | 0 | exit: |
533 | 0 | return return_value; |
534 | 0 | } |
535 | | |
536 | | #endif /* defined(HAVE_SIGSET_T) && defined(HAVE_SIGWAIT) */ |
537 | | |
538 | | #if ((defined(HAVE_SIGFILLSET) && defined(HAVE_SIGSET_T)) || defined(MS_WINDOWS)) |
539 | | |
540 | | PyDoc_STRVAR(signal_valid_signals__doc__, |
541 | | "valid_signals($module, /)\n" |
542 | | "--\n" |
543 | | "\n" |
544 | | "Return a set of valid signal numbers on this platform.\n" |
545 | | "\n" |
546 | | "The signal numbers returned by this function can be safely passed to\n" |
547 | | "functions like `pthread_sigmask`."); |
548 | | |
549 | | #define SIGNAL_VALID_SIGNALS_METHODDEF \ |
550 | | {"valid_signals", (PyCFunction)signal_valid_signals, METH_NOARGS, signal_valid_signals__doc__}, |
551 | | |
552 | | static PyObject * |
553 | | signal_valid_signals_impl(PyObject *module); |
554 | | |
555 | | static PyObject * |
556 | | signal_valid_signals(PyObject *module, PyObject *Py_UNUSED(ignored)) |
557 | 0 | { |
558 | 0 | return signal_valid_signals_impl(module); |
559 | 0 | } |
560 | | |
561 | | #endif /* ((defined(HAVE_SIGFILLSET) && defined(HAVE_SIGSET_T)) || defined(MS_WINDOWS)) */ |
562 | | |
563 | | #if defined(HAVE_SIGSET_T) && defined(HAVE_SIGWAITINFO) |
564 | | |
565 | | PyDoc_STRVAR(signal_sigwaitinfo__doc__, |
566 | | "sigwaitinfo($module, sigset, /)\n" |
567 | | "--\n" |
568 | | "\n" |
569 | | "Wait synchronously until one of the signals in *sigset* is delivered.\n" |
570 | | "\n" |
571 | | "Returns a struct_siginfo containing information about the signal."); |
572 | | |
573 | | #define SIGNAL_SIGWAITINFO_METHODDEF \ |
574 | | {"sigwaitinfo", (PyCFunction)signal_sigwaitinfo, METH_O, signal_sigwaitinfo__doc__}, |
575 | | |
576 | | static PyObject * |
577 | | signal_sigwaitinfo_impl(PyObject *module, sigset_t sigset); |
578 | | |
579 | | static PyObject * |
580 | | signal_sigwaitinfo(PyObject *module, PyObject *arg) |
581 | 0 | { |
582 | 0 | PyObject *return_value = NULL; |
583 | 0 | sigset_t sigset; |
584 | |
|
585 | 0 | if (!_Py_Sigset_Converter(arg, &sigset)) { |
586 | 0 | goto exit; |
587 | 0 | } |
588 | 0 | return_value = signal_sigwaitinfo_impl(module, sigset); |
589 | |
|
590 | 0 | exit: |
591 | 0 | return return_value; |
592 | 0 | } |
593 | | |
594 | | #endif /* defined(HAVE_SIGSET_T) && defined(HAVE_SIGWAITINFO) */ |
595 | | |
596 | | #if defined(HAVE_SIGSET_T) && defined(HAVE_SIGTIMEDWAIT) |
597 | | |
598 | | PyDoc_STRVAR(signal_sigtimedwait__doc__, |
599 | | "sigtimedwait($module, sigset, timeout, /)\n" |
600 | | "--\n" |
601 | | "\n" |
602 | | "Like sigwaitinfo(), but with a timeout.\n" |
603 | | "\n" |
604 | | "The timeout is specified in seconds, rounded up to nanoseconds."); |
605 | | |
606 | | #define SIGNAL_SIGTIMEDWAIT_METHODDEF \ |
607 | | {"sigtimedwait", _PyCFunction_CAST(signal_sigtimedwait), METH_FASTCALL, signal_sigtimedwait__doc__}, |
608 | | |
609 | | static PyObject * |
610 | | signal_sigtimedwait_impl(PyObject *module, sigset_t sigset, |
611 | | PyObject *timeout_obj); |
612 | | |
613 | | static PyObject * |
614 | | signal_sigtimedwait(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
615 | 0 | { |
616 | 0 | PyObject *return_value = NULL; |
617 | 0 | sigset_t sigset; |
618 | 0 | PyObject *timeout_obj; |
619 | |
|
620 | 0 | if (!_PyArg_CheckPositional("sigtimedwait", nargs, 2, 2)) { |
621 | 0 | goto exit; |
622 | 0 | } |
623 | 0 | if (!_Py_Sigset_Converter(args[0], &sigset)) { |
624 | 0 | goto exit; |
625 | 0 | } |
626 | 0 | timeout_obj = args[1]; |
627 | 0 | return_value = signal_sigtimedwait_impl(module, sigset, timeout_obj); |
628 | |
|
629 | 0 | exit: |
630 | 0 | return return_value; |
631 | 0 | } |
632 | | |
633 | | #endif /* defined(HAVE_SIGSET_T) && defined(HAVE_SIGTIMEDWAIT) */ |
634 | | |
635 | | #if defined(HAVE_PTHREAD_KILL) |
636 | | |
637 | | PyDoc_STRVAR(signal_pthread_kill__doc__, |
638 | | "pthread_kill($module, thread_id, signalnum, /)\n" |
639 | | "--\n" |
640 | | "\n" |
641 | | "Send a signal to a thread."); |
642 | | |
643 | | #define SIGNAL_PTHREAD_KILL_METHODDEF \ |
644 | | {"pthread_kill", _PyCFunction_CAST(signal_pthread_kill), METH_FASTCALL, signal_pthread_kill__doc__}, |
645 | | |
646 | | static PyObject * |
647 | | signal_pthread_kill_impl(PyObject *module, unsigned long thread_id, |
648 | | int signalnum); |
649 | | |
650 | | static PyObject * |
651 | | signal_pthread_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
652 | 0 | { |
653 | 0 | PyObject *return_value = NULL; |
654 | 0 | unsigned long thread_id; |
655 | 0 | int signalnum; |
656 | |
|
657 | 0 | if (!_PyArg_CheckPositional("pthread_kill", nargs, 2, 2)) { |
658 | 0 | goto exit; |
659 | 0 | } |
660 | 0 | if (!PyIndex_Check(args[0])) { |
661 | 0 | _PyArg_BadArgument("pthread_kill", "argument 1", "int", args[0]); |
662 | 0 | goto exit; |
663 | 0 | } |
664 | 0 | { |
665 | 0 | Py_ssize_t _bytes = PyLong_AsNativeBytes(args[0], &thread_id, sizeof(unsigned long), |
666 | 0 | Py_ASNATIVEBYTES_NATIVE_ENDIAN | |
667 | 0 | Py_ASNATIVEBYTES_ALLOW_INDEX | |
668 | 0 | Py_ASNATIVEBYTES_UNSIGNED_BUFFER); |
669 | 0 | if (_bytes < 0) { |
670 | 0 | goto exit; |
671 | 0 | } |
672 | 0 | if ((size_t)_bytes > sizeof(unsigned long)) { |
673 | 0 | if (PyErr_WarnEx(PyExc_DeprecationWarning, |
674 | 0 | "integer value out of range", 1) < 0) |
675 | 0 | { |
676 | 0 | goto exit; |
677 | 0 | } |
678 | 0 | } |
679 | 0 | } |
680 | 0 | signalnum = PyLong_AsInt(args[1]); |
681 | 0 | if (signalnum == -1 && PyErr_Occurred()) { |
682 | 0 | goto exit; |
683 | 0 | } |
684 | 0 | return_value = signal_pthread_kill_impl(module, thread_id, signalnum); |
685 | |
|
686 | 0 | exit: |
687 | 0 | return return_value; |
688 | 0 | } |
689 | | |
690 | | #endif /* defined(HAVE_PTHREAD_KILL) */ |
691 | | |
692 | | #if (defined(__linux__) && defined(__NR_pidfd_send_signal) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) |
693 | | |
694 | | PyDoc_STRVAR(signal_pidfd_send_signal__doc__, |
695 | | "pidfd_send_signal($module, pidfd, signalnum, siginfo=None, flags=0, /)\n" |
696 | | "--\n" |
697 | | "\n" |
698 | | "Send a signal to a process referred to by a pid file descriptor."); |
699 | | |
700 | | #define SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF \ |
701 | | {"pidfd_send_signal", _PyCFunction_CAST(signal_pidfd_send_signal), METH_FASTCALL, signal_pidfd_send_signal__doc__}, |
702 | | |
703 | | static PyObject * |
704 | | signal_pidfd_send_signal_impl(PyObject *module, int pidfd, int signalnum, |
705 | | PyObject *siginfo, int flags); |
706 | | |
707 | | static PyObject * |
708 | | signal_pidfd_send_signal(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
709 | 0 | { |
710 | 0 | PyObject *return_value = NULL; |
711 | 0 | int pidfd; |
712 | 0 | int signalnum; |
713 | 0 | PyObject *siginfo = Py_None; |
714 | 0 | int flags = 0; |
715 | |
|
716 | 0 | if (!_PyArg_CheckPositional("pidfd_send_signal", nargs, 2, 4)) { |
717 | 0 | goto exit; |
718 | 0 | } |
719 | 0 | pidfd = PyLong_AsInt(args[0]); |
720 | 0 | if (pidfd == -1 && PyErr_Occurred()) { |
721 | 0 | goto exit; |
722 | 0 | } |
723 | 0 | signalnum = PyLong_AsInt(args[1]); |
724 | 0 | if (signalnum == -1 && PyErr_Occurred()) { |
725 | 0 | goto exit; |
726 | 0 | } |
727 | 0 | if (nargs < 3) { |
728 | 0 | goto skip_optional; |
729 | 0 | } |
730 | 0 | siginfo = args[2]; |
731 | 0 | if (nargs < 4) { |
732 | 0 | goto skip_optional; |
733 | 0 | } |
734 | 0 | flags = PyLong_AsInt(args[3]); |
735 | 0 | if (flags == -1 && PyErr_Occurred()) { |
736 | 0 | goto exit; |
737 | 0 | } |
738 | 0 | skip_optional: |
739 | 0 | return_value = signal_pidfd_send_signal_impl(module, pidfd, signalnum, siginfo, flags); |
740 | |
|
741 | 0 | exit: |
742 | 0 | return return_value; |
743 | 0 | } |
744 | | |
745 | | #endif /* (defined(__linux__) && defined(__NR_pidfd_send_signal) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) */ |
746 | | |
747 | | #ifndef SIGNAL_ALARM_METHODDEF |
748 | | #define SIGNAL_ALARM_METHODDEF |
749 | | #endif /* !defined(SIGNAL_ALARM_METHODDEF) */ |
750 | | |
751 | | #ifndef SIGNAL_PAUSE_METHODDEF |
752 | | #define SIGNAL_PAUSE_METHODDEF |
753 | | #endif /* !defined(SIGNAL_PAUSE_METHODDEF) */ |
754 | | |
755 | | #ifndef SIGNAL_SIGINTERRUPT_METHODDEF |
756 | | #define SIGNAL_SIGINTERRUPT_METHODDEF |
757 | | #endif /* !defined(SIGNAL_SIGINTERRUPT_METHODDEF) */ |
758 | | |
759 | | #ifndef SIGNAL_SETITIMER_METHODDEF |
760 | | #define SIGNAL_SETITIMER_METHODDEF |
761 | | #endif /* !defined(SIGNAL_SETITIMER_METHODDEF) */ |
762 | | |
763 | | #ifndef SIGNAL_GETITIMER_METHODDEF |
764 | | #define SIGNAL_GETITIMER_METHODDEF |
765 | | #endif /* !defined(SIGNAL_GETITIMER_METHODDEF) */ |
766 | | |
767 | | #ifndef SIGNAL_PTHREAD_SIGMASK_METHODDEF |
768 | | #define SIGNAL_PTHREAD_SIGMASK_METHODDEF |
769 | | #endif /* !defined(SIGNAL_PTHREAD_SIGMASK_METHODDEF) */ |
770 | | |
771 | | #ifndef SIGNAL_SIGPENDING_METHODDEF |
772 | | #define SIGNAL_SIGPENDING_METHODDEF |
773 | | #endif /* !defined(SIGNAL_SIGPENDING_METHODDEF) */ |
774 | | |
775 | | #ifndef SIGNAL_SIGWAIT_METHODDEF |
776 | | #define SIGNAL_SIGWAIT_METHODDEF |
777 | | #endif /* !defined(SIGNAL_SIGWAIT_METHODDEF) */ |
778 | | |
779 | | #ifndef SIGNAL_VALID_SIGNALS_METHODDEF |
780 | | #define SIGNAL_VALID_SIGNALS_METHODDEF |
781 | | #endif /* !defined(SIGNAL_VALID_SIGNALS_METHODDEF) */ |
782 | | |
783 | | #ifndef SIGNAL_SIGWAITINFO_METHODDEF |
784 | | #define SIGNAL_SIGWAITINFO_METHODDEF |
785 | | #endif /* !defined(SIGNAL_SIGWAITINFO_METHODDEF) */ |
786 | | |
787 | | #ifndef SIGNAL_SIGTIMEDWAIT_METHODDEF |
788 | | #define SIGNAL_SIGTIMEDWAIT_METHODDEF |
789 | | #endif /* !defined(SIGNAL_SIGTIMEDWAIT_METHODDEF) */ |
790 | | |
791 | | #ifndef SIGNAL_PTHREAD_KILL_METHODDEF |
792 | | #define SIGNAL_PTHREAD_KILL_METHODDEF |
793 | | #endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */ |
794 | | |
795 | | #ifndef SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF |
796 | | #define SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF |
797 | | #endif /* !defined(SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF) */ |
798 | | /*[clinic end generated code: output=0731d6f05c42c09a input=a9049054013a1b77]*/ |