blob: 33a278e488f9439bcb9fe208bc4190fb991b4e51 [file] [log] [blame]
Tal Einatc7027b72015-05-16 14:14:49 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5#if defined(HAVE_ALARM)
6
7PyDoc_STRVAR(signal_alarm__doc__,
8"alarm($module, seconds, /)\n"
9"--\n"
10"\n"
11"Arrange for SIGALRM to arrive after the given number of seconds.");
12
13#define SIGNAL_ALARM_METHODDEF \
14 {"alarm", (PyCFunction)signal_alarm, METH_O, signal_alarm__doc__},
15
16static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030017signal_alarm_impl(PyObject *module, int seconds);
Tal Einatc7027b72015-05-16 14:14:49 +030018
19static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030020signal_alarm(PyObject *module, PyObject *arg)
Tal Einatc7027b72015-05-16 14:14:49 +030021{
22 PyObject *return_value = NULL;
23 int seconds;
24 long _return_value;
25
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020026 seconds = _PyLong_AsInt(arg);
27 if (seconds == -1 && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +030028 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030029 }
Tal Einatc7027b72015-05-16 14:14:49 +030030 _return_value = signal_alarm_impl(module, seconds);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030031 if ((_return_value == -1) && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +030032 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030033 }
Tal Einatc7027b72015-05-16 14:14:49 +030034 return_value = PyLong_FromLong(_return_value);
35
36exit:
37 return return_value;
38}
39
40#endif /* defined(HAVE_ALARM) */
41
42#if defined(HAVE_PAUSE)
43
44PyDoc_STRVAR(signal_pause__doc__,
45"pause($module, /)\n"
46"--\n"
47"\n"
48"Wait until a signal arrives.");
49
50#define SIGNAL_PAUSE_METHODDEF \
51 {"pause", (PyCFunction)signal_pause, METH_NOARGS, signal_pause__doc__},
52
53static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030054signal_pause_impl(PyObject *module);
Tal Einatc7027b72015-05-16 14:14:49 +030055
56static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030057signal_pause(PyObject *module, PyObject *Py_UNUSED(ignored))
Tal Einatc7027b72015-05-16 14:14:49 +030058{
59 return signal_pause_impl(module);
60}
61
62#endif /* defined(HAVE_PAUSE) */
63
Vladimir Matveevc24c6c22019-01-08 01:58:25 -080064PyDoc_STRVAR(signal_raise_signal__doc__,
65"raise_signal($module, signalnum, /)\n"
66"--\n"
67"\n"
68"Send a signal to the executing process.");
69
70#define SIGNAL_RAISE_SIGNAL_METHODDEF \
71 {"raise_signal", (PyCFunction)signal_raise_signal, METH_O, signal_raise_signal__doc__},
72
73static PyObject *
74signal_raise_signal_impl(PyObject *module, int signalnum);
75
76static PyObject *
77signal_raise_signal(PyObject *module, PyObject *arg)
78{
79 PyObject *return_value = NULL;
80 int signalnum;
81
Vladimir Matveevc24c6c22019-01-08 01:58:25 -080082 signalnum = _PyLong_AsInt(arg);
83 if (signalnum == -1 && PyErr_Occurred()) {
84 goto exit;
85 }
86 return_value = signal_raise_signal_impl(module, signalnum);
87
88exit:
89 return return_value;
90}
91
Tal Einatc7027b72015-05-16 14:14:49 +030092PyDoc_STRVAR(signal_signal__doc__,
93"signal($module, signalnum, handler, /)\n"
94"--\n"
95"\n"
96"Set the action for the given signal.\n"
97"\n"
98"The action can be SIG_DFL, SIG_IGN, or a callable Python object.\n"
99"The previous action is returned. See getsignal() for possible return values.\n"
100"\n"
101"*** IMPORTANT NOTICE ***\n"
102"A signal handler function is called with two arguments:\n"
103"the first is the signal number, the second is the interrupted stack frame.");
104
105#define SIGNAL_SIGNAL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200106 {"signal", (PyCFunction)(void(*)(void))signal_signal, METH_FASTCALL, signal_signal__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300107
108static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300109signal_signal_impl(PyObject *module, int signalnum, PyObject *handler);
Tal Einatc7027b72015-05-16 14:14:49 +0300110
111static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200112signal_signal(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300113{
114 PyObject *return_value = NULL;
115 int signalnum;
116 PyObject *handler;
117
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200118 if (!_PyArg_CheckPositional("signal", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100119 goto exit;
120 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200121 signalnum = _PyLong_AsInt(args[0]);
122 if (signalnum == -1 && PyErr_Occurred()) {
123 goto exit;
124 }
125 handler = args[1];
Tal Einatc7027b72015-05-16 14:14:49 +0300126 return_value = signal_signal_impl(module, signalnum, handler);
127
128exit:
129 return return_value;
130}
131
132PyDoc_STRVAR(signal_getsignal__doc__,
133"getsignal($module, signalnum, /)\n"
134"--\n"
135"\n"
136"Return the current action for the given signal.\n"
137"\n"
138"The return value can be:\n"
139" SIG_IGN -- if the signal is being ignored\n"
140" SIG_DFL -- if the default action for the signal is in effect\n"
141" None -- if an unknown handler is in effect\n"
142" anything else -- the callable Python object used as a handler");
143
144#define SIGNAL_GETSIGNAL_METHODDEF \
145 {"getsignal", (PyCFunction)signal_getsignal, METH_O, signal_getsignal__doc__},
146
147static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300148signal_getsignal_impl(PyObject *module, int signalnum);
Tal Einatc7027b72015-05-16 14:14:49 +0300149
150static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300151signal_getsignal(PyObject *module, PyObject *arg)
Tal Einatc7027b72015-05-16 14:14:49 +0300152{
153 PyObject *return_value = NULL;
154 int signalnum;
155
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200156 signalnum = _PyLong_AsInt(arg);
157 if (signalnum == -1 && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +0300158 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300159 }
Tal Einatc7027b72015-05-16 14:14:49 +0300160 return_value = signal_getsignal_impl(module, signalnum);
161
162exit:
163 return return_value;
164}
165
Antoine Pietri5d2a27d2018-03-12 14:42:34 +0100166PyDoc_STRVAR(signal_strsignal__doc__,
167"strsignal($module, signalnum, /)\n"
168"--\n"
169"\n"
170"Return the system description of the given signal.\n"
171"\n"
172"The return values can be such as \"Interrupt\", \"Segmentation fault\", etc.\n"
173"Returns None if the signal is not recognized.");
174
175#define SIGNAL_STRSIGNAL_METHODDEF \
176 {"strsignal", (PyCFunction)signal_strsignal, METH_O, signal_strsignal__doc__},
177
178static PyObject *
179signal_strsignal_impl(PyObject *module, int signalnum);
180
181static PyObject *
182signal_strsignal(PyObject *module, PyObject *arg)
183{
184 PyObject *return_value = NULL;
185 int signalnum;
186
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200187 signalnum = _PyLong_AsInt(arg);
188 if (signalnum == -1 && PyErr_Occurred()) {
Antoine Pietri5d2a27d2018-03-12 14:42:34 +0100189 goto exit;
190 }
191 return_value = signal_strsignal_impl(module, signalnum);
192
193exit:
194 return return_value;
195}
196
Tal Einatc7027b72015-05-16 14:14:49 +0300197#if defined(HAVE_SIGINTERRUPT)
198
199PyDoc_STRVAR(signal_siginterrupt__doc__,
200"siginterrupt($module, signalnum, flag, /)\n"
201"--\n"
202"\n"
203"Change system call restart behaviour.\n"
204"\n"
205"If flag is False, system calls will be restarted when interrupted by\n"
206"signal sig, else system calls will be interrupted.");
207
208#define SIGNAL_SIGINTERRUPT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200209 {"siginterrupt", (PyCFunction)(void(*)(void))signal_siginterrupt, METH_FASTCALL, signal_siginterrupt__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300210
211static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300212signal_siginterrupt_impl(PyObject *module, int signalnum, int flag);
Tal Einatc7027b72015-05-16 14:14:49 +0300213
214static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200215signal_siginterrupt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300216{
217 PyObject *return_value = NULL;
218 int signalnum;
219 int flag;
220
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200221 if (!_PyArg_CheckPositional("siginterrupt", nargs, 2, 2)) {
222 goto exit;
223 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200224 signalnum = _PyLong_AsInt(args[0]);
225 if (signalnum == -1 && PyErr_Occurred()) {
226 goto exit;
227 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200228 flag = _PyLong_AsInt(args[1]);
229 if (flag == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100230 goto exit;
231 }
Tal Einatc7027b72015-05-16 14:14:49 +0300232 return_value = signal_siginterrupt_impl(module, signalnum, flag);
233
234exit:
235 return return_value;
236}
237
238#endif /* defined(HAVE_SIGINTERRUPT) */
239
240#if defined(HAVE_SETITIMER)
241
242PyDoc_STRVAR(signal_setitimer__doc__,
243"setitimer($module, which, seconds, interval=0.0, /)\n"
244"--\n"
245"\n"
246"Sets given itimer (one of ITIMER_REAL, ITIMER_VIRTUAL or ITIMER_PROF).\n"
247"\n"
248"The timer will fire after value seconds and after that every interval seconds.\n"
249"The itimer can be cleared by setting seconds to zero.\n"
250"\n"
251"Returns old values as a tuple: (delay, interval).");
252
253#define SIGNAL_SETITIMER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200254 {"setitimer", (PyCFunction)(void(*)(void))signal_setitimer, METH_FASTCALL, signal_setitimer__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300255
256static PyObject *
Victor Stinneref611c92017-10-13 13:49:43 -0700257signal_setitimer_impl(PyObject *module, int which, PyObject *seconds,
258 PyObject *interval);
Tal Einatc7027b72015-05-16 14:14:49 +0300259
260static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200261signal_setitimer(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300262{
263 PyObject *return_value = NULL;
264 int which;
Victor Stinneref611c92017-10-13 13:49:43 -0700265 PyObject *seconds;
266 PyObject *interval = NULL;
Tal Einatc7027b72015-05-16 14:14:49 +0300267
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200268 if (!_PyArg_CheckPositional("setitimer", nargs, 2, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100269 goto exit;
270 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200271 which = _PyLong_AsInt(args[0]);
272 if (which == -1 && PyErr_Occurred()) {
273 goto exit;
274 }
275 seconds = args[1];
276 if (nargs < 3) {
277 goto skip_optional;
278 }
279 interval = args[2];
280skip_optional:
Tal Einatc7027b72015-05-16 14:14:49 +0300281 return_value = signal_setitimer_impl(module, which, seconds, interval);
282
283exit:
284 return return_value;
285}
286
287#endif /* defined(HAVE_SETITIMER) */
288
289#if defined(HAVE_GETITIMER)
290
291PyDoc_STRVAR(signal_getitimer__doc__,
292"getitimer($module, which, /)\n"
293"--\n"
294"\n"
295"Returns current value of given itimer.");
296
297#define SIGNAL_GETITIMER_METHODDEF \
298 {"getitimer", (PyCFunction)signal_getitimer, METH_O, signal_getitimer__doc__},
299
300static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300301signal_getitimer_impl(PyObject *module, int which);
Tal Einatc7027b72015-05-16 14:14:49 +0300302
303static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300304signal_getitimer(PyObject *module, PyObject *arg)
Tal Einatc7027b72015-05-16 14:14:49 +0300305{
306 PyObject *return_value = NULL;
307 int which;
308
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200309 which = _PyLong_AsInt(arg);
310 if (which == -1 && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +0300311 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300312 }
Tal Einatc7027b72015-05-16 14:14:49 +0300313 return_value = signal_getitimer_impl(module, which);
314
315exit:
316 return return_value;
317}
318
319#endif /* defined(HAVE_GETITIMER) */
320
321#if defined(PYPTHREAD_SIGMASK)
322
323PyDoc_STRVAR(signal_pthread_sigmask__doc__,
324"pthread_sigmask($module, how, mask, /)\n"
325"--\n"
326"\n"
327"Fetch and/or change the signal mask of the calling thread.");
328
329#define SIGNAL_PTHREAD_SIGMASK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200330 {"pthread_sigmask", (PyCFunction)(void(*)(void))signal_pthread_sigmask, METH_FASTCALL, signal_pthread_sigmask__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300331
332static PyObject *
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300333signal_pthread_sigmask_impl(PyObject *module, int how, sigset_t mask);
Tal Einatc7027b72015-05-16 14:14:49 +0300334
335static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200336signal_pthread_sigmask(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300337{
338 PyObject *return_value = NULL;
339 int how;
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300340 sigset_t mask;
Tal Einatc7027b72015-05-16 14:14:49 +0300341
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200342 if (!_PyArg_CheckPositional("pthread_sigmask", nargs, 2, 2)) {
343 goto exit;
344 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200345 how = _PyLong_AsInt(args[0]);
346 if (how == -1 && PyErr_Occurred()) {
347 goto exit;
348 }
349 if (!_Py_Sigset_Converter(args[1], &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100350 goto exit;
351 }
Tal Einatc7027b72015-05-16 14:14:49 +0300352 return_value = signal_pthread_sigmask_impl(module, how, mask);
353
354exit:
355 return return_value;
356}
357
358#endif /* defined(PYPTHREAD_SIGMASK) */
359
360#if defined(HAVE_SIGPENDING)
361
362PyDoc_STRVAR(signal_sigpending__doc__,
363"sigpending($module, /)\n"
364"--\n"
365"\n"
366"Examine pending signals.\n"
367"\n"
368"Returns a set of signal numbers that are pending for delivery to\n"
369"the calling thread.");
370
371#define SIGNAL_SIGPENDING_METHODDEF \
372 {"sigpending", (PyCFunction)signal_sigpending, METH_NOARGS, signal_sigpending__doc__},
373
374static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300375signal_sigpending_impl(PyObject *module);
Tal Einatc7027b72015-05-16 14:14:49 +0300376
377static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300378signal_sigpending(PyObject *module, PyObject *Py_UNUSED(ignored))
Tal Einatc7027b72015-05-16 14:14:49 +0300379{
380 return signal_sigpending_impl(module);
381}
382
383#endif /* defined(HAVE_SIGPENDING) */
384
385#if defined(HAVE_SIGWAIT)
386
387PyDoc_STRVAR(signal_sigwait__doc__,
388"sigwait($module, sigset, /)\n"
389"--\n"
390"\n"
391"Wait for a signal.\n"
392"\n"
393"Suspend execution of the calling thread until the delivery of one of the\n"
394"signals specified in the signal set sigset. The function accepts the signal\n"
395"and returns the signal number.");
396
397#define SIGNAL_SIGWAIT_METHODDEF \
398 {"sigwait", (PyCFunction)signal_sigwait, METH_O, signal_sigwait__doc__},
399
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300400static PyObject *
401signal_sigwait_impl(PyObject *module, sigset_t sigset);
402
403static PyObject *
404signal_sigwait(PyObject *module, PyObject *arg)
405{
406 PyObject *return_value = NULL;
407 sigset_t sigset;
408
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200409 if (!_Py_Sigset_Converter(arg, &sigset)) {
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300410 goto exit;
411 }
412 return_value = signal_sigwait_impl(module, sigset);
413
414exit:
415 return return_value;
416}
417
Tal Einatc7027b72015-05-16 14:14:49 +0300418#endif /* defined(HAVE_SIGWAIT) */
419
Antoine Pitrou9d3627e2018-05-04 13:00:50 +0200420#if (defined(HAVE_SIGFILLSET) || defined(MS_WINDOWS))
421
422PyDoc_STRVAR(signal_valid_signals__doc__,
423"valid_signals($module, /)\n"
424"--\n"
425"\n"
426"Return a set of valid signal numbers on this platform.\n"
427"\n"
428"The signal numbers returned by this function can be safely passed to\n"
429"functions like `pthread_sigmask`.");
430
431#define SIGNAL_VALID_SIGNALS_METHODDEF \
432 {"valid_signals", (PyCFunction)signal_valid_signals, METH_NOARGS, signal_valid_signals__doc__},
433
434static PyObject *
435signal_valid_signals_impl(PyObject *module);
436
437static PyObject *
438signal_valid_signals(PyObject *module, PyObject *Py_UNUSED(ignored))
439{
440 return signal_valid_signals_impl(module);
441}
442
443#endif /* (defined(HAVE_SIGFILLSET) || defined(MS_WINDOWS)) */
444
Tal Einatc7027b72015-05-16 14:14:49 +0300445#if defined(HAVE_SIGWAITINFO)
446
447PyDoc_STRVAR(signal_sigwaitinfo__doc__,
448"sigwaitinfo($module, sigset, /)\n"
449"--\n"
450"\n"
451"Wait synchronously until one of the signals in *sigset* is delivered.\n"
452"\n"
453"Returns a struct_siginfo containing information about the signal.");
454
455#define SIGNAL_SIGWAITINFO_METHODDEF \
456 {"sigwaitinfo", (PyCFunction)signal_sigwaitinfo, METH_O, signal_sigwaitinfo__doc__},
457
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300458static PyObject *
459signal_sigwaitinfo_impl(PyObject *module, sigset_t sigset);
460
461static PyObject *
462signal_sigwaitinfo(PyObject *module, PyObject *arg)
463{
464 PyObject *return_value = NULL;
465 sigset_t sigset;
466
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200467 if (!_Py_Sigset_Converter(arg, &sigset)) {
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300468 goto exit;
469 }
470 return_value = signal_sigwaitinfo_impl(module, sigset);
471
472exit:
473 return return_value;
474}
475
Tal Einatc7027b72015-05-16 14:14:49 +0300476#endif /* defined(HAVE_SIGWAITINFO) */
477
478#if defined(HAVE_SIGTIMEDWAIT)
479
480PyDoc_STRVAR(signal_sigtimedwait__doc__,
481"sigtimedwait($module, sigset, timeout, /)\n"
482"--\n"
483"\n"
484"Like sigwaitinfo(), but with a timeout.\n"
485"\n"
486"The timeout is specified in seconds, with floating point numbers allowed.");
487
488#define SIGNAL_SIGTIMEDWAIT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200489 {"sigtimedwait", (PyCFunction)(void(*)(void))signal_sigtimedwait, METH_FASTCALL, signal_sigtimedwait__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300490
491static PyObject *
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300492signal_sigtimedwait_impl(PyObject *module, sigset_t sigset,
Serhiy Storchaka6b680cd2015-05-16 15:57:56 +0300493 PyObject *timeout_obj);
Tal Einatc7027b72015-05-16 14:14:49 +0300494
495static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200496signal_sigtimedwait(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300497{
498 PyObject *return_value = NULL;
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300499 sigset_t sigset;
Serhiy Storchaka6b680cd2015-05-16 15:57:56 +0300500 PyObject *timeout_obj;
Tal Einatc7027b72015-05-16 14:14:49 +0300501
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200502 if (!_PyArg_CheckPositional("sigtimedwait", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100503 goto exit;
504 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200505 if (!_Py_Sigset_Converter(args[0], &sigset)) {
506 goto exit;
507 }
508 timeout_obj = args[1];
Serhiy Storchaka6b680cd2015-05-16 15:57:56 +0300509 return_value = signal_sigtimedwait_impl(module, sigset, timeout_obj);
Tal Einatc7027b72015-05-16 14:14:49 +0300510
511exit:
512 return return_value;
513}
514
515#endif /* defined(HAVE_SIGTIMEDWAIT) */
516
Antoine Pitroua6a4dc82017-09-07 18:56:24 +0200517#if defined(HAVE_PTHREAD_KILL)
Tal Einatc7027b72015-05-16 14:14:49 +0300518
519PyDoc_STRVAR(signal_pthread_kill__doc__,
520"pthread_kill($module, thread_id, signalnum, /)\n"
521"--\n"
522"\n"
523"Send a signal to a thread.");
524
525#define SIGNAL_PTHREAD_KILL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200526 {"pthread_kill", (PyCFunction)(void(*)(void))signal_pthread_kill, METH_FASTCALL, signal_pthread_kill__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300527
528static PyObject *
Serhiy Storchakaaefa7eb2017-03-23 15:48:39 +0200529signal_pthread_kill_impl(PyObject *module, unsigned long thread_id,
530 int signalnum);
Tal Einatc7027b72015-05-16 14:14:49 +0300531
532static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200533signal_pthread_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300534{
535 PyObject *return_value = NULL;
Serhiy Storchakaaefa7eb2017-03-23 15:48:39 +0200536 unsigned long thread_id;
Tal Einatc7027b72015-05-16 14:14:49 +0300537 int signalnum;
538
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200539 if (!_PyArg_CheckPositional("pthread_kill", nargs, 2, 2)) {
540 goto exit;
541 }
542 if (!PyLong_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200543 _PyArg_BadArgument("pthread_kill", "argument 1", "int", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200544 goto exit;
545 }
546 thread_id = PyLong_AsUnsignedLongMask(args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200547 signalnum = _PyLong_AsInt(args[1]);
548 if (signalnum == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100549 goto exit;
550 }
Tal Einatc7027b72015-05-16 14:14:49 +0300551 return_value = signal_pthread_kill_impl(module, thread_id, signalnum);
552
553exit:
554 return return_value;
555}
556
Antoine Pitroua6a4dc82017-09-07 18:56:24 +0200557#endif /* defined(HAVE_PTHREAD_KILL) */
Tal Einatc7027b72015-05-16 14:14:49 +0300558
Benjamin Peterson74834512019-11-19 20:39:14 -0800559#if (defined(__linux__) && defined(__NR_pidfd_send_signal))
560
561PyDoc_STRVAR(signal_pidfd_send_signal__doc__,
562"pidfd_send_signal($module, pidfd, signalnum, siginfo=None, flags=0, /)\n"
563"--\n"
564"\n"
565"Send a signal to a process referred to by a pid file descriptor.");
566
567#define SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF \
568 {"pidfd_send_signal", (PyCFunction)(void(*)(void))signal_pidfd_send_signal, METH_FASTCALL, signal_pidfd_send_signal__doc__},
569
570static PyObject *
571signal_pidfd_send_signal_impl(PyObject *module, int pidfd, int signalnum,
572 PyObject *siginfo, int flags);
573
574static PyObject *
575signal_pidfd_send_signal(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
576{
577 PyObject *return_value = NULL;
578 int pidfd;
579 int signalnum;
580 PyObject *siginfo = Py_None;
581 int flags = 0;
582
583 if (!_PyArg_CheckPositional("pidfd_send_signal", nargs, 2, 4)) {
584 goto exit;
585 }
Benjamin Peterson74834512019-11-19 20:39:14 -0800586 pidfd = _PyLong_AsInt(args[0]);
587 if (pidfd == -1 && PyErr_Occurred()) {
588 goto exit;
589 }
Benjamin Peterson74834512019-11-19 20:39:14 -0800590 signalnum = _PyLong_AsInt(args[1]);
591 if (signalnum == -1 && PyErr_Occurred()) {
592 goto exit;
593 }
594 if (nargs < 3) {
595 goto skip_optional;
596 }
597 siginfo = args[2];
598 if (nargs < 4) {
599 goto skip_optional;
600 }
Benjamin Peterson74834512019-11-19 20:39:14 -0800601 flags = _PyLong_AsInt(args[3]);
602 if (flags == -1 && PyErr_Occurred()) {
603 goto exit;
604 }
605skip_optional:
606 return_value = signal_pidfd_send_signal_impl(module, pidfd, signalnum, siginfo, flags);
607
608exit:
609 return return_value;
610}
611
612#endif /* (defined(__linux__) && defined(__NR_pidfd_send_signal)) */
613
Tal Einatc7027b72015-05-16 14:14:49 +0300614#ifndef SIGNAL_ALARM_METHODDEF
615 #define SIGNAL_ALARM_METHODDEF
616#endif /* !defined(SIGNAL_ALARM_METHODDEF) */
617
618#ifndef SIGNAL_PAUSE_METHODDEF
619 #define SIGNAL_PAUSE_METHODDEF
620#endif /* !defined(SIGNAL_PAUSE_METHODDEF) */
621
622#ifndef SIGNAL_SIGINTERRUPT_METHODDEF
623 #define SIGNAL_SIGINTERRUPT_METHODDEF
624#endif /* !defined(SIGNAL_SIGINTERRUPT_METHODDEF) */
625
626#ifndef SIGNAL_SETITIMER_METHODDEF
627 #define SIGNAL_SETITIMER_METHODDEF
628#endif /* !defined(SIGNAL_SETITIMER_METHODDEF) */
629
630#ifndef SIGNAL_GETITIMER_METHODDEF
631 #define SIGNAL_GETITIMER_METHODDEF
632#endif /* !defined(SIGNAL_GETITIMER_METHODDEF) */
633
634#ifndef SIGNAL_PTHREAD_SIGMASK_METHODDEF
635 #define SIGNAL_PTHREAD_SIGMASK_METHODDEF
636#endif /* !defined(SIGNAL_PTHREAD_SIGMASK_METHODDEF) */
637
638#ifndef SIGNAL_SIGPENDING_METHODDEF
639 #define SIGNAL_SIGPENDING_METHODDEF
640#endif /* !defined(SIGNAL_SIGPENDING_METHODDEF) */
641
642#ifndef SIGNAL_SIGWAIT_METHODDEF
643 #define SIGNAL_SIGWAIT_METHODDEF
644#endif /* !defined(SIGNAL_SIGWAIT_METHODDEF) */
645
Antoine Pitrou9d3627e2018-05-04 13:00:50 +0200646#ifndef SIGNAL_VALID_SIGNALS_METHODDEF
647 #define SIGNAL_VALID_SIGNALS_METHODDEF
648#endif /* !defined(SIGNAL_VALID_SIGNALS_METHODDEF) */
649
Tal Einatc7027b72015-05-16 14:14:49 +0300650#ifndef SIGNAL_SIGWAITINFO_METHODDEF
651 #define SIGNAL_SIGWAITINFO_METHODDEF
652#endif /* !defined(SIGNAL_SIGWAITINFO_METHODDEF) */
653
654#ifndef SIGNAL_SIGTIMEDWAIT_METHODDEF
655 #define SIGNAL_SIGTIMEDWAIT_METHODDEF
656#endif /* !defined(SIGNAL_SIGTIMEDWAIT_METHODDEF) */
657
658#ifndef SIGNAL_PTHREAD_KILL_METHODDEF
659 #define SIGNAL_PTHREAD_KILL_METHODDEF
660#endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */
Benjamin Peterson74834512019-11-19 20:39:14 -0800661
662#ifndef SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
663 #define SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
664#endif /* !defined(SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF) */
Serhiy Storchaka578c3952020-05-26 18:43:38 +0300665/*[clinic end generated code: output=dff93c869101f043 input=a9049054013a1b77]*/