signalmodule.c.h 19 KB

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