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