blob: 4713bab7486acb9fda93a776cbb54da8e715172c [file] [log] [blame]
Tal Einatc7027b72015-05-16 14:14:49 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
Serhiy Storchakab0689ae2020-07-12 19:15:20 +03005PyDoc_STRVAR(signal_default_int_handler__doc__,
6"default_int_handler($module, signalnum, frame, /)\n"
7"--\n"
8"\n"
9"The default handler for SIGINT installed by Python.\n"
10"\n"
11"It raises KeyboardInterrupt.");
12
13#define SIGNAL_DEFAULT_INT_HANDLER_METHODDEF \
14 {"default_int_handler", (PyCFunction)(void(*)(void))signal_default_int_handler, METH_FASTCALL, signal_default_int_handler__doc__},
15
16static PyObject *
17signal_default_int_handler_impl(PyObject *module, int signalnum,
18 PyObject *frame);
19
20static PyObject *
21signal_default_int_handler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
22{
23 PyObject *return_value = NULL;
24 int signalnum;
25 PyObject *frame;
26
27 if (!_PyArg_CheckPositional("default_int_handler", nargs, 2, 2)) {
28 goto exit;
29 }
30 signalnum = _PyLong_AsInt(args[0]);
31 if (signalnum == -1 && PyErr_Occurred()) {
32 goto exit;
33 }
34 frame = args[1];
35 return_value = signal_default_int_handler_impl(module, signalnum, frame);
36
37exit:
38 return return_value;
39}
40
Tal Einatc7027b72015-05-16 14:14:49 +030041#if defined(HAVE_ALARM)
42
43PyDoc_STRVAR(signal_alarm__doc__,
44"alarm($module, seconds, /)\n"
45"--\n"
46"\n"
47"Arrange for SIGALRM to arrive after the given number of seconds.");
48
49#define SIGNAL_ALARM_METHODDEF \
50 {"alarm", (PyCFunction)signal_alarm, METH_O, signal_alarm__doc__},
51
52static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030053signal_alarm_impl(PyObject *module, int seconds);
Tal Einatc7027b72015-05-16 14:14:49 +030054
55static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030056signal_alarm(PyObject *module, PyObject *arg)
Tal Einatc7027b72015-05-16 14:14:49 +030057{
58 PyObject *return_value = NULL;
59 int seconds;
60 long _return_value;
61
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020062 seconds = _PyLong_AsInt(arg);
63 if (seconds == -1 && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +030064 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030065 }
Tal Einatc7027b72015-05-16 14:14:49 +030066 _return_value = signal_alarm_impl(module, seconds);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030067 if ((_return_value == -1) && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +030068 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030069 }
Tal Einatc7027b72015-05-16 14:14:49 +030070 return_value = PyLong_FromLong(_return_value);
71
72exit:
73 return return_value;
74}
75
76#endif /* defined(HAVE_ALARM) */
77
78#if defined(HAVE_PAUSE)
79
80PyDoc_STRVAR(signal_pause__doc__,
81"pause($module, /)\n"
82"--\n"
83"\n"
84"Wait until a signal arrives.");
85
86#define SIGNAL_PAUSE_METHODDEF \
87 {"pause", (PyCFunction)signal_pause, METH_NOARGS, signal_pause__doc__},
88
89static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030090signal_pause_impl(PyObject *module);
Tal Einatc7027b72015-05-16 14:14:49 +030091
92static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030093signal_pause(PyObject *module, PyObject *Py_UNUSED(ignored))
Tal Einatc7027b72015-05-16 14:14:49 +030094{
95 return signal_pause_impl(module);
96}
97
98#endif /* defined(HAVE_PAUSE) */
99
Vladimir Matveevc24c6c22019-01-08 01:58:25 -0800100PyDoc_STRVAR(signal_raise_signal__doc__,
101"raise_signal($module, signalnum, /)\n"
102"--\n"
103"\n"
104"Send a signal to the executing process.");
105
106#define SIGNAL_RAISE_SIGNAL_METHODDEF \
107 {"raise_signal", (PyCFunction)signal_raise_signal, METH_O, signal_raise_signal__doc__},
108
109static PyObject *
110signal_raise_signal_impl(PyObject *module, int signalnum);
111
112static PyObject *
113signal_raise_signal(PyObject *module, PyObject *arg)
114{
115 PyObject *return_value = NULL;
116 int signalnum;
117
Vladimir Matveevc24c6c22019-01-08 01:58:25 -0800118 signalnum = _PyLong_AsInt(arg);
119 if (signalnum == -1 && PyErr_Occurred()) {
120 goto exit;
121 }
122 return_value = signal_raise_signal_impl(module, signalnum);
123
124exit:
125 return return_value;
126}
127
Tal Einatc7027b72015-05-16 14:14:49 +0300128PyDoc_STRVAR(signal_signal__doc__,
129"signal($module, signalnum, handler, /)\n"
130"--\n"
131"\n"
132"Set the action for the given signal.\n"
133"\n"
134"The action can be SIG_DFL, SIG_IGN, or a callable Python object.\n"
135"The previous action is returned. See getsignal() for possible return values.\n"
136"\n"
137"*** IMPORTANT NOTICE ***\n"
138"A signal handler function is called with two arguments:\n"
139"the first is the signal number, the second is the interrupted stack frame.");
140
141#define SIGNAL_SIGNAL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200142 {"signal", (PyCFunction)(void(*)(void))signal_signal, METH_FASTCALL, signal_signal__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300143
144static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300145signal_signal_impl(PyObject *module, int signalnum, PyObject *handler);
Tal Einatc7027b72015-05-16 14:14:49 +0300146
147static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200148signal_signal(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300149{
150 PyObject *return_value = NULL;
151 int signalnum;
152 PyObject *handler;
153
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200154 if (!_PyArg_CheckPositional("signal", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100155 goto exit;
156 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200157 signalnum = _PyLong_AsInt(args[0]);
158 if (signalnum == -1 && PyErr_Occurred()) {
159 goto exit;
160 }
161 handler = args[1];
Tal Einatc7027b72015-05-16 14:14:49 +0300162 return_value = signal_signal_impl(module, signalnum, handler);
163
164exit:
165 return return_value;
166}
167
168PyDoc_STRVAR(signal_getsignal__doc__,
169"getsignal($module, signalnum, /)\n"
170"--\n"
171"\n"
172"Return the current action for the given signal.\n"
173"\n"
174"The return value can be:\n"
175" SIG_IGN -- if the signal is being ignored\n"
176" SIG_DFL -- if the default action for the signal is in effect\n"
177" None -- if an unknown handler is in effect\n"
178" anything else -- the callable Python object used as a handler");
179
180#define SIGNAL_GETSIGNAL_METHODDEF \
181 {"getsignal", (PyCFunction)signal_getsignal, METH_O, signal_getsignal__doc__},
182
183static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300184signal_getsignal_impl(PyObject *module, int signalnum);
Tal Einatc7027b72015-05-16 14:14:49 +0300185
186static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300187signal_getsignal(PyObject *module, PyObject *arg)
Tal Einatc7027b72015-05-16 14:14:49 +0300188{
189 PyObject *return_value = NULL;
190 int signalnum;
191
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200192 signalnum = _PyLong_AsInt(arg);
193 if (signalnum == -1 && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +0300194 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300195 }
Tal Einatc7027b72015-05-16 14:14:49 +0300196 return_value = signal_getsignal_impl(module, signalnum);
197
198exit:
199 return return_value;
200}
201
Antoine Pietri5d2a27d2018-03-12 14:42:34 +0100202PyDoc_STRVAR(signal_strsignal__doc__,
203"strsignal($module, signalnum, /)\n"
204"--\n"
205"\n"
206"Return the system description of the given signal.\n"
207"\n"
208"The return values can be such as \"Interrupt\", \"Segmentation fault\", etc.\n"
209"Returns None if the signal is not recognized.");
210
211#define SIGNAL_STRSIGNAL_METHODDEF \
212 {"strsignal", (PyCFunction)signal_strsignal, METH_O, signal_strsignal__doc__},
213
214static PyObject *
215signal_strsignal_impl(PyObject *module, int signalnum);
216
217static PyObject *
218signal_strsignal(PyObject *module, PyObject *arg)
219{
220 PyObject *return_value = NULL;
221 int signalnum;
222
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200223 signalnum = _PyLong_AsInt(arg);
224 if (signalnum == -1 && PyErr_Occurred()) {
Antoine Pietri5d2a27d2018-03-12 14:42:34 +0100225 goto exit;
226 }
227 return_value = signal_strsignal_impl(module, signalnum);
228
229exit:
230 return return_value;
231}
232
Tal Einatc7027b72015-05-16 14:14:49 +0300233#if defined(HAVE_SIGINTERRUPT)
234
235PyDoc_STRVAR(signal_siginterrupt__doc__,
236"siginterrupt($module, signalnum, flag, /)\n"
237"--\n"
238"\n"
239"Change system call restart behaviour.\n"
240"\n"
241"If flag is False, system calls will be restarted when interrupted by\n"
242"signal sig, else system calls will be interrupted.");
243
244#define SIGNAL_SIGINTERRUPT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200245 {"siginterrupt", (PyCFunction)(void(*)(void))signal_siginterrupt, METH_FASTCALL, signal_siginterrupt__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300246
247static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300248signal_siginterrupt_impl(PyObject *module, int signalnum, int flag);
Tal Einatc7027b72015-05-16 14:14:49 +0300249
250static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200251signal_siginterrupt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300252{
253 PyObject *return_value = NULL;
254 int signalnum;
255 int flag;
256
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200257 if (!_PyArg_CheckPositional("siginterrupt", nargs, 2, 2)) {
258 goto exit;
259 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200260 signalnum = _PyLong_AsInt(args[0]);
261 if (signalnum == -1 && PyErr_Occurred()) {
262 goto exit;
263 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200264 flag = _PyLong_AsInt(args[1]);
265 if (flag == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100266 goto exit;
267 }
Tal Einatc7027b72015-05-16 14:14:49 +0300268 return_value = signal_siginterrupt_impl(module, signalnum, flag);
269
270exit:
271 return return_value;
272}
273
274#endif /* defined(HAVE_SIGINTERRUPT) */
275
276#if defined(HAVE_SETITIMER)
277
278PyDoc_STRVAR(signal_setitimer__doc__,
279"setitimer($module, which, seconds, interval=0.0, /)\n"
280"--\n"
281"\n"
282"Sets given itimer (one of ITIMER_REAL, ITIMER_VIRTUAL or ITIMER_PROF).\n"
283"\n"
284"The timer will fire after value seconds and after that every interval seconds.\n"
285"The itimer can be cleared by setting seconds to zero.\n"
286"\n"
287"Returns old values as a tuple: (delay, interval).");
288
289#define SIGNAL_SETITIMER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200290 {"setitimer", (PyCFunction)(void(*)(void))signal_setitimer, METH_FASTCALL, signal_setitimer__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300291
292static PyObject *
Victor Stinneref611c92017-10-13 13:49:43 -0700293signal_setitimer_impl(PyObject *module, int which, PyObject *seconds,
294 PyObject *interval);
Tal Einatc7027b72015-05-16 14:14:49 +0300295
296static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200297signal_setitimer(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300298{
299 PyObject *return_value = NULL;
300 int which;
Victor Stinneref611c92017-10-13 13:49:43 -0700301 PyObject *seconds;
302 PyObject *interval = NULL;
Tal Einatc7027b72015-05-16 14:14:49 +0300303
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200304 if (!_PyArg_CheckPositional("setitimer", nargs, 2, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100305 goto exit;
306 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200307 which = _PyLong_AsInt(args[0]);
308 if (which == -1 && PyErr_Occurred()) {
309 goto exit;
310 }
311 seconds = args[1];
312 if (nargs < 3) {
313 goto skip_optional;
314 }
315 interval = args[2];
316skip_optional:
Tal Einatc7027b72015-05-16 14:14:49 +0300317 return_value = signal_setitimer_impl(module, which, seconds, interval);
318
319exit:
320 return return_value;
321}
322
323#endif /* defined(HAVE_SETITIMER) */
324
325#if defined(HAVE_GETITIMER)
326
327PyDoc_STRVAR(signal_getitimer__doc__,
328"getitimer($module, which, /)\n"
329"--\n"
330"\n"
331"Returns current value of given itimer.");
332
333#define SIGNAL_GETITIMER_METHODDEF \
334 {"getitimer", (PyCFunction)signal_getitimer, METH_O, signal_getitimer__doc__},
335
336static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300337signal_getitimer_impl(PyObject *module, int which);
Tal Einatc7027b72015-05-16 14:14:49 +0300338
339static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300340signal_getitimer(PyObject *module, PyObject *arg)
Tal Einatc7027b72015-05-16 14:14:49 +0300341{
342 PyObject *return_value = NULL;
343 int which;
344
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200345 which = _PyLong_AsInt(arg);
346 if (which == -1 && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +0300347 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300348 }
Tal Einatc7027b72015-05-16 14:14:49 +0300349 return_value = signal_getitimer_impl(module, which);
350
351exit:
352 return return_value;
353}
354
355#endif /* defined(HAVE_GETITIMER) */
356
357#if defined(PYPTHREAD_SIGMASK)
358
359PyDoc_STRVAR(signal_pthread_sigmask__doc__,
360"pthread_sigmask($module, how, mask, /)\n"
361"--\n"
362"\n"
363"Fetch and/or change the signal mask of the calling thread.");
364
365#define SIGNAL_PTHREAD_SIGMASK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200366 {"pthread_sigmask", (PyCFunction)(void(*)(void))signal_pthread_sigmask, METH_FASTCALL, signal_pthread_sigmask__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300367
368static PyObject *
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300369signal_pthread_sigmask_impl(PyObject *module, int how, sigset_t mask);
Tal Einatc7027b72015-05-16 14:14:49 +0300370
371static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200372signal_pthread_sigmask(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300373{
374 PyObject *return_value = NULL;
375 int how;
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300376 sigset_t mask;
Tal Einatc7027b72015-05-16 14:14:49 +0300377
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200378 if (!_PyArg_CheckPositional("pthread_sigmask", nargs, 2, 2)) {
379 goto exit;
380 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200381 how = _PyLong_AsInt(args[0]);
382 if (how == -1 && PyErr_Occurred()) {
383 goto exit;
384 }
385 if (!_Py_Sigset_Converter(args[1], &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100386 goto exit;
387 }
Tal Einatc7027b72015-05-16 14:14:49 +0300388 return_value = signal_pthread_sigmask_impl(module, how, mask);
389
390exit:
391 return return_value;
392}
393
394#endif /* defined(PYPTHREAD_SIGMASK) */
395
396#if defined(HAVE_SIGPENDING)
397
398PyDoc_STRVAR(signal_sigpending__doc__,
399"sigpending($module, /)\n"
400"--\n"
401"\n"
402"Examine pending signals.\n"
403"\n"
404"Returns a set of signal numbers that are pending for delivery to\n"
405"the calling thread.");
406
407#define SIGNAL_SIGPENDING_METHODDEF \
408 {"sigpending", (PyCFunction)signal_sigpending, METH_NOARGS, signal_sigpending__doc__},
409
410static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300411signal_sigpending_impl(PyObject *module);
Tal Einatc7027b72015-05-16 14:14:49 +0300412
413static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300414signal_sigpending(PyObject *module, PyObject *Py_UNUSED(ignored))
Tal Einatc7027b72015-05-16 14:14:49 +0300415{
416 return signal_sigpending_impl(module);
417}
418
419#endif /* defined(HAVE_SIGPENDING) */
420
421#if defined(HAVE_SIGWAIT)
422
423PyDoc_STRVAR(signal_sigwait__doc__,
424"sigwait($module, sigset, /)\n"
425"--\n"
426"\n"
427"Wait for a signal.\n"
428"\n"
429"Suspend execution of the calling thread until the delivery of one of the\n"
430"signals specified in the signal set sigset. The function accepts the signal\n"
431"and returns the signal number.");
432
433#define SIGNAL_SIGWAIT_METHODDEF \
434 {"sigwait", (PyCFunction)signal_sigwait, METH_O, signal_sigwait__doc__},
435
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300436static PyObject *
437signal_sigwait_impl(PyObject *module, sigset_t sigset);
438
439static PyObject *
440signal_sigwait(PyObject *module, PyObject *arg)
441{
442 PyObject *return_value = NULL;
443 sigset_t sigset;
444
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200445 if (!_Py_Sigset_Converter(arg, &sigset)) {
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300446 goto exit;
447 }
448 return_value = signal_sigwait_impl(module, sigset);
449
450exit:
451 return return_value;
452}
453
Tal Einatc7027b72015-05-16 14:14:49 +0300454#endif /* defined(HAVE_SIGWAIT) */
455
Antoine Pitrou9d3627e2018-05-04 13:00:50 +0200456#if (defined(HAVE_SIGFILLSET) || defined(MS_WINDOWS))
457
458PyDoc_STRVAR(signal_valid_signals__doc__,
459"valid_signals($module, /)\n"
460"--\n"
461"\n"
462"Return a set of valid signal numbers on this platform.\n"
463"\n"
464"The signal numbers returned by this function can be safely passed to\n"
465"functions like `pthread_sigmask`.");
466
467#define SIGNAL_VALID_SIGNALS_METHODDEF \
468 {"valid_signals", (PyCFunction)signal_valid_signals, METH_NOARGS, signal_valid_signals__doc__},
469
470static PyObject *
471signal_valid_signals_impl(PyObject *module);
472
473static PyObject *
474signal_valid_signals(PyObject *module, PyObject *Py_UNUSED(ignored))
475{
476 return signal_valid_signals_impl(module);
477}
478
479#endif /* (defined(HAVE_SIGFILLSET) || defined(MS_WINDOWS)) */
480
Tal Einatc7027b72015-05-16 14:14:49 +0300481#if defined(HAVE_SIGWAITINFO)
482
483PyDoc_STRVAR(signal_sigwaitinfo__doc__,
484"sigwaitinfo($module, sigset, /)\n"
485"--\n"
486"\n"
487"Wait synchronously until one of the signals in *sigset* is delivered.\n"
488"\n"
489"Returns a struct_siginfo containing information about the signal.");
490
491#define SIGNAL_SIGWAITINFO_METHODDEF \
492 {"sigwaitinfo", (PyCFunction)signal_sigwaitinfo, METH_O, signal_sigwaitinfo__doc__},
493
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300494static PyObject *
495signal_sigwaitinfo_impl(PyObject *module, sigset_t sigset);
496
497static PyObject *
498signal_sigwaitinfo(PyObject *module, PyObject *arg)
499{
500 PyObject *return_value = NULL;
501 sigset_t sigset;
502
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200503 if (!_Py_Sigset_Converter(arg, &sigset)) {
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300504 goto exit;
505 }
506 return_value = signal_sigwaitinfo_impl(module, sigset);
507
508exit:
509 return return_value;
510}
511
Tal Einatc7027b72015-05-16 14:14:49 +0300512#endif /* defined(HAVE_SIGWAITINFO) */
513
514#if defined(HAVE_SIGTIMEDWAIT)
515
516PyDoc_STRVAR(signal_sigtimedwait__doc__,
517"sigtimedwait($module, sigset, timeout, /)\n"
518"--\n"
519"\n"
520"Like sigwaitinfo(), but with a timeout.\n"
521"\n"
522"The timeout is specified in seconds, with floating point numbers allowed.");
523
524#define SIGNAL_SIGTIMEDWAIT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200525 {"sigtimedwait", (PyCFunction)(void(*)(void))signal_sigtimedwait, METH_FASTCALL, signal_sigtimedwait__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300526
527static PyObject *
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300528signal_sigtimedwait_impl(PyObject *module, sigset_t sigset,
Serhiy Storchaka6b680cd2015-05-16 15:57:56 +0300529 PyObject *timeout_obj);
Tal Einatc7027b72015-05-16 14:14:49 +0300530
531static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200532signal_sigtimedwait(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300533{
534 PyObject *return_value = NULL;
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300535 sigset_t sigset;
Serhiy Storchaka6b680cd2015-05-16 15:57:56 +0300536 PyObject *timeout_obj;
Tal Einatc7027b72015-05-16 14:14:49 +0300537
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200538 if (!_PyArg_CheckPositional("sigtimedwait", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100539 goto exit;
540 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200541 if (!_Py_Sigset_Converter(args[0], &sigset)) {
542 goto exit;
543 }
544 timeout_obj = args[1];
Serhiy Storchaka6b680cd2015-05-16 15:57:56 +0300545 return_value = signal_sigtimedwait_impl(module, sigset, timeout_obj);
Tal Einatc7027b72015-05-16 14:14:49 +0300546
547exit:
548 return return_value;
549}
550
551#endif /* defined(HAVE_SIGTIMEDWAIT) */
552
Antoine Pitroua6a4dc82017-09-07 18:56:24 +0200553#if defined(HAVE_PTHREAD_KILL)
Tal Einatc7027b72015-05-16 14:14:49 +0300554
555PyDoc_STRVAR(signal_pthread_kill__doc__,
556"pthread_kill($module, thread_id, signalnum, /)\n"
557"--\n"
558"\n"
559"Send a signal to a thread.");
560
561#define SIGNAL_PTHREAD_KILL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200562 {"pthread_kill", (PyCFunction)(void(*)(void))signal_pthread_kill, METH_FASTCALL, signal_pthread_kill__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300563
564static PyObject *
Serhiy Storchakaaefa7eb2017-03-23 15:48:39 +0200565signal_pthread_kill_impl(PyObject *module, unsigned long thread_id,
566 int signalnum);
Tal Einatc7027b72015-05-16 14:14:49 +0300567
568static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200569signal_pthread_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300570{
571 PyObject *return_value = NULL;
Serhiy Storchakaaefa7eb2017-03-23 15:48:39 +0200572 unsigned long thread_id;
Tal Einatc7027b72015-05-16 14:14:49 +0300573 int signalnum;
574
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200575 if (!_PyArg_CheckPositional("pthread_kill", nargs, 2, 2)) {
576 goto exit;
577 }
578 if (!PyLong_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200579 _PyArg_BadArgument("pthread_kill", "argument 1", "int", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200580 goto exit;
581 }
582 thread_id = PyLong_AsUnsignedLongMask(args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200583 signalnum = _PyLong_AsInt(args[1]);
584 if (signalnum == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100585 goto exit;
586 }
Tal Einatc7027b72015-05-16 14:14:49 +0300587 return_value = signal_pthread_kill_impl(module, thread_id, signalnum);
588
589exit:
590 return return_value;
591}
592
Antoine Pitroua6a4dc82017-09-07 18:56:24 +0200593#endif /* defined(HAVE_PTHREAD_KILL) */
Tal Einatc7027b72015-05-16 14:14:49 +0300594
Benjamin Peterson74834512019-11-19 20:39:14 -0800595#if (defined(__linux__) && defined(__NR_pidfd_send_signal))
596
597PyDoc_STRVAR(signal_pidfd_send_signal__doc__,
598"pidfd_send_signal($module, pidfd, signalnum, siginfo=None, flags=0, /)\n"
599"--\n"
600"\n"
601"Send a signal to a process referred to by a pid file descriptor.");
602
603#define SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF \
604 {"pidfd_send_signal", (PyCFunction)(void(*)(void))signal_pidfd_send_signal, METH_FASTCALL, signal_pidfd_send_signal__doc__},
605
606static PyObject *
607signal_pidfd_send_signal_impl(PyObject *module, int pidfd, int signalnum,
608 PyObject *siginfo, int flags);
609
610static PyObject *
611signal_pidfd_send_signal(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
612{
613 PyObject *return_value = NULL;
614 int pidfd;
615 int signalnum;
616 PyObject *siginfo = Py_None;
617 int flags = 0;
618
619 if (!_PyArg_CheckPositional("pidfd_send_signal", nargs, 2, 4)) {
620 goto exit;
621 }
Benjamin Peterson74834512019-11-19 20:39:14 -0800622 pidfd = _PyLong_AsInt(args[0]);
623 if (pidfd == -1 && PyErr_Occurred()) {
624 goto exit;
625 }
Benjamin Peterson74834512019-11-19 20:39:14 -0800626 signalnum = _PyLong_AsInt(args[1]);
627 if (signalnum == -1 && PyErr_Occurred()) {
628 goto exit;
629 }
630 if (nargs < 3) {
631 goto skip_optional;
632 }
633 siginfo = args[2];
634 if (nargs < 4) {
635 goto skip_optional;
636 }
Benjamin Peterson74834512019-11-19 20:39:14 -0800637 flags = _PyLong_AsInt(args[3]);
638 if (flags == -1 && PyErr_Occurred()) {
639 goto exit;
640 }
641skip_optional:
642 return_value = signal_pidfd_send_signal_impl(module, pidfd, signalnum, siginfo, flags);
643
644exit:
645 return return_value;
646}
647
648#endif /* (defined(__linux__) && defined(__NR_pidfd_send_signal)) */
649
Tal Einatc7027b72015-05-16 14:14:49 +0300650#ifndef SIGNAL_ALARM_METHODDEF
651 #define SIGNAL_ALARM_METHODDEF
652#endif /* !defined(SIGNAL_ALARM_METHODDEF) */
653
654#ifndef SIGNAL_PAUSE_METHODDEF
655 #define SIGNAL_PAUSE_METHODDEF
656#endif /* !defined(SIGNAL_PAUSE_METHODDEF) */
657
658#ifndef SIGNAL_SIGINTERRUPT_METHODDEF
659 #define SIGNAL_SIGINTERRUPT_METHODDEF
660#endif /* !defined(SIGNAL_SIGINTERRUPT_METHODDEF) */
661
662#ifndef SIGNAL_SETITIMER_METHODDEF
663 #define SIGNAL_SETITIMER_METHODDEF
664#endif /* !defined(SIGNAL_SETITIMER_METHODDEF) */
665
666#ifndef SIGNAL_GETITIMER_METHODDEF
667 #define SIGNAL_GETITIMER_METHODDEF
668#endif /* !defined(SIGNAL_GETITIMER_METHODDEF) */
669
670#ifndef SIGNAL_PTHREAD_SIGMASK_METHODDEF
671 #define SIGNAL_PTHREAD_SIGMASK_METHODDEF
672#endif /* !defined(SIGNAL_PTHREAD_SIGMASK_METHODDEF) */
673
674#ifndef SIGNAL_SIGPENDING_METHODDEF
675 #define SIGNAL_SIGPENDING_METHODDEF
676#endif /* !defined(SIGNAL_SIGPENDING_METHODDEF) */
677
678#ifndef SIGNAL_SIGWAIT_METHODDEF
679 #define SIGNAL_SIGWAIT_METHODDEF
680#endif /* !defined(SIGNAL_SIGWAIT_METHODDEF) */
681
Antoine Pitrou9d3627e2018-05-04 13:00:50 +0200682#ifndef SIGNAL_VALID_SIGNALS_METHODDEF
683 #define SIGNAL_VALID_SIGNALS_METHODDEF
684#endif /* !defined(SIGNAL_VALID_SIGNALS_METHODDEF) */
685
Tal Einatc7027b72015-05-16 14:14:49 +0300686#ifndef SIGNAL_SIGWAITINFO_METHODDEF
687 #define SIGNAL_SIGWAITINFO_METHODDEF
688#endif /* !defined(SIGNAL_SIGWAITINFO_METHODDEF) */
689
690#ifndef SIGNAL_SIGTIMEDWAIT_METHODDEF
691 #define SIGNAL_SIGTIMEDWAIT_METHODDEF
692#endif /* !defined(SIGNAL_SIGTIMEDWAIT_METHODDEF) */
693
694#ifndef SIGNAL_PTHREAD_KILL_METHODDEF
695 #define SIGNAL_PTHREAD_KILL_METHODDEF
696#endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */
Benjamin Peterson74834512019-11-19 20:39:14 -0800697
698#ifndef SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
699 #define SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
700#endif /* !defined(SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF) */
Serhiy Storchakab0689ae2020-07-12 19:15:20 +0300701/*[clinic end generated code: output=59c33f0af42aebb5 input=a9049054013a1b77]*/