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