Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | #if defined(HAVE_ALARM) |
| 6 | |
| 7 | PyDoc_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 | |
| 16 | static long |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 17 | signal_alarm_impl(PyObject *module, int seconds); |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 18 | |
| 19 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 20 | signal_alarm(PyObject *module, PyObject *arg) |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 21 | { |
| 22 | PyObject *return_value = NULL; |
| 23 | int seconds; |
| 24 | long _return_value; |
| 25 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 26 | if (PyFloat_Check(arg)) { |
| 27 | PyErr_SetString(PyExc_TypeError, |
| 28 | "integer argument expected, got float" ); |
| 29 | goto exit; |
| 30 | } |
| 31 | seconds = _PyLong_AsInt(arg); |
| 32 | if (seconds == -1 && PyErr_Occurred()) { |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 33 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 34 | } |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 35 | _return_value = signal_alarm_impl(module, seconds); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 36 | if ((_return_value == -1) && PyErr_Occurred()) { |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 37 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 38 | } |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 39 | return_value = PyLong_FromLong(_return_value); |
| 40 | |
| 41 | exit: |
| 42 | return return_value; |
| 43 | } |
| 44 | |
| 45 | #endif /* defined(HAVE_ALARM) */ |
| 46 | |
| 47 | #if defined(HAVE_PAUSE) |
| 48 | |
| 49 | PyDoc_STRVAR(signal_pause__doc__, |
| 50 | "pause($module, /)\n" |
| 51 | "--\n" |
| 52 | "\n" |
| 53 | "Wait until a signal arrives."); |
| 54 | |
| 55 | #define SIGNAL_PAUSE_METHODDEF \ |
| 56 | {"pause", (PyCFunction)signal_pause, METH_NOARGS, signal_pause__doc__}, |
| 57 | |
| 58 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 59 | signal_pause_impl(PyObject *module); |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 60 | |
| 61 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 62 | signal_pause(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 63 | { |
| 64 | return signal_pause_impl(module); |
| 65 | } |
| 66 | |
| 67 | #endif /* defined(HAVE_PAUSE) */ |
| 68 | |
Vladimir Matveev | c24c6c2 | 2019-01-08 01:58:25 -0800 | [diff] [blame^] | 69 | PyDoc_STRVAR(signal_raise_signal__doc__, |
| 70 | "raise_signal($module, signalnum, /)\n" |
| 71 | "--\n" |
| 72 | "\n" |
| 73 | "Send a signal to the executing process."); |
| 74 | |
| 75 | #define SIGNAL_RAISE_SIGNAL_METHODDEF \ |
| 76 | {"raise_signal", (PyCFunction)signal_raise_signal, METH_O, signal_raise_signal__doc__}, |
| 77 | |
| 78 | static PyObject * |
| 79 | signal_raise_signal_impl(PyObject *module, int signalnum); |
| 80 | |
| 81 | static PyObject * |
| 82 | signal_raise_signal(PyObject *module, PyObject *arg) |
| 83 | { |
| 84 | PyObject *return_value = NULL; |
| 85 | int signalnum; |
| 86 | |
| 87 | if (PyFloat_Check(arg)) { |
| 88 | PyErr_SetString(PyExc_TypeError, |
| 89 | "integer argument expected, got float" ); |
| 90 | goto exit; |
| 91 | } |
| 92 | signalnum = _PyLong_AsInt(arg); |
| 93 | if (signalnum == -1 && PyErr_Occurred()) { |
| 94 | goto exit; |
| 95 | } |
| 96 | return_value = signal_raise_signal_impl(module, signalnum); |
| 97 | |
| 98 | exit: |
| 99 | return return_value; |
| 100 | } |
| 101 | |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 102 | PyDoc_STRVAR(signal_signal__doc__, |
| 103 | "signal($module, signalnum, handler, /)\n" |
| 104 | "--\n" |
| 105 | "\n" |
| 106 | "Set the action for the given signal.\n" |
| 107 | "\n" |
| 108 | "The action can be SIG_DFL, SIG_IGN, or a callable Python object.\n" |
| 109 | "The previous action is returned. See getsignal() for possible return values.\n" |
| 110 | "\n" |
| 111 | "*** IMPORTANT NOTICE ***\n" |
| 112 | "A signal handler function is called with two arguments:\n" |
| 113 | "the first is the signal number, the second is the interrupted stack frame."); |
| 114 | |
| 115 | #define SIGNAL_SIGNAL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 116 | {"signal", (PyCFunction)(void(*)(void))signal_signal, METH_FASTCALL, signal_signal__doc__}, |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 117 | |
| 118 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 119 | signal_signal_impl(PyObject *module, int signalnum, PyObject *handler); |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 120 | |
| 121 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 122 | signal_signal(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 123 | { |
| 124 | PyObject *return_value = NULL; |
| 125 | int signalnum; |
| 126 | PyObject *handler; |
| 127 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 128 | if (!_PyArg_ParseStack(args, nargs, "iO:signal", |
| 129 | &signalnum, &handler)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 130 | goto exit; |
| 131 | } |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 132 | return_value = signal_signal_impl(module, signalnum, handler); |
| 133 | |
| 134 | exit: |
| 135 | return return_value; |
| 136 | } |
| 137 | |
| 138 | PyDoc_STRVAR(signal_getsignal__doc__, |
| 139 | "getsignal($module, signalnum, /)\n" |
| 140 | "--\n" |
| 141 | "\n" |
| 142 | "Return the current action for the given signal.\n" |
| 143 | "\n" |
| 144 | "The return value can be:\n" |
| 145 | " SIG_IGN -- if the signal is being ignored\n" |
| 146 | " SIG_DFL -- if the default action for the signal is in effect\n" |
| 147 | " None -- if an unknown handler is in effect\n" |
| 148 | " anything else -- the callable Python object used as a handler"); |
| 149 | |
| 150 | #define SIGNAL_GETSIGNAL_METHODDEF \ |
| 151 | {"getsignal", (PyCFunction)signal_getsignal, METH_O, signal_getsignal__doc__}, |
| 152 | |
| 153 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 154 | signal_getsignal_impl(PyObject *module, int signalnum); |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 155 | |
| 156 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 157 | signal_getsignal(PyObject *module, PyObject *arg) |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 158 | { |
| 159 | PyObject *return_value = NULL; |
| 160 | int signalnum; |
| 161 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 162 | if (PyFloat_Check(arg)) { |
| 163 | PyErr_SetString(PyExc_TypeError, |
| 164 | "integer argument expected, got float" ); |
| 165 | goto exit; |
| 166 | } |
| 167 | signalnum = _PyLong_AsInt(arg); |
| 168 | if (signalnum == -1 && PyErr_Occurred()) { |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 169 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 170 | } |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 171 | return_value = signal_getsignal_impl(module, signalnum); |
| 172 | |
| 173 | exit: |
| 174 | return return_value; |
| 175 | } |
| 176 | |
Antoine Pietri | 5d2a27d | 2018-03-12 14:42:34 +0100 | [diff] [blame] | 177 | PyDoc_STRVAR(signal_strsignal__doc__, |
| 178 | "strsignal($module, signalnum, /)\n" |
| 179 | "--\n" |
| 180 | "\n" |
| 181 | "Return the system description of the given signal.\n" |
| 182 | "\n" |
| 183 | "The return values can be such as \"Interrupt\", \"Segmentation fault\", etc.\n" |
| 184 | "Returns None if the signal is not recognized."); |
| 185 | |
| 186 | #define SIGNAL_STRSIGNAL_METHODDEF \ |
| 187 | {"strsignal", (PyCFunction)signal_strsignal, METH_O, signal_strsignal__doc__}, |
| 188 | |
| 189 | static PyObject * |
| 190 | signal_strsignal_impl(PyObject *module, int signalnum); |
| 191 | |
| 192 | static PyObject * |
| 193 | signal_strsignal(PyObject *module, PyObject *arg) |
| 194 | { |
| 195 | PyObject *return_value = NULL; |
| 196 | int signalnum; |
| 197 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 198 | if (PyFloat_Check(arg)) { |
| 199 | PyErr_SetString(PyExc_TypeError, |
| 200 | "integer argument expected, got float" ); |
| 201 | goto exit; |
| 202 | } |
| 203 | signalnum = _PyLong_AsInt(arg); |
| 204 | if (signalnum == -1 && PyErr_Occurred()) { |
Antoine Pietri | 5d2a27d | 2018-03-12 14:42:34 +0100 | [diff] [blame] | 205 | goto exit; |
| 206 | } |
| 207 | return_value = signal_strsignal_impl(module, signalnum); |
| 208 | |
| 209 | exit: |
| 210 | return return_value; |
| 211 | } |
| 212 | |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 213 | #if defined(HAVE_SIGINTERRUPT) |
| 214 | |
| 215 | PyDoc_STRVAR(signal_siginterrupt__doc__, |
| 216 | "siginterrupt($module, signalnum, flag, /)\n" |
| 217 | "--\n" |
| 218 | "\n" |
| 219 | "Change system call restart behaviour.\n" |
| 220 | "\n" |
| 221 | "If flag is False, system calls will be restarted when interrupted by\n" |
| 222 | "signal sig, else system calls will be interrupted."); |
| 223 | |
| 224 | #define SIGNAL_SIGINTERRUPT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 225 | {"siginterrupt", (PyCFunction)(void(*)(void))signal_siginterrupt, METH_FASTCALL, signal_siginterrupt__doc__}, |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 226 | |
| 227 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 228 | signal_siginterrupt_impl(PyObject *module, int signalnum, int flag); |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 229 | |
| 230 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 231 | signal_siginterrupt(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 232 | { |
| 233 | PyObject *return_value = NULL; |
| 234 | int signalnum; |
| 235 | int flag; |
| 236 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 237 | if (!_PyArg_ParseStack(args, nargs, "ii:siginterrupt", |
| 238 | &signalnum, &flag)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 239 | goto exit; |
| 240 | } |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 241 | return_value = signal_siginterrupt_impl(module, signalnum, flag); |
| 242 | |
| 243 | exit: |
| 244 | return return_value; |
| 245 | } |
| 246 | |
| 247 | #endif /* defined(HAVE_SIGINTERRUPT) */ |
| 248 | |
| 249 | #if defined(HAVE_SETITIMER) |
| 250 | |
| 251 | PyDoc_STRVAR(signal_setitimer__doc__, |
| 252 | "setitimer($module, which, seconds, interval=0.0, /)\n" |
| 253 | "--\n" |
| 254 | "\n" |
| 255 | "Sets given itimer (one of ITIMER_REAL, ITIMER_VIRTUAL or ITIMER_PROF).\n" |
| 256 | "\n" |
| 257 | "The timer will fire after value seconds and after that every interval seconds.\n" |
| 258 | "The itimer can be cleared by setting seconds to zero.\n" |
| 259 | "\n" |
| 260 | "Returns old values as a tuple: (delay, interval)."); |
| 261 | |
| 262 | #define SIGNAL_SETITIMER_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 263 | {"setitimer", (PyCFunction)(void(*)(void))signal_setitimer, METH_FASTCALL, signal_setitimer__doc__}, |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 264 | |
| 265 | static PyObject * |
Victor Stinner | ef611c9 | 2017-10-13 13:49:43 -0700 | [diff] [blame] | 266 | signal_setitimer_impl(PyObject *module, int which, PyObject *seconds, |
| 267 | PyObject *interval); |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 268 | |
| 269 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 270 | signal_setitimer(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 271 | { |
| 272 | PyObject *return_value = NULL; |
| 273 | int which; |
Victor Stinner | ef611c9 | 2017-10-13 13:49:43 -0700 | [diff] [blame] | 274 | PyObject *seconds; |
| 275 | PyObject *interval = NULL; |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 276 | |
Victor Stinner | ef611c9 | 2017-10-13 13:49:43 -0700 | [diff] [blame] | 277 | if (!_PyArg_ParseStack(args, nargs, "iO|O:setitimer", |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 278 | &which, &seconds, &interval)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 279 | goto exit; |
| 280 | } |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 281 | return_value = signal_setitimer_impl(module, which, seconds, interval); |
| 282 | |
| 283 | exit: |
| 284 | return return_value; |
| 285 | } |
| 286 | |
| 287 | #endif /* defined(HAVE_SETITIMER) */ |
| 288 | |
| 289 | #if defined(HAVE_GETITIMER) |
| 290 | |
| 291 | PyDoc_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 | |
| 300 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 301 | signal_getitimer_impl(PyObject *module, int which); |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 302 | |
| 303 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 304 | signal_getitimer(PyObject *module, PyObject *arg) |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 305 | { |
| 306 | PyObject *return_value = NULL; |
| 307 | int which; |
| 308 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 309 | if (PyFloat_Check(arg)) { |
| 310 | PyErr_SetString(PyExc_TypeError, |
| 311 | "integer argument expected, got float" ); |
| 312 | goto exit; |
| 313 | } |
| 314 | which = _PyLong_AsInt(arg); |
| 315 | if (which == -1 && PyErr_Occurred()) { |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 316 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 317 | } |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 318 | return_value = signal_getitimer_impl(module, which); |
| 319 | |
| 320 | exit: |
| 321 | return return_value; |
| 322 | } |
| 323 | |
| 324 | #endif /* defined(HAVE_GETITIMER) */ |
| 325 | |
| 326 | #if defined(PYPTHREAD_SIGMASK) |
| 327 | |
| 328 | PyDoc_STRVAR(signal_pthread_sigmask__doc__, |
| 329 | "pthread_sigmask($module, how, mask, /)\n" |
| 330 | "--\n" |
| 331 | "\n" |
| 332 | "Fetch and/or change the signal mask of the calling thread."); |
| 333 | |
| 334 | #define SIGNAL_PTHREAD_SIGMASK_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 335 | {"pthread_sigmask", (PyCFunction)(void(*)(void))signal_pthread_sigmask, METH_FASTCALL, signal_pthread_sigmask__doc__}, |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 336 | |
| 337 | static PyObject * |
Serhiy Storchaka | d54cfb1 | 2018-05-08 07:48:50 +0300 | [diff] [blame] | 338 | signal_pthread_sigmask_impl(PyObject *module, int how, sigset_t mask); |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 339 | |
| 340 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 341 | signal_pthread_sigmask(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 342 | { |
| 343 | PyObject *return_value = NULL; |
| 344 | int how; |
Serhiy Storchaka | d54cfb1 | 2018-05-08 07:48:50 +0300 | [diff] [blame] | 345 | sigset_t mask; |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 346 | |
Serhiy Storchaka | d54cfb1 | 2018-05-08 07:48:50 +0300 | [diff] [blame] | 347 | if (!_PyArg_ParseStack(args, nargs, "iO&:pthread_sigmask", |
| 348 | &how, _Py_Sigset_Converter, &mask)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 349 | goto exit; |
| 350 | } |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 351 | return_value = signal_pthread_sigmask_impl(module, how, mask); |
| 352 | |
| 353 | exit: |
| 354 | return return_value; |
| 355 | } |
| 356 | |
| 357 | #endif /* defined(PYPTHREAD_SIGMASK) */ |
| 358 | |
| 359 | #if defined(HAVE_SIGPENDING) |
| 360 | |
| 361 | PyDoc_STRVAR(signal_sigpending__doc__, |
| 362 | "sigpending($module, /)\n" |
| 363 | "--\n" |
| 364 | "\n" |
| 365 | "Examine pending signals.\n" |
| 366 | "\n" |
| 367 | "Returns a set of signal numbers that are pending for delivery to\n" |
| 368 | "the calling thread."); |
| 369 | |
| 370 | #define SIGNAL_SIGPENDING_METHODDEF \ |
| 371 | {"sigpending", (PyCFunction)signal_sigpending, METH_NOARGS, signal_sigpending__doc__}, |
| 372 | |
| 373 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 374 | signal_sigpending_impl(PyObject *module); |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 375 | |
| 376 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 377 | signal_sigpending(PyObject *module, PyObject *Py_UNUSED(ignored)) |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 378 | { |
| 379 | return signal_sigpending_impl(module); |
| 380 | } |
| 381 | |
| 382 | #endif /* defined(HAVE_SIGPENDING) */ |
| 383 | |
| 384 | #if defined(HAVE_SIGWAIT) |
| 385 | |
| 386 | PyDoc_STRVAR(signal_sigwait__doc__, |
| 387 | "sigwait($module, sigset, /)\n" |
| 388 | "--\n" |
| 389 | "\n" |
| 390 | "Wait for a signal.\n" |
| 391 | "\n" |
| 392 | "Suspend execution of the calling thread until the delivery of one of the\n" |
| 393 | "signals specified in the signal set sigset. The function accepts the signal\n" |
| 394 | "and returns the signal number."); |
| 395 | |
| 396 | #define SIGNAL_SIGWAIT_METHODDEF \ |
| 397 | {"sigwait", (PyCFunction)signal_sigwait, METH_O, signal_sigwait__doc__}, |
| 398 | |
Serhiy Storchaka | d54cfb1 | 2018-05-08 07:48:50 +0300 | [diff] [blame] | 399 | static PyObject * |
| 400 | signal_sigwait_impl(PyObject *module, sigset_t sigset); |
| 401 | |
| 402 | static PyObject * |
| 403 | signal_sigwait(PyObject *module, PyObject *arg) |
| 404 | { |
| 405 | PyObject *return_value = NULL; |
| 406 | sigset_t sigset; |
| 407 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 408 | if (!_Py_Sigset_Converter(arg, &sigset)) { |
Serhiy Storchaka | d54cfb1 | 2018-05-08 07:48:50 +0300 | [diff] [blame] | 409 | goto exit; |
| 410 | } |
| 411 | return_value = signal_sigwait_impl(module, sigset); |
| 412 | |
| 413 | exit: |
| 414 | return return_value; |
| 415 | } |
| 416 | |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 417 | #endif /* defined(HAVE_SIGWAIT) */ |
| 418 | |
Antoine Pitrou | 9d3627e | 2018-05-04 13:00:50 +0200 | [diff] [blame] | 419 | #if (defined(HAVE_SIGFILLSET) || defined(MS_WINDOWS)) |
| 420 | |
| 421 | PyDoc_STRVAR(signal_valid_signals__doc__, |
| 422 | "valid_signals($module, /)\n" |
| 423 | "--\n" |
| 424 | "\n" |
| 425 | "Return a set of valid signal numbers on this platform.\n" |
| 426 | "\n" |
| 427 | "The signal numbers returned by this function can be safely passed to\n" |
| 428 | "functions like `pthread_sigmask`."); |
| 429 | |
| 430 | #define SIGNAL_VALID_SIGNALS_METHODDEF \ |
| 431 | {"valid_signals", (PyCFunction)signal_valid_signals, METH_NOARGS, signal_valid_signals__doc__}, |
| 432 | |
| 433 | static PyObject * |
| 434 | signal_valid_signals_impl(PyObject *module); |
| 435 | |
| 436 | static PyObject * |
| 437 | signal_valid_signals(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 438 | { |
| 439 | return signal_valid_signals_impl(module); |
| 440 | } |
| 441 | |
| 442 | #endif /* (defined(HAVE_SIGFILLSET) || defined(MS_WINDOWS)) */ |
| 443 | |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 444 | #if defined(HAVE_SIGWAITINFO) |
| 445 | |
| 446 | PyDoc_STRVAR(signal_sigwaitinfo__doc__, |
| 447 | "sigwaitinfo($module, sigset, /)\n" |
| 448 | "--\n" |
| 449 | "\n" |
| 450 | "Wait synchronously until one of the signals in *sigset* is delivered.\n" |
| 451 | "\n" |
| 452 | "Returns a struct_siginfo containing information about the signal."); |
| 453 | |
| 454 | #define SIGNAL_SIGWAITINFO_METHODDEF \ |
| 455 | {"sigwaitinfo", (PyCFunction)signal_sigwaitinfo, METH_O, signal_sigwaitinfo__doc__}, |
| 456 | |
Serhiy Storchaka | d54cfb1 | 2018-05-08 07:48:50 +0300 | [diff] [blame] | 457 | static PyObject * |
| 458 | signal_sigwaitinfo_impl(PyObject *module, sigset_t sigset); |
| 459 | |
| 460 | static PyObject * |
| 461 | signal_sigwaitinfo(PyObject *module, PyObject *arg) |
| 462 | { |
| 463 | PyObject *return_value = NULL; |
| 464 | sigset_t sigset; |
| 465 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 466 | if (!_Py_Sigset_Converter(arg, &sigset)) { |
Serhiy Storchaka | d54cfb1 | 2018-05-08 07:48:50 +0300 | [diff] [blame] | 467 | goto exit; |
| 468 | } |
| 469 | return_value = signal_sigwaitinfo_impl(module, sigset); |
| 470 | |
| 471 | exit: |
| 472 | return return_value; |
| 473 | } |
| 474 | |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 475 | #endif /* defined(HAVE_SIGWAITINFO) */ |
| 476 | |
| 477 | #if defined(HAVE_SIGTIMEDWAIT) |
| 478 | |
| 479 | PyDoc_STRVAR(signal_sigtimedwait__doc__, |
| 480 | "sigtimedwait($module, sigset, timeout, /)\n" |
| 481 | "--\n" |
| 482 | "\n" |
| 483 | "Like sigwaitinfo(), but with a timeout.\n" |
| 484 | "\n" |
| 485 | "The timeout is specified in seconds, with floating point numbers allowed."); |
| 486 | |
| 487 | #define SIGNAL_SIGTIMEDWAIT_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 488 | {"sigtimedwait", (PyCFunction)(void(*)(void))signal_sigtimedwait, METH_FASTCALL, signal_sigtimedwait__doc__}, |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 489 | |
| 490 | static PyObject * |
Serhiy Storchaka | d54cfb1 | 2018-05-08 07:48:50 +0300 | [diff] [blame] | 491 | signal_sigtimedwait_impl(PyObject *module, sigset_t sigset, |
Serhiy Storchaka | 6b680cd | 2015-05-16 15:57:56 +0300 | [diff] [blame] | 492 | PyObject *timeout_obj); |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 493 | |
| 494 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 495 | signal_sigtimedwait(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 496 | { |
| 497 | PyObject *return_value = NULL; |
Serhiy Storchaka | d54cfb1 | 2018-05-08 07:48:50 +0300 | [diff] [blame] | 498 | sigset_t sigset; |
Serhiy Storchaka | 6b680cd | 2015-05-16 15:57:56 +0300 | [diff] [blame] | 499 | PyObject *timeout_obj; |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 500 | |
Serhiy Storchaka | d54cfb1 | 2018-05-08 07:48:50 +0300 | [diff] [blame] | 501 | if (!_PyArg_ParseStack(args, nargs, "O&O:sigtimedwait", |
| 502 | _Py_Sigset_Converter, &sigset, &timeout_obj)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 503 | goto exit; |
| 504 | } |
Serhiy Storchaka | 6b680cd | 2015-05-16 15:57:56 +0300 | [diff] [blame] | 505 | return_value = signal_sigtimedwait_impl(module, sigset, timeout_obj); |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 506 | |
| 507 | exit: |
| 508 | return return_value; |
| 509 | } |
| 510 | |
| 511 | #endif /* defined(HAVE_SIGTIMEDWAIT) */ |
| 512 | |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 513 | #if defined(HAVE_PTHREAD_KILL) |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 514 | |
| 515 | PyDoc_STRVAR(signal_pthread_kill__doc__, |
| 516 | "pthread_kill($module, thread_id, signalnum, /)\n" |
| 517 | "--\n" |
| 518 | "\n" |
| 519 | "Send a signal to a thread."); |
| 520 | |
| 521 | #define SIGNAL_PTHREAD_KILL_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 522 | {"pthread_kill", (PyCFunction)(void(*)(void))signal_pthread_kill, METH_FASTCALL, signal_pthread_kill__doc__}, |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 523 | |
| 524 | static PyObject * |
Serhiy Storchaka | aefa7eb | 2017-03-23 15:48:39 +0200 | [diff] [blame] | 525 | signal_pthread_kill_impl(PyObject *module, unsigned long thread_id, |
| 526 | int signalnum); |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 527 | |
| 528 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 529 | signal_pthread_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 530 | { |
| 531 | PyObject *return_value = NULL; |
Serhiy Storchaka | aefa7eb | 2017-03-23 15:48:39 +0200 | [diff] [blame] | 532 | unsigned long thread_id; |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 533 | int signalnum; |
| 534 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 535 | if (!_PyArg_ParseStack(args, nargs, "ki:pthread_kill", |
| 536 | &thread_id, &signalnum)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 537 | goto exit; |
| 538 | } |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 539 | return_value = signal_pthread_kill_impl(module, thread_id, signalnum); |
| 540 | |
| 541 | exit: |
| 542 | return return_value; |
| 543 | } |
| 544 | |
Antoine Pitrou | a6a4dc8 | 2017-09-07 18:56:24 +0200 | [diff] [blame] | 545 | #endif /* defined(HAVE_PTHREAD_KILL) */ |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 546 | |
| 547 | #ifndef SIGNAL_ALARM_METHODDEF |
| 548 | #define SIGNAL_ALARM_METHODDEF |
| 549 | #endif /* !defined(SIGNAL_ALARM_METHODDEF) */ |
| 550 | |
| 551 | #ifndef SIGNAL_PAUSE_METHODDEF |
| 552 | #define SIGNAL_PAUSE_METHODDEF |
| 553 | #endif /* !defined(SIGNAL_PAUSE_METHODDEF) */ |
| 554 | |
| 555 | #ifndef SIGNAL_SIGINTERRUPT_METHODDEF |
| 556 | #define SIGNAL_SIGINTERRUPT_METHODDEF |
| 557 | #endif /* !defined(SIGNAL_SIGINTERRUPT_METHODDEF) */ |
| 558 | |
| 559 | #ifndef SIGNAL_SETITIMER_METHODDEF |
| 560 | #define SIGNAL_SETITIMER_METHODDEF |
| 561 | #endif /* !defined(SIGNAL_SETITIMER_METHODDEF) */ |
| 562 | |
| 563 | #ifndef SIGNAL_GETITIMER_METHODDEF |
| 564 | #define SIGNAL_GETITIMER_METHODDEF |
| 565 | #endif /* !defined(SIGNAL_GETITIMER_METHODDEF) */ |
| 566 | |
| 567 | #ifndef SIGNAL_PTHREAD_SIGMASK_METHODDEF |
| 568 | #define SIGNAL_PTHREAD_SIGMASK_METHODDEF |
| 569 | #endif /* !defined(SIGNAL_PTHREAD_SIGMASK_METHODDEF) */ |
| 570 | |
| 571 | #ifndef SIGNAL_SIGPENDING_METHODDEF |
| 572 | #define SIGNAL_SIGPENDING_METHODDEF |
| 573 | #endif /* !defined(SIGNAL_SIGPENDING_METHODDEF) */ |
| 574 | |
| 575 | #ifndef SIGNAL_SIGWAIT_METHODDEF |
| 576 | #define SIGNAL_SIGWAIT_METHODDEF |
| 577 | #endif /* !defined(SIGNAL_SIGWAIT_METHODDEF) */ |
| 578 | |
Antoine Pitrou | 9d3627e | 2018-05-04 13:00:50 +0200 | [diff] [blame] | 579 | #ifndef SIGNAL_VALID_SIGNALS_METHODDEF |
| 580 | #define SIGNAL_VALID_SIGNALS_METHODDEF |
| 581 | #endif /* !defined(SIGNAL_VALID_SIGNALS_METHODDEF) */ |
| 582 | |
Tal Einat | c7027b7 | 2015-05-16 14:14:49 +0300 | [diff] [blame] | 583 | #ifndef SIGNAL_SIGWAITINFO_METHODDEF |
| 584 | #define SIGNAL_SIGWAITINFO_METHODDEF |
| 585 | #endif /* !defined(SIGNAL_SIGWAITINFO_METHODDEF) */ |
| 586 | |
| 587 | #ifndef SIGNAL_SIGTIMEDWAIT_METHODDEF |
| 588 | #define SIGNAL_SIGTIMEDWAIT_METHODDEF |
| 589 | #endif /* !defined(SIGNAL_SIGTIMEDWAIT_METHODDEF) */ |
| 590 | |
| 591 | #ifndef SIGNAL_PTHREAD_KILL_METHODDEF |
| 592 | #define SIGNAL_PTHREAD_KILL_METHODDEF |
| 593 | #endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */ |
Vladimir Matveev | c24c6c2 | 2019-01-08 01:58:25 -0800 | [diff] [blame^] | 594 | /*[clinic end generated code: output=365db4e807c26d4e input=a9049054013a1b77]*/ |