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