Debian Codegraph @

Modules/clinic/signalmodule.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_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 {
29 PyObject *return_value = NULL;
30 int signalnum;
31 PyObject *frame;
32
33 if (!_PyArg_CheckPositional("default_int_handler", nargs, 2, 2)) {
34 goto exit;
35 }
36 signalnum = PyLong_AsInt(args[0]);
37 if (signalnum == -1 && PyErr_Occurred()) {
38 goto exit;
39 }
40 frame = args[1];
41 return_value = signal_default_int_handler_impl(module, signalnum, frame);
42
43 exit:
44 return return_value;
45 }
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 {
64 PyObject *return_value = NULL;
65 int seconds;
66 long _return_value;
67
68 seconds = PyLong_AsInt(arg);
69 if (seconds == -1 && PyErr_Occurred()) {
70 goto exit;
71 }
72 _return_value = signal_alarm_impl(module, seconds);
73 if ((_return_value == -1) && PyErr_Occurred()) {
74 goto exit;
75 }
76 return_value = PyLong_FromLong(_return_value);
77
78 exit:
79 return return_value;
80 }
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 {
101 return signal_pause_impl(module);
102 }
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 {
121 PyObject *return_value = NULL;
122 int signalnum;
123
124 signalnum = PyLong_AsInt(arg);
125 if (signalnum == -1 && PyErr_Occurred()) {
126 goto exit;
127 }
128 return_value = signal_raise_signal_impl(module, signalnum);
129
130 exit:
131 return return_value;
132 }
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 {
156 PyObject *return_value = NULL;
157 int signalnum;
158 PyObject *handler;
159
160 if (!_PyArg_CheckPositional("signal", nargs, 2, 2)) {
161 goto exit;
162 }
163 signalnum = PyLong_AsInt(args[0]);
164 if (signalnum == -1 && PyErr_Occurred()) {
165 goto exit;
166 }
167 handler = args[1];
168 return_value = signal_signal_impl(module, signalnum, handler);
169
170 exit:
171 return return_value;
172 }
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 {
195 PyObject *return_value = NULL;
196 int signalnum;
197
198 signalnum = PyLong_AsInt(arg);
199 if (signalnum == -1 && PyErr_Occurred()) {
200 goto exit;
201 }
202 return_value = signal_getsignal_impl(module, signalnum);
203
204 exit:
205 return return_value;
206 }
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 {
227 PyObject *return_value = NULL;
228 int signalnum;
229
230 signalnum = PyLong_AsInt(arg);
231 if (signalnum == -1 && PyErr_Occurred()) {
232 goto exit;
233 }
234 return_value = signal_strsignal_impl(module, signalnum);
235
236 exit:
237 return return_value;
238 }
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 {
260 PyObject *return_value = NULL;
261 int signalnum;
262 int flag;
263
264 if (!_PyArg_CheckPositional("siginterrupt", nargs, 2, 2)) {
265 goto exit;
266 }
267 signalnum = PyLong_AsInt(args[0]);
268 if (signalnum == -1 && PyErr_Occurred()) {
269 goto exit;
270 }
271 flag = PyLong_AsInt(args[1]);
272 if (flag == -1 && PyErr_Occurred()) {
273 goto exit;
274 }
275 return_value = signal_siginterrupt_impl(module, signalnum, flag);
276
277 exit:
278 return return_value;
279 }
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 {
304 PyObject *return_value = NULL;
305 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
306
307 #define NUM_KEYWORDS 1
308 static struct {
309 PyGC_Head _this_is_not_used;
310 PyObject_VAR_HEAD
311 Py_hash_t ob_hash;
312 PyObject *ob_item[NUM_KEYWORDS];
313 } _kwtuple = {
314 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
315 .ob_hash = -1,
316 .ob_item = { &_Py_ID(warn_on_full_buffer), },
317 };
318 #undef NUM_KEYWORDS
319 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
320
321 #else // !Py_BUILD_CORE
322 # define KWTUPLE NULL
323 #endif // !Py_BUILD_CORE
324
325 static const char * const _keywords[] = {"", "warn_on_full_buffer", NULL};
326 static _PyArg_Parser _parser = {
327 .keywords = _keywords,
328 .fname = "set_wakeup_fd",
329 .kwtuple = KWTUPLE,
330 };
331 #undef KWTUPLE
332 PyObject *argsbuf[2];
333 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
334 PyObject *fdobj;
335 int warn_on_full_buffer = 1;
336
337 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
338 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
339 if (!args) {
340 goto exit;
341 }
342 fdobj = args[0];
343 if (!noptargs) {
344 goto skip_optional_kwonly;
345 }
346 warn_on_full_buffer = PyObject_IsTrue(args[1]);
347 if (warn_on_full_buffer < 0) {
348 goto exit;
349 }
350 skip_optional_kwonly:
351 return_value = signal_set_wakeup_fd_impl(module, fdobj, warn_on_full_buffer);
352
353 exit:
354 return return_value;
355 }
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 {
380 PyObject *return_value = NULL;
381 int which;
382 PyObject *seconds;
383 PyObject *interval = NULL;
384
385 if (!_PyArg_CheckPositional("setitimer", nargs, 2, 3)) {
386 goto exit;
387 }
388 which = PyLong_AsInt(args[0]);
389 if (which == -1 && PyErr_Occurred()) {
390 goto exit;
391 }
392 seconds = args[1];
393 if (nargs < 3) {
394 goto skip_optional;
395 }
396 interval = args[2];
397 skip_optional:
398 return_value = signal_setitimer_impl(module, which, seconds, interval);
399
400 exit:
401 return return_value;
402 }
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 {
423 PyObject *return_value = NULL;
424 int which;
425
426 which = PyLong_AsInt(arg);
427 if (which == -1 && PyErr_Occurred()) {
428 goto exit;
429 }
430 return_value = signal_getitimer_impl(module, which);
431
432 exit:
433 return return_value;
434 }
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 {
455 PyObject *return_value = NULL;
456 int how;
457 sigset_t mask;
458
459 if (!_PyArg_CheckPositional("pthread_sigmask", nargs, 2, 2)) {
460 goto exit;
461 }
462 how = PyLong_AsInt(args[0]);
463 if (how == -1 && PyErr_Occurred()) {
464 goto exit;
465 }
466 if (!_Py_Sigset_Converter(args[1], &mask)) {
467 goto exit;
468 }
469 return_value = signal_pthread_sigmask_impl(module, how, mask);
470
471 exit:
472 return return_value;
473 }
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 {
497 return signal_sigpending_impl(module);
498 }
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 {
523 PyObject *return_value = NULL;
524 sigset_t sigset;
525
526 if (!_Py_Sigset_Converter(arg, &sigset)) {
527 goto exit;
528 }
529 return_value = signal_sigwait_impl(module, sigset);
530
531 exit:
532 return return_value;
533 }
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 {
557 return signal_valid_signals_impl(module);
558 }
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 {
581 PyObject *return_value = NULL;
582 sigset_t sigset;
583
584 if (!_Py_Sigset_Converter(arg, &sigset)) {
585 goto exit;
586 }
587 return_value = signal_sigwaitinfo_impl(module, sigset);
588
589 exit:
590 return return_value;
591 }
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 {
615 PyObject *return_value = NULL;
616 sigset_t sigset;
617 PyObject *timeout_obj;
618
619 if (!_PyArg_CheckPositional("sigtimedwait", nargs, 2, 2)) {
620 goto exit;
621 }
622 if (!_Py_Sigset_Converter(args[0], &sigset)) {
623 goto exit;
624 }
625 timeout_obj = args[1];
626 return_value = signal_sigtimedwait_impl(module, sigset, timeout_obj);
627
628 exit:
629 return return_value;
630 }
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 {
652 PyObject *return_value = NULL;
653 unsigned long thread_id;
654 int signalnum;
655
656 if (!_PyArg_CheckPositional("pthread_kill", nargs, 2, 2)) {
657 goto exit;
658 }
659 if (!PyIndex_Check(args[0])) {
660 _PyArg_BadArgument("pthread_kill", "argument 1", "int", args[0]);
661 goto exit;
662 }
663 thread_id = PyLong_AsUnsignedLongMask(args[0]);
664 signalnum = PyLong_AsInt(args[1]);
665 if (signalnum == -1 && PyErr_Occurred()) {
666 goto exit;
667 }
668 return_value = signal_pthread_kill_impl(module, thread_id, signalnum);
669
670 exit:
671 return return_value;
672 }
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 {
694 PyObject *return_value = NULL;
695 int pidfd;
696 int signalnum;
697 PyObject *siginfo = Py_None;
698 int flags = 0;
699
700 if (!_PyArg_CheckPositional("pidfd_send_signal", nargs, 2, 4)) {
701 goto exit;
702 }
703 pidfd = PyLong_AsInt(args[0]);
704 if (pidfd == -1 && PyErr_Occurred()) {
705 goto exit;
706 }
707 signalnum = PyLong_AsInt(args[1]);
708 if (signalnum == -1 && PyErr_Occurred()) {
709 goto exit;
710 }
711 if (nargs < 3) {
712 goto skip_optional;
713 }
714 siginfo = args[2];
715 if (nargs < 4) {
716 goto skip_optional;
717 }
718 flags = PyLong_AsInt(args[3]);
719 if (flags == -1 && PyErr_Occurred()) {
720 goto exit;
721 }
722 skip_optional:
723 return_value = signal_pidfd_send_signal_impl(module, pidfd, signalnum, siginfo, flags);
724
725 exit:
726 return return_value;
727 }
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]*/