diff options
author | Benjamin Peterson <benjamin@python.org> | 2019-11-20 04:39:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-20 04:39:14 (GMT) |
commit | 7483451577916e693af6d20cf520b2cc7e2174d2 (patch) | |
tree | 54fdd671a4513a4cf938f1438ce53823909b02db /Modules/signalmodule.c | |
parent | be143ec99674ba38c5811f34cdb85ef39c2dc8f8 (diff) | |
download | cpython-7483451577916e693af6d20cf520b2cc7e2174d2.zip cpython-7483451577916e693af6d20cf520b2cc7e2174d2.tar.gz cpython-7483451577916e693af6d20cf520b2cc7e2174d2.tar.bz2 |
closes bpo-38712: Add signal.pidfd_send_signal. (GH-17070)
This exposes a Linux-specific syscall for sending a signal to a process
identified by a file descriptor rather than a pid.
For simplicity, we don't support the siginfo_t parameter to the syscall. This
parameter allows implementing a pidfd version of rt_sigqueueinfo(2), which
Python also doesn't support.
Diffstat (limited to 'Modules/signalmodule.c')
-rw-r--r-- | Modules/signalmodule.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 1d99f87..693b90b 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -25,6 +25,9 @@ #ifdef HAVE_SIGNAL_H #include <signal.h> #endif +#ifdef HAVE_SYS_SYSCALL_H +#include <sys/syscall.h> +#endif #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif @@ -1250,6 +1253,38 @@ signal_pthread_kill_impl(PyObject *module, unsigned long thread_id, #endif /* #if defined(HAVE_PTHREAD_KILL) */ +#if defined(__linux__) && defined(__NR_pidfd_send_signal) +/*[clinic input] +signal.pidfd_send_signal + + pidfd: int + signalnum: int + siginfo: object = None + flags: int = 0 + / + +Send a signal to a process referred to by a pid file descriptor. +[clinic start generated code]*/ + +static PyObject * +signal_pidfd_send_signal_impl(PyObject *module, int pidfd, int signalnum, + PyObject *siginfo, int flags) +/*[clinic end generated code: output=2d59f04a75d9cbdf input=2a6543a1f4ac2000]*/ + +{ + if (siginfo != Py_None) { + PyErr_SetString(PyExc_TypeError, "siginfo must be None"); + return NULL; + } + if (syscall(__NR_pidfd_send_signal, pidfd, signalnum, NULL, flags) < 0) { + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + Py_RETURN_NONE; +} +#endif + + /* List of functions defined in the module -- some of the methoddefs are defined to nothing if the corresponding C function is not available. */ @@ -1265,6 +1300,7 @@ static PyMethodDef signal_methods[] = { {"set_wakeup_fd", (PyCFunction)(void(*)(void))signal_set_wakeup_fd, METH_VARARGS | METH_KEYWORDS, set_wakeup_fd_doc}, SIGNAL_SIGINTERRUPT_METHODDEF SIGNAL_PAUSE_METHODDEF + SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF SIGNAL_PTHREAD_KILL_METHODDEF SIGNAL_PTHREAD_SIGMASK_METHODDEF SIGNAL_SIGPENDING_METHODDEF |