blob: 1c439716c4988033d88173b9c30b8c3b87caa7b4 [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 Storchaka5dee6552016-06-09 16:16:06 +030026 if (!PyArg_Parse(arg, "i:alarm", &seconds)) {
Tal Einatc7027b72015-05-16 14:14:49 +030027 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030028 }
Tal Einatc7027b72015-05-16 14:14:49 +030029 _return_value = signal_alarm_impl(module, seconds);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030030 if ((_return_value == -1) && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +030031 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030032 }
Tal Einatc7027b72015-05-16 14:14:49 +030033 return_value = PyLong_FromLong(_return_value);
34
35exit:
36 return return_value;
37}
38
39#endif /* defined(HAVE_ALARM) */
40
41#if defined(HAVE_PAUSE)
42
43PyDoc_STRVAR(signal_pause__doc__,
44"pause($module, /)\n"
45"--\n"
46"\n"
47"Wait until a signal arrives.");
48
49#define SIGNAL_PAUSE_METHODDEF \
50 {"pause", (PyCFunction)signal_pause, METH_NOARGS, signal_pause__doc__},
51
52static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030053signal_pause_impl(PyObject *module);
Tal Einatc7027b72015-05-16 14:14:49 +030054
55static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030056signal_pause(PyObject *module, PyObject *Py_UNUSED(ignored))
Tal Einatc7027b72015-05-16 14:14:49 +030057{
58 return signal_pause_impl(module);
59}
60
61#endif /* defined(HAVE_PAUSE) */
62
63PyDoc_STRVAR(signal_signal__doc__,
64"signal($module, signalnum, handler, /)\n"
65"--\n"
66"\n"
67"Set the action for the given signal.\n"
68"\n"
69"The action can be SIG_DFL, SIG_IGN, or a callable Python object.\n"
70"The previous action is returned. See getsignal() for possible return values.\n"
71"\n"
72"*** IMPORTANT NOTICE ***\n"
73"A signal handler function is called with two arguments:\n"
74"the first is the signal number, the second is the interrupted stack frame.");
75
76#define SIGNAL_SIGNAL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +010077 {"signal", (PyCFunction)signal_signal, METH_FASTCALL, signal_signal__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +030078
79static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030080signal_signal_impl(PyObject *module, int signalnum, PyObject *handler);
Tal Einatc7027b72015-05-16 14:14:49 +030081
82static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020083signal_signal(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +030084{
85 PyObject *return_value = NULL;
86 int signalnum;
87 PyObject *handler;
88
Sylvain74453812017-06-10 06:51:48 +020089 if (!_PyArg_ParseStack(args, nargs, "iO:signal",
90 &signalnum, &handler)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010091 goto exit;
92 }
Tal Einatc7027b72015-05-16 14:14:49 +030093 return_value = signal_signal_impl(module, signalnum, handler);
94
95exit:
96 return return_value;
97}
98
99PyDoc_STRVAR(signal_getsignal__doc__,
100"getsignal($module, signalnum, /)\n"
101"--\n"
102"\n"
103"Return the current action for the given signal.\n"
104"\n"
105"The return value can be:\n"
106" SIG_IGN -- if the signal is being ignored\n"
107" SIG_DFL -- if the default action for the signal is in effect\n"
108" None -- if an unknown handler is in effect\n"
109" anything else -- the callable Python object used as a handler");
110
111#define SIGNAL_GETSIGNAL_METHODDEF \
112 {"getsignal", (PyCFunction)signal_getsignal, METH_O, signal_getsignal__doc__},
113
114static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300115signal_getsignal_impl(PyObject *module, int signalnum);
Tal Einatc7027b72015-05-16 14:14:49 +0300116
117static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300118signal_getsignal(PyObject *module, PyObject *arg)
Tal Einatc7027b72015-05-16 14:14:49 +0300119{
120 PyObject *return_value = NULL;
121 int signalnum;
122
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300123 if (!PyArg_Parse(arg, "i:getsignal", &signalnum)) {
Tal Einatc7027b72015-05-16 14:14:49 +0300124 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300125 }
Tal Einatc7027b72015-05-16 14:14:49 +0300126 return_value = signal_getsignal_impl(module, signalnum);
127
128exit:
129 return return_value;
130}
131
Antoine Pietri5d2a27d2018-03-12 14:42:34 +0100132PyDoc_STRVAR(signal_strsignal__doc__,
133"strsignal($module, signalnum, /)\n"
134"--\n"
135"\n"
136"Return the system description of the given signal.\n"
137"\n"
138"The return values can be such as \"Interrupt\", \"Segmentation fault\", etc.\n"
139"Returns None if the signal is not recognized.");
140
141#define SIGNAL_STRSIGNAL_METHODDEF \
142 {"strsignal", (PyCFunction)signal_strsignal, METH_O, signal_strsignal__doc__},
143
144static PyObject *
145signal_strsignal_impl(PyObject *module, int signalnum);
146
147static PyObject *
148signal_strsignal(PyObject *module, PyObject *arg)
149{
150 PyObject *return_value = NULL;
151 int signalnum;
152
153 if (!PyArg_Parse(arg, "i:strsignal", &signalnum)) {
154 goto exit;
155 }
156 return_value = signal_strsignal_impl(module, signalnum);
157
158exit:
159 return return_value;
160}
161
Tal Einatc7027b72015-05-16 14:14:49 +0300162#if defined(HAVE_SIGINTERRUPT)
163
164PyDoc_STRVAR(signal_siginterrupt__doc__,
165"siginterrupt($module, signalnum, flag, /)\n"
166"--\n"
167"\n"
168"Change system call restart behaviour.\n"
169"\n"
170"If flag is False, system calls will be restarted when interrupted by\n"
171"signal sig, else system calls will be interrupted.");
172
173#define SIGNAL_SIGINTERRUPT_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100174 {"siginterrupt", (PyCFunction)signal_siginterrupt, METH_FASTCALL, signal_siginterrupt__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300175
176static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300177signal_siginterrupt_impl(PyObject *module, int signalnum, int flag);
Tal Einatc7027b72015-05-16 14:14:49 +0300178
179static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200180signal_siginterrupt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300181{
182 PyObject *return_value = NULL;
183 int signalnum;
184 int flag;
185
Sylvain74453812017-06-10 06:51:48 +0200186 if (!_PyArg_ParseStack(args, nargs, "ii:siginterrupt",
187 &signalnum, &flag)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100188 goto exit;
189 }
Tal Einatc7027b72015-05-16 14:14:49 +0300190 return_value = signal_siginterrupt_impl(module, signalnum, flag);
191
192exit:
193 return return_value;
194}
195
196#endif /* defined(HAVE_SIGINTERRUPT) */
197
198#if defined(HAVE_SETITIMER)
199
200PyDoc_STRVAR(signal_setitimer__doc__,
201"setitimer($module, which, seconds, interval=0.0, /)\n"
202"--\n"
203"\n"
204"Sets given itimer (one of ITIMER_REAL, ITIMER_VIRTUAL or ITIMER_PROF).\n"
205"\n"
206"The timer will fire after value seconds and after that every interval seconds.\n"
207"The itimer can be cleared by setting seconds to zero.\n"
208"\n"
209"Returns old values as a tuple: (delay, interval).");
210
211#define SIGNAL_SETITIMER_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100212 {"setitimer", (PyCFunction)signal_setitimer, METH_FASTCALL, signal_setitimer__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300213
214static PyObject *
Victor Stinneref611c92017-10-13 13:49:43 -0700215signal_setitimer_impl(PyObject *module, int which, PyObject *seconds,
216 PyObject *interval);
Tal Einatc7027b72015-05-16 14:14:49 +0300217
218static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200219signal_setitimer(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300220{
221 PyObject *return_value = NULL;
222 int which;
Victor Stinneref611c92017-10-13 13:49:43 -0700223 PyObject *seconds;
224 PyObject *interval = NULL;
Tal Einatc7027b72015-05-16 14:14:49 +0300225
Victor Stinneref611c92017-10-13 13:49:43 -0700226 if (!_PyArg_ParseStack(args, nargs, "iO|O:setitimer",
Sylvain74453812017-06-10 06:51:48 +0200227 &which, &seconds, &interval)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100228 goto exit;
229 }
Tal Einatc7027b72015-05-16 14:14:49 +0300230 return_value = signal_setitimer_impl(module, which, seconds, interval);
231
232exit:
233 return return_value;
234}
235
236#endif /* defined(HAVE_SETITIMER) */
237
238#if defined(HAVE_GETITIMER)
239
240PyDoc_STRVAR(signal_getitimer__doc__,
241"getitimer($module, which, /)\n"
242"--\n"
243"\n"
244"Returns current value of given itimer.");
245
246#define SIGNAL_GETITIMER_METHODDEF \
247 {"getitimer", (PyCFunction)signal_getitimer, METH_O, signal_getitimer__doc__},
248
249static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300250signal_getitimer_impl(PyObject *module, int which);
Tal Einatc7027b72015-05-16 14:14:49 +0300251
252static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300253signal_getitimer(PyObject *module, PyObject *arg)
Tal Einatc7027b72015-05-16 14:14:49 +0300254{
255 PyObject *return_value = NULL;
256 int which;
257
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300258 if (!PyArg_Parse(arg, "i:getitimer", &which)) {
Tal Einatc7027b72015-05-16 14:14:49 +0300259 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300260 }
Tal Einatc7027b72015-05-16 14:14:49 +0300261 return_value = signal_getitimer_impl(module, which);
262
263exit:
264 return return_value;
265}
266
267#endif /* defined(HAVE_GETITIMER) */
268
269#if defined(PYPTHREAD_SIGMASK)
270
271PyDoc_STRVAR(signal_pthread_sigmask__doc__,
272"pthread_sigmask($module, how, mask, /)\n"
273"--\n"
274"\n"
275"Fetch and/or change the signal mask of the calling thread.");
276
277#define SIGNAL_PTHREAD_SIGMASK_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100278 {"pthread_sigmask", (PyCFunction)signal_pthread_sigmask, METH_FASTCALL, signal_pthread_sigmask__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300279
280static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300281signal_pthread_sigmask_impl(PyObject *module, int how, PyObject *mask);
Tal Einatc7027b72015-05-16 14:14:49 +0300282
283static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200284signal_pthread_sigmask(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300285{
286 PyObject *return_value = NULL;
287 int how;
288 PyObject *mask;
289
Sylvain74453812017-06-10 06:51:48 +0200290 if (!_PyArg_ParseStack(args, nargs, "iO:pthread_sigmask",
291 &how, &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100292 goto exit;
293 }
Tal Einatc7027b72015-05-16 14:14:49 +0300294 return_value = signal_pthread_sigmask_impl(module, how, mask);
295
296exit:
297 return return_value;
298}
299
300#endif /* defined(PYPTHREAD_SIGMASK) */
301
302#if defined(HAVE_SIGPENDING)
303
304PyDoc_STRVAR(signal_sigpending__doc__,
305"sigpending($module, /)\n"
306"--\n"
307"\n"
308"Examine pending signals.\n"
309"\n"
310"Returns a set of signal numbers that are pending for delivery to\n"
311"the calling thread.");
312
313#define SIGNAL_SIGPENDING_METHODDEF \
314 {"sigpending", (PyCFunction)signal_sigpending, METH_NOARGS, signal_sigpending__doc__},
315
316static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300317signal_sigpending_impl(PyObject *module);
Tal Einatc7027b72015-05-16 14:14:49 +0300318
319static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300320signal_sigpending(PyObject *module, PyObject *Py_UNUSED(ignored))
Tal Einatc7027b72015-05-16 14:14:49 +0300321{
322 return signal_sigpending_impl(module);
323}
324
325#endif /* defined(HAVE_SIGPENDING) */
326
327#if defined(HAVE_SIGWAIT)
328
329PyDoc_STRVAR(signal_sigwait__doc__,
330"sigwait($module, sigset, /)\n"
331"--\n"
332"\n"
333"Wait for a signal.\n"
334"\n"
335"Suspend execution of the calling thread until the delivery of one of the\n"
336"signals specified in the signal set sigset. The function accepts the signal\n"
337"and returns the signal number.");
338
339#define SIGNAL_SIGWAIT_METHODDEF \
340 {"sigwait", (PyCFunction)signal_sigwait, METH_O, signal_sigwait__doc__},
341
342#endif /* defined(HAVE_SIGWAIT) */
343
344#if defined(HAVE_SIGWAITINFO)
345
346PyDoc_STRVAR(signal_sigwaitinfo__doc__,
347"sigwaitinfo($module, sigset, /)\n"
348"--\n"
349"\n"
350"Wait synchronously until one of the signals in *sigset* is delivered.\n"
351"\n"
352"Returns a struct_siginfo containing information about the signal.");
353
354#define SIGNAL_SIGWAITINFO_METHODDEF \
355 {"sigwaitinfo", (PyCFunction)signal_sigwaitinfo, METH_O, signal_sigwaitinfo__doc__},
356
357#endif /* defined(HAVE_SIGWAITINFO) */
358
359#if defined(HAVE_SIGTIMEDWAIT)
360
361PyDoc_STRVAR(signal_sigtimedwait__doc__,
362"sigtimedwait($module, sigset, timeout, /)\n"
363"--\n"
364"\n"
365"Like sigwaitinfo(), but with a timeout.\n"
366"\n"
367"The timeout is specified in seconds, with floating point numbers allowed.");
368
369#define SIGNAL_SIGTIMEDWAIT_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100370 {"sigtimedwait", (PyCFunction)signal_sigtimedwait, METH_FASTCALL, signal_sigtimedwait__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300371
372static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300373signal_sigtimedwait_impl(PyObject *module, PyObject *sigset,
Serhiy Storchaka6b680cd2015-05-16 15:57:56 +0300374 PyObject *timeout_obj);
Tal Einatc7027b72015-05-16 14:14:49 +0300375
376static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200377signal_sigtimedwait(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300378{
379 PyObject *return_value = NULL;
380 PyObject *sigset;
Serhiy Storchaka6b680cd2015-05-16 15:57:56 +0300381 PyObject *timeout_obj;
Tal Einatc7027b72015-05-16 14:14:49 +0300382
Sylvain74453812017-06-10 06:51:48 +0200383 if (!_PyArg_UnpackStack(args, nargs, "sigtimedwait",
384 2, 2,
385 &sigset, &timeout_obj)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100386 goto exit;
387 }
Serhiy Storchaka6b680cd2015-05-16 15:57:56 +0300388 return_value = signal_sigtimedwait_impl(module, sigset, timeout_obj);
Tal Einatc7027b72015-05-16 14:14:49 +0300389
390exit:
391 return return_value;
392}
393
394#endif /* defined(HAVE_SIGTIMEDWAIT) */
395
Antoine Pitroua6a4dc82017-09-07 18:56:24 +0200396#if defined(HAVE_PTHREAD_KILL)
Tal Einatc7027b72015-05-16 14:14:49 +0300397
398PyDoc_STRVAR(signal_pthread_kill__doc__,
399"pthread_kill($module, thread_id, signalnum, /)\n"
400"--\n"
401"\n"
402"Send a signal to a thread.");
403
404#define SIGNAL_PTHREAD_KILL_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100405 {"pthread_kill", (PyCFunction)signal_pthread_kill, METH_FASTCALL, signal_pthread_kill__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300406
407static PyObject *
Serhiy Storchakaaefa7eb2017-03-23 15:48:39 +0200408signal_pthread_kill_impl(PyObject *module, unsigned long thread_id,
409 int signalnum);
Tal Einatc7027b72015-05-16 14:14:49 +0300410
411static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200412signal_pthread_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300413{
414 PyObject *return_value = NULL;
Serhiy Storchakaaefa7eb2017-03-23 15:48:39 +0200415 unsigned long thread_id;
Tal Einatc7027b72015-05-16 14:14:49 +0300416 int signalnum;
417
Sylvain74453812017-06-10 06:51:48 +0200418 if (!_PyArg_ParseStack(args, nargs, "ki:pthread_kill",
419 &thread_id, &signalnum)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100420 goto exit;
421 }
Tal Einatc7027b72015-05-16 14:14:49 +0300422 return_value = signal_pthread_kill_impl(module, thread_id, signalnum);
423
424exit:
425 return return_value;
426}
427
Antoine Pitroua6a4dc82017-09-07 18:56:24 +0200428#endif /* defined(HAVE_PTHREAD_KILL) */
Tal Einatc7027b72015-05-16 14:14:49 +0300429
430#ifndef SIGNAL_ALARM_METHODDEF
431 #define SIGNAL_ALARM_METHODDEF
432#endif /* !defined(SIGNAL_ALARM_METHODDEF) */
433
434#ifndef SIGNAL_PAUSE_METHODDEF
435 #define SIGNAL_PAUSE_METHODDEF
436#endif /* !defined(SIGNAL_PAUSE_METHODDEF) */
437
438#ifndef SIGNAL_SIGINTERRUPT_METHODDEF
439 #define SIGNAL_SIGINTERRUPT_METHODDEF
440#endif /* !defined(SIGNAL_SIGINTERRUPT_METHODDEF) */
441
442#ifndef SIGNAL_SETITIMER_METHODDEF
443 #define SIGNAL_SETITIMER_METHODDEF
444#endif /* !defined(SIGNAL_SETITIMER_METHODDEF) */
445
446#ifndef SIGNAL_GETITIMER_METHODDEF
447 #define SIGNAL_GETITIMER_METHODDEF
448#endif /* !defined(SIGNAL_GETITIMER_METHODDEF) */
449
450#ifndef SIGNAL_PTHREAD_SIGMASK_METHODDEF
451 #define SIGNAL_PTHREAD_SIGMASK_METHODDEF
452#endif /* !defined(SIGNAL_PTHREAD_SIGMASK_METHODDEF) */
453
454#ifndef SIGNAL_SIGPENDING_METHODDEF
455 #define SIGNAL_SIGPENDING_METHODDEF
456#endif /* !defined(SIGNAL_SIGPENDING_METHODDEF) */
457
458#ifndef SIGNAL_SIGWAIT_METHODDEF
459 #define SIGNAL_SIGWAIT_METHODDEF
460#endif /* !defined(SIGNAL_SIGWAIT_METHODDEF) */
461
462#ifndef SIGNAL_SIGWAITINFO_METHODDEF
463 #define SIGNAL_SIGWAITINFO_METHODDEF
464#endif /* !defined(SIGNAL_SIGWAITINFO_METHODDEF) */
465
466#ifndef SIGNAL_SIGTIMEDWAIT_METHODDEF
467 #define SIGNAL_SIGTIMEDWAIT_METHODDEF
468#endif /* !defined(SIGNAL_SIGTIMEDWAIT_METHODDEF) */
469
470#ifndef SIGNAL_PTHREAD_KILL_METHODDEF
471 #define SIGNAL_PTHREAD_KILL_METHODDEF
472#endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */
Antoine Pietri5d2a27d2018-03-12 14:42:34 +0100473/*[clinic end generated code: output=7b41486acf93aa8e input=a9049054013a1b77]*/