blob: 30dc7453380c7ac7cc3ab91cdbd6d8df6126a274 [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
17signal_alarm_impl(PyModuleDef *module, int seconds);
18
19static PyObject *
20signal_alarm(PyModuleDef *module, PyObject *arg)
21{
22 PyObject *return_value = NULL;
23 int seconds;
24 long _return_value;
25
26 if (!PyArg_Parse(arg, "i:alarm", &seconds))
27 goto exit;
28 _return_value = signal_alarm_impl(module, seconds);
29 if ((_return_value == -1) && PyErr_Occurred())
30 goto exit;
31 return_value = PyLong_FromLong(_return_value);
32
33exit:
34 return return_value;
35}
36
37#endif /* defined(HAVE_ALARM) */
38
39#if defined(HAVE_PAUSE)
40
41PyDoc_STRVAR(signal_pause__doc__,
42"pause($module, /)\n"
43"--\n"
44"\n"
45"Wait until a signal arrives.");
46
47#define SIGNAL_PAUSE_METHODDEF \
48 {"pause", (PyCFunction)signal_pause, METH_NOARGS, signal_pause__doc__},
49
50static PyObject *
51signal_pause_impl(PyModuleDef *module);
52
53static PyObject *
54signal_pause(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
55{
56 return signal_pause_impl(module);
57}
58
59#endif /* defined(HAVE_PAUSE) */
60
61PyDoc_STRVAR(signal_signal__doc__,
62"signal($module, signalnum, handler, /)\n"
63"--\n"
64"\n"
65"Set the action for the given signal.\n"
66"\n"
67"The action can be SIG_DFL, SIG_IGN, or a callable Python object.\n"
68"The previous action is returned. See getsignal() for possible return values.\n"
69"\n"
70"*** IMPORTANT NOTICE ***\n"
71"A signal handler function is called with two arguments:\n"
72"the first is the signal number, the second is the interrupted stack frame.");
73
74#define SIGNAL_SIGNAL_METHODDEF \
75 {"signal", (PyCFunction)signal_signal, METH_VARARGS, signal_signal__doc__},
76
77static PyObject *
78signal_signal_impl(PyModuleDef *module, int signalnum, PyObject *handler);
79
80static PyObject *
81signal_signal(PyModuleDef *module, PyObject *args)
82{
83 PyObject *return_value = NULL;
84 int signalnum;
85 PyObject *handler;
86
87 if (!PyArg_ParseTuple(args, "iO:signal",
88 &signalnum, &handler))
89 goto exit;
90 return_value = signal_signal_impl(module, signalnum, handler);
91
92exit:
93 return return_value;
94}
95
96PyDoc_STRVAR(signal_getsignal__doc__,
97"getsignal($module, signalnum, /)\n"
98"--\n"
99"\n"
100"Return the current action for the given signal.\n"
101"\n"
102"The return value can be:\n"
103" SIG_IGN -- if the signal is being ignored\n"
104" SIG_DFL -- if the default action for the signal is in effect\n"
105" None -- if an unknown handler is in effect\n"
106" anything else -- the callable Python object used as a handler");
107
108#define SIGNAL_GETSIGNAL_METHODDEF \
109 {"getsignal", (PyCFunction)signal_getsignal, METH_O, signal_getsignal__doc__},
110
111static PyObject *
112signal_getsignal_impl(PyModuleDef *module, int signalnum);
113
114static PyObject *
115signal_getsignal(PyModuleDef *module, PyObject *arg)
116{
117 PyObject *return_value = NULL;
118 int signalnum;
119
120 if (!PyArg_Parse(arg, "i:getsignal", &signalnum))
121 goto exit;
122 return_value = signal_getsignal_impl(module, signalnum);
123
124exit:
125 return return_value;
126}
127
128#if defined(HAVE_SIGINTERRUPT)
129
130PyDoc_STRVAR(signal_siginterrupt__doc__,
131"siginterrupt($module, signalnum, flag, /)\n"
132"--\n"
133"\n"
134"Change system call restart behaviour.\n"
135"\n"
136"If flag is False, system calls will be restarted when interrupted by\n"
137"signal sig, else system calls will be interrupted.");
138
139#define SIGNAL_SIGINTERRUPT_METHODDEF \
140 {"siginterrupt", (PyCFunction)signal_siginterrupt, METH_VARARGS, signal_siginterrupt__doc__},
141
142static PyObject *
143signal_siginterrupt_impl(PyModuleDef *module, int signalnum, int flag);
144
145static PyObject *
146signal_siginterrupt(PyModuleDef *module, PyObject *args)
147{
148 PyObject *return_value = NULL;
149 int signalnum;
150 int flag;
151
152 if (!PyArg_ParseTuple(args, "ii:siginterrupt",
153 &signalnum, &flag))
154 goto exit;
155 return_value = signal_siginterrupt_impl(module, signalnum, flag);
156
157exit:
158 return return_value;
159}
160
161#endif /* defined(HAVE_SIGINTERRUPT) */
162
163#if defined(HAVE_SETITIMER)
164
165PyDoc_STRVAR(signal_setitimer__doc__,
166"setitimer($module, which, seconds, interval=0.0, /)\n"
167"--\n"
168"\n"
169"Sets given itimer (one of ITIMER_REAL, ITIMER_VIRTUAL or ITIMER_PROF).\n"
170"\n"
171"The timer will fire after value seconds and after that every interval seconds.\n"
172"The itimer can be cleared by setting seconds to zero.\n"
173"\n"
174"Returns old values as a tuple: (delay, interval).");
175
176#define SIGNAL_SETITIMER_METHODDEF \
177 {"setitimer", (PyCFunction)signal_setitimer, METH_VARARGS, signal_setitimer__doc__},
178
179static PyObject *
180signal_setitimer_impl(PyModuleDef *module, int which, double seconds,
181 double interval);
182
183static PyObject *
184signal_setitimer(PyModuleDef *module, PyObject *args)
185{
186 PyObject *return_value = NULL;
187 int which;
188 double seconds;
189 double interval = 0.0;
190
191 if (!PyArg_ParseTuple(args, "id|d:setitimer",
192 &which, &seconds, &interval))
193 goto exit;
194 return_value = signal_setitimer_impl(module, which, seconds, interval);
195
196exit:
197 return return_value;
198}
199
200#endif /* defined(HAVE_SETITIMER) */
201
202#if defined(HAVE_GETITIMER)
203
204PyDoc_STRVAR(signal_getitimer__doc__,
205"getitimer($module, which, /)\n"
206"--\n"
207"\n"
208"Returns current value of given itimer.");
209
210#define SIGNAL_GETITIMER_METHODDEF \
211 {"getitimer", (PyCFunction)signal_getitimer, METH_O, signal_getitimer__doc__},
212
213static PyObject *
214signal_getitimer_impl(PyModuleDef *module, int which);
215
216static PyObject *
217signal_getitimer(PyModuleDef *module, PyObject *arg)
218{
219 PyObject *return_value = NULL;
220 int which;
221
222 if (!PyArg_Parse(arg, "i:getitimer", &which))
223 goto exit;
224 return_value = signal_getitimer_impl(module, which);
225
226exit:
227 return return_value;
228}
229
230#endif /* defined(HAVE_GETITIMER) */
231
232#if defined(PYPTHREAD_SIGMASK)
233
234PyDoc_STRVAR(signal_pthread_sigmask__doc__,
235"pthread_sigmask($module, how, mask, /)\n"
236"--\n"
237"\n"
238"Fetch and/or change the signal mask of the calling thread.");
239
240#define SIGNAL_PTHREAD_SIGMASK_METHODDEF \
241 {"pthread_sigmask", (PyCFunction)signal_pthread_sigmask, METH_VARARGS, signal_pthread_sigmask__doc__},
242
243static PyObject *
244signal_pthread_sigmask_impl(PyModuleDef *module, int how, PyObject *mask);
245
246static PyObject *
247signal_pthread_sigmask(PyModuleDef *module, PyObject *args)
248{
249 PyObject *return_value = NULL;
250 int how;
251 PyObject *mask;
252
253 if (!PyArg_ParseTuple(args, "iO:pthread_sigmask",
254 &how, &mask))
255 goto exit;
256 return_value = signal_pthread_sigmask_impl(module, how, mask);
257
258exit:
259 return return_value;
260}
261
262#endif /* defined(PYPTHREAD_SIGMASK) */
263
264#if defined(HAVE_SIGPENDING)
265
266PyDoc_STRVAR(signal_sigpending__doc__,
267"sigpending($module, /)\n"
268"--\n"
269"\n"
270"Examine pending signals.\n"
271"\n"
272"Returns a set of signal numbers that are pending for delivery to\n"
273"the calling thread.");
274
275#define SIGNAL_SIGPENDING_METHODDEF \
276 {"sigpending", (PyCFunction)signal_sigpending, METH_NOARGS, signal_sigpending__doc__},
277
278static PyObject *
279signal_sigpending_impl(PyModuleDef *module);
280
281static PyObject *
282signal_sigpending(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
283{
284 return signal_sigpending_impl(module);
285}
286
287#endif /* defined(HAVE_SIGPENDING) */
288
289#if defined(HAVE_SIGWAIT)
290
291PyDoc_STRVAR(signal_sigwait__doc__,
292"sigwait($module, sigset, /)\n"
293"--\n"
294"\n"
295"Wait for a signal.\n"
296"\n"
297"Suspend execution of the calling thread until the delivery of one of the\n"
298"signals specified in the signal set sigset. The function accepts the signal\n"
299"and returns the signal number.");
300
301#define SIGNAL_SIGWAIT_METHODDEF \
302 {"sigwait", (PyCFunction)signal_sigwait, METH_O, signal_sigwait__doc__},
303
304#endif /* defined(HAVE_SIGWAIT) */
305
306#if defined(HAVE_SIGWAITINFO)
307
308PyDoc_STRVAR(signal_sigwaitinfo__doc__,
309"sigwaitinfo($module, sigset, /)\n"
310"--\n"
311"\n"
312"Wait synchronously until one of the signals in *sigset* is delivered.\n"
313"\n"
314"Returns a struct_siginfo containing information about the signal.");
315
316#define SIGNAL_SIGWAITINFO_METHODDEF \
317 {"sigwaitinfo", (PyCFunction)signal_sigwaitinfo, METH_O, signal_sigwaitinfo__doc__},
318
319#endif /* defined(HAVE_SIGWAITINFO) */
320
321#if defined(HAVE_SIGTIMEDWAIT)
322
323PyDoc_STRVAR(signal_sigtimedwait__doc__,
324"sigtimedwait($module, sigset, timeout, /)\n"
325"--\n"
326"\n"
327"Like sigwaitinfo(), but with a timeout.\n"
328"\n"
329"The timeout is specified in seconds, with floating point numbers allowed.");
330
331#define SIGNAL_SIGTIMEDWAIT_METHODDEF \
332 {"sigtimedwait", (PyCFunction)signal_sigtimedwait, METH_VARARGS, signal_sigtimedwait__doc__},
333
334static PyObject *
335signal_sigtimedwait_impl(PyModuleDef *module, PyObject *sigset,
336 PyObject *timeout);
337
338static PyObject *
339signal_sigtimedwait(PyModuleDef *module, PyObject *args)
340{
341 PyObject *return_value = NULL;
342 PyObject *sigset;
343 PyObject *timeout;
344
345 if (!PyArg_UnpackTuple(args, "sigtimedwait",
346 2, 2,
347 &sigset, &timeout))
348 goto exit;
349 return_value = signal_sigtimedwait_impl(module, sigset, timeout);
350
351exit:
352 return return_value;
353}
354
355#endif /* defined(HAVE_SIGTIMEDWAIT) */
356
357#if (defined(HAVE_PTHREAD_KILL) && defined(WITH_THREAD))
358
359PyDoc_STRVAR(signal_pthread_kill__doc__,
360"pthread_kill($module, thread_id, signalnum, /)\n"
361"--\n"
362"\n"
363"Send a signal to a thread.");
364
365#define SIGNAL_PTHREAD_KILL_METHODDEF \
366 {"pthread_kill", (PyCFunction)signal_pthread_kill, METH_VARARGS, signal_pthread_kill__doc__},
367
368static PyObject *
369signal_pthread_kill_impl(PyModuleDef *module, long thread_id, int signalnum);
370
371static PyObject *
372signal_pthread_kill(PyModuleDef *module, PyObject *args)
373{
374 PyObject *return_value = NULL;
375 long thread_id;
376 int signalnum;
377
378 if (!PyArg_ParseTuple(args, "li:pthread_kill",
379 &thread_id, &signalnum))
380 goto exit;
381 return_value = signal_pthread_kill_impl(module, thread_id, signalnum);
382
383exit:
384 return return_value;
385}
386
387#endif /* (defined(HAVE_PTHREAD_KILL) && defined(WITH_THREAD)) */
388
389#ifndef SIGNAL_ALARM_METHODDEF
390 #define SIGNAL_ALARM_METHODDEF
391#endif /* !defined(SIGNAL_ALARM_METHODDEF) */
392
393#ifndef SIGNAL_PAUSE_METHODDEF
394 #define SIGNAL_PAUSE_METHODDEF
395#endif /* !defined(SIGNAL_PAUSE_METHODDEF) */
396
397#ifndef SIGNAL_SIGINTERRUPT_METHODDEF
398 #define SIGNAL_SIGINTERRUPT_METHODDEF
399#endif /* !defined(SIGNAL_SIGINTERRUPT_METHODDEF) */
400
401#ifndef SIGNAL_SETITIMER_METHODDEF
402 #define SIGNAL_SETITIMER_METHODDEF
403#endif /* !defined(SIGNAL_SETITIMER_METHODDEF) */
404
405#ifndef SIGNAL_GETITIMER_METHODDEF
406 #define SIGNAL_GETITIMER_METHODDEF
407#endif /* !defined(SIGNAL_GETITIMER_METHODDEF) */
408
409#ifndef SIGNAL_PTHREAD_SIGMASK_METHODDEF
410 #define SIGNAL_PTHREAD_SIGMASK_METHODDEF
411#endif /* !defined(SIGNAL_PTHREAD_SIGMASK_METHODDEF) */
412
413#ifndef SIGNAL_SIGPENDING_METHODDEF
414 #define SIGNAL_SIGPENDING_METHODDEF
415#endif /* !defined(SIGNAL_SIGPENDING_METHODDEF) */
416
417#ifndef SIGNAL_SIGWAIT_METHODDEF
418 #define SIGNAL_SIGWAIT_METHODDEF
419#endif /* !defined(SIGNAL_SIGWAIT_METHODDEF) */
420
421#ifndef SIGNAL_SIGWAITINFO_METHODDEF
422 #define SIGNAL_SIGWAITINFO_METHODDEF
423#endif /* !defined(SIGNAL_SIGWAITINFO_METHODDEF) */
424
425#ifndef SIGNAL_SIGTIMEDWAIT_METHODDEF
426 #define SIGNAL_SIGTIMEDWAIT_METHODDEF
427#endif /* !defined(SIGNAL_SIGTIMEDWAIT_METHODDEF) */
428
429#ifndef SIGNAL_PTHREAD_KILL_METHODDEF
430 #define SIGNAL_PTHREAD_KILL_METHODDEF
431#endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */
432/*[clinic end generated code: output=65ca7b83632eda99 input=a9049054013a1b77]*/