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