closes bpo-38712: Add signal.pidfd_send_signal. (GH-17070) · python/cpython@7483451 (original) (raw)

`@@ -25,6 +25,9 @@

`

25

25

`#ifdef HAVE_SIGNAL_H

`

26

26

`#include <signal.h>

`

27

27

`#endif

`

``

28

`+

#ifdef HAVE_SYS_SYSCALL_H

`

``

29

`+

#include <sys/syscall.h>

`

``

30

`+

#endif

`

28

31

`#ifdef HAVE_SYS_STAT_H

`

29

32

`#include <sys/stat.h>

`

30

33

`#endif

`

`@@ -1250,6 +1253,38 @@ signal_pthread_kill_impl(PyObject *module, unsigned long thread_id,

`

1250

1253

`#endif /* #if defined(HAVE_PTHREAD_KILL) */

`

1251

1254

``

1252

1255

``

``

1256

`+

#if defined(linux) && defined(__NR_pidfd_send_signal)

`

``

1257

`+

/*[clinic input]

`

``

1258

`+

signal.pidfd_send_signal

`

``

1259

+

``

1260

`+

pidfd: int

`

``

1261

`+

signalnum: int

`

``

1262

`+

siginfo: object = None

`

``

1263

`+

flags: int = 0

`

``

1264

`+

/

`

``

1265

+

``

1266

`+

Send a signal to a process referred to by a pid file descriptor.

`

``

1267

`+

[clinic start generated code]*/

`

``

1268

+

``

1269

`+

static PyObject *

`

``

1270

`+

signal_pidfd_send_signal_impl(PyObject *module, int pidfd, int signalnum,

`

``

1271

`+

PyObject *siginfo, int flags)

`

``

1272

`+

/[clinic end generated code: output=2d59f04a75d9cbdf input=2a6543a1f4ac2000]/

`

``

1273

+

``

1274

`+

{

`

``

1275

`+

if (siginfo != Py_None) {

`

``

1276

`+

PyErr_SetString(PyExc_TypeError, "siginfo must be None");

`

``

1277

`+

return NULL;

`

``

1278

`+

}

`

``

1279

`+

if (syscall(__NR_pidfd_send_signal, pidfd, signalnum, NULL, flags) < 0) {

`

``

1280

`+

PyErr_SetFromErrno(PyExc_OSError);

`

``

1281

`+

return NULL;

`

``

1282

`+

}

`

``

1283

`+

Py_RETURN_NONE;

`

``

1284

`+

}

`

``

1285

`+

#endif

`

``

1286

+

``

1287

+

1253

1288

``

1254

1289

`/* List of functions defined in the module -- some of the methoddefs are

`

1255

1290

` defined to nothing if the corresponding C function is not available. */

`

`@@ -1265,6 +1300,7 @@ static PyMethodDef signal_methods[] = {

`

1265

1300

` {"set_wakeup_fd", (PyCFunction)(void(*)(void))signal_set_wakeup_fd, METH_VARARGS | METH_KEYWORDS, set_wakeup_fd_doc},

`

1266

1301

`SIGNAL_SIGINTERRUPT_METHODDEF

`

1267

1302

`SIGNAL_PAUSE_METHODDEF

`

``

1303

`+

SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF

`

1268

1304

`SIGNAL_PTHREAD_KILL_METHODDEF

`

1269

1305

`SIGNAL_PTHREAD_SIGMASK_METHODDEF

`

1270

1306

`SIGNAL_SIGPENDING_METHODDEF

`