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